Giter VIP home page Giter VIP logo

opentx-ui's Introduction

opentx-ui

User Interface library code for OpenTX

Example

Please see the included example.lua for a full, working example of the script.

Menu

Usage

Include menu.lua in your Lua source

local menu = dofile('/SCRIPTS/LIBRARY/menu.lua')

Define a menu structure and table to hold values

local SWITCH_NAMES = { 'sa', 'sb', 'sc', 'sd' }
local BUTTON_OK = -5

local setupMenu = {
	ValueColumn = 115,
	{ menu.TYPE_INTEGER, 'Throttle Channel', 'ThrottleChannel', 10, 11, 1, 16 },
	{ m.TYPE_LIST, 'Lap Switch', 'LapSwitch', 10, 21, SWITCH_NAMES },
	{ menu.TYPE_YES_NO, 'Speak', 'SpeakSounds', 10, 31 },
	{ menu.TYPE_BUTTON, 'Ok', BUTTON_OK, 10, 41 }
}

local setup = {
	ThrottleChannel = 1,
	SpeakSounds = true,
	LapSwitch = 2
}

Call the execute method of the menu class

local function run_func(keyEvent)
	lcd.clear()
	lcd.drawScreenTitle('Menu Example', 1, 1)

	local result = menu.execute(setupMenu, setup, keyEvent)
end

Handle any key event that falls through the menu system

if result == EVT_MENU_BREAK then
	-- blah
elseif result == BUTTON_OK then
	-- OK button was pressed
end

Menu Layout

The menu should be defined as a table of sub-tables. Each sub-table will become a new menu entry. A menu entry layout is defined by:

  1. Type of menu entry. See TYPE_ constants
  2. Label to display
  3. Value key to read and write to passed in the values parameter of the execute method
  4. X location of Label
  5. Y location of Label
  6. Additional Parameters - defined by the TYPE of menu entry

Menu Types

  • TYPE_INTEGER -- Contains two additional parameters, min and max
  • TYPE_STRING -- Contains one additional parameter, max size
  • TYPE_LIST -- Contains one additional parameter, an array of list values
  • TYPE_YES_NO -- No additional parameters
  • TYPE_BUTTON -- No additional parameters. The value part, however, is returned as the event if pressed. Thus, the value of a button should not be any standard EVT_ values

Config

Read and write configuration files based on a table

Usage

Include config.lua in your Lua source

local config = dofile('/SCRIPTS/LIBRARY/config.lua')

Create a configuration table with default values

local setup = {
	ThrottleChannel = 1,
	SpeakSounds = true,
	LapSwitch = 3
}

Load load and save your configuration from disk

local function do_something()
	setup = config.read('/example.cfg', setup)
	config.write('/example.cfg', setup)
end

Release History

  • Version 0.3.0 -- Jan 14, 2016 (evening): String editing now functions, although it is not an exact replica of OpenTX string editing, that will come in a future release.
  • Version 0.2.0 -- Jan 14, 2016 (morning): First public release, a lot can/will change still.

opentx-ui's People

Contributors

jcowgar avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

opentx-ui's Issues

Create scrollable menus

One should be able to define an array of menu entries that may contain 50 items. The system should be able to scroll and edit all of those entries.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.