Lua Wizard simplification. Engine paged added.

This commit is contained in:
bsongis
2014-05-26 10:20:29 +02:00
parent 02396dc03d
commit eb2fd118b7
6 changed files with 143 additions and 59 deletions
+9 -1
View File
@@ -63,7 +63,7 @@ ScriptInternalData standaloneScript = { SCRIPT_NOFILE, 0 };
#define PERMANENT_SCRIPTS_MAX_INSTRUCTIONS (1000/100)
#define MANUAL_SCRIPTS_MAX_INSTRUCTIONS (10000/100)
#define SCRIPTS_MAX_HEAP 50
#define SCRIPTS_MAX_HEAP 100
#define SET_LUA_INSTRUCTIONS_COUNT(x) (instructionsPercent=0, lua_sethook(L, hook, LUA_MASKCOUNT, x))
static int instructionsPercent = 0;
@@ -193,6 +193,12 @@ static int luaPlayNumber(lua_State *L)
return 0;
}
static int luaKillEvents(lua_State *L)
{
int event = luaL_checkinteger(L, 1);
killEvents(event);
return 0;
}
static int luaLcdLock(lua_State *L)
{
@@ -993,6 +999,7 @@ void luaInit()
lua_register(L, "playNumber", luaPlayNumber);
lua_register(L, "popupInput", luaPopupInput);
lua_register(L, "channelOrder", luaChannelOrder);
lua_register(L, "killEvents", luaKillEvents);
// Push OpenTX constants
lua_registerint(L, "FULLSCALE", RESX);
@@ -1012,6 +1019,7 @@ void luaInit()
lua_registerint(L, "SOURCE_FIRST_CH", MIXSRC_FIRST_CH);
lua_registerint(L, "EVT_MENU_BREAK", EVT_KEY_BREAK(KEY_MENU));
lua_registerint(L, "EVT_PAGE_BREAK", EVT_KEY_BREAK(KEY_PAGE));
lua_registerint(L, "EVT_PAGE_LONG", EVT_KEY_LONG(KEY_PAGE));
lua_registerint(L, "EVT_ENTER_BREAK", EVT_KEY_BREAK(KEY_ENTER));
lua_registerint(L, "EVT_EXIT_BREAK", EVT_KEY_BREAK(KEY_EXIT));
lua_registerint(L, "EVT_PLUS_BREAK", EVT_KEY_BREAK(KEY_PLUS));
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

+134 -58
View File
@@ -6,7 +6,8 @@ local HELI_MENU = PLANE_MENU+10
local DELTA_MENU = HELI_MENU+10
local QUADRI_MENU = DELTA_MENU+10
local AILERONS_MENU = PLANE_MENU
local ENGINE_MENU = PLANE_MENU
local AILERONS_MENU = PLANE_MENU+1
local page = MODELTYPE_MENU
local dirty = true
@@ -15,38 +16,26 @@ local choice = 0
local edit = false
local field = 0
local fieldsMax = 0
local engineMode = 0
local engineCH1 = 0
local aileronsMode = 0
local aileronsCH1 = 0
local aileronsCH2 = 4
local function init()
for stick = 0, 4, 1 do
local index = channelOrder(stick);
if index == 0 then
elseif index == 1 then
elseif index == 2 then
else
aileronsCH1 = stick
end
-- Common functions
local lastBlink = 0
local function blinkChanged()
local time = getTime() % 128
local blink = (time - time % 64) / 64
if blink ~= lastBlink then
lastBlink = blink
return true
else
return false
end
end
local function choiceSurround(index)
lcd.drawRectangle(12+47*index, 13, 48, 48)
lcd.drawPixmap(17+47*index, 8, "/TEMPLATES/mark.bmp")
end
local function drawModelChoiceMenu()
lcd.clear()
lcd.drawScreenTitle("", 0, 0)
-- lcd.drawText(58, 13, "Select model type", 0)
lcd.drawPixmap( 16, 17, "/TEMPLATES/plane.bmp")
lcd.drawPixmap( 63, 17, "/TEMPLATES/heli.bmp")
lcd.drawPixmap(110, 17, "/TEMPLATES/delta.bmp")
lcd.drawPixmap(157, 17, "/TEMPLATES/quadri.bmp")
choiceSurround(choice)
end
local function keyIncDec(event, value, max, isvalue)
if isvalue then
if event == EVT_PLUS_BREAK then
@@ -73,16 +62,26 @@ local function keyIncDec(event, value, max, isvalue)
return value
end
local function modelTypeMenu(event)
if dirty == true then
drawModelChoiceMenu()
dirty = false
end
local function navigate(event, fieldMax, prevPage, nextPage)
if event == EVT_ENTER_BREAK then
page = PLANE_MENU+(10*choice)
edit = not edit
dirty = true
end
if edit then
if not dirty then
dirty = blinkChanged()
end
else
choice = keyIncDec(event, choice, 3)
if event == EVT_PAGE_BREAK then
page = nextPage
dirty = true
elseif event == EVT_PAGE_LONG then
page = prevPage
killEvents(event);
dirty = true
else
field = keyIncDec(event, field, fieldMax)
end
end
end
@@ -97,19 +96,96 @@ local function getFieldFlags(position)
return flags
end
local lastBlink = 0
local function blinkChanged()
local time = getTime() % 128
local blink = (time - time % 64) / 64
if blink ~= lastBlink then
lastBlink = blink
return true
else
return false
-- Init function
local function init()
for stick = 0, 4, 1 do
local index = channelOrder(stick);
if index == 0 then
elseif index == 1 then
elseif index == 2 then
engineCH1 = stick
else
aileronsCH1 = stick
end
end
end
local aileronsModeItems = {"Yes...", "No...", "Yes, 2 channels..."}
-- Model Type Menu
local function choiceSurround(index)
lcd.drawRectangle(12+47*index, 13, 48, 48)
lcd.drawPixmap(17+47*index, 8, "/TEMPLATES/mark.bmp")
end
local function drawModelChoiceMenu()
lcd.clear()
lcd.drawScreenTitle("", 0, 0)
-- lcd.drawText(58, 13, "Select model type", 0)
lcd.drawPixmap( 16, 17, "/TEMPLATES/plane.bmp")
lcd.drawPixmap( 63, 17, "/TEMPLATES/heli.bmp")
lcd.drawPixmap(110, 17, "/TEMPLATES/delta.bmp")
lcd.drawPixmap(157, 17, "/TEMPLATES/quadri.bmp")
choiceSurround(choice)
end
local function modelTypeMenu(event)
if dirty == true then
drawModelChoiceMenu()
dirty = false
end
if event == EVT_ENTER_BREAK then
page = PLANE_MENU+(10*choice)
dirty = true
else
choice = keyIncDec(event, choice, 3)
end
end
-- Engine Menu
local engineModeItems = {"Yes...", "No"}
local function drawEngineMenu()
lcd.clear()
lcd.drawText(1, 0, "Has your model got an engine?", 0)
lcd.drawRect(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE)
lcd.drawCombobox(0, 8, LCD_W/2, engineModeItems, engineMode, getFieldFlags(0))
lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H, DOTTED, 0)
if engineMode == 1 then
-- No engine
lcd.drawPixmap(132, 8, "/TEMPLATES/engine-0.bmp")
fieldsMax = 0
else
-- 1 channel
lcd.drawPixmap(132, 8, "/TEMPLATES/engine-1.bmp")
lcd.drawText(25, LCD_H-16, "Assign channel", 0);
lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0);
lcd.drawSource(151, LCD_H-8, SOURCE_FIRST_CH+engineCH1, getFieldFlags(1))
fieldsMax = 1
end
end
local function engineMenu(event)
if dirty then
dirty = false
drawEngineMenu()
end
navigate(event, fieldsMax, MODELTYPE_MENU, page+1)
if edit then
if field==0 then
engineMode = keyIncDec(event, engineMode, 1)
elseif field==1 then
engineCH1 = keyIncDec(event, engineCH1, 7, true)
end
end
end
-- Ailerons Menu
local aileronsModeItems = {"Yes...", "No", "Yes, 2 channels..."}
local function drawAileronsMenu()
lcd.clear()
@@ -140,28 +216,26 @@ local function drawAileronsMenu()
end
local function aileronsMenu(event)
if not dirty then
dirty = blinkChanged()
end
if dirty then
dirty = false
drawAileronsMenu()
end
if event == EVT_ENTER_BREAK then
edit = not edit
dirty = true
end
if edit == false then
field = keyIncDec(event, field, fieldsMax)
elseif field == 0 then
aileronsMode = keyIncDec(event, aileronsMode, 2)
elseif field == 1 then
aileronsCH1 = keyIncDec(event, aileronsCH1, 7, true)
elseif field == 2 then
aileronsCH2 = keyIncDec(event, aileronsCH2, 7, true)
navigate(event, fieldsMax, page-1, page+1)
if edit then
if field==0 then
aileronsMode = keyIncDec(event, aileronsMode, 2)
elseif field==1 then
aileronsCH1 = keyIncDec(event, aileronsCH1, 7, true)
elseif field==2 then
aileronsCH2 = keyIncDec(event, aileronsCH2, 7, true)
end
end
end
-- Main
local function run(event)
if event == EVT_EXIT_BREAK then
return 2
@@ -169,6 +243,8 @@ local function run(event)
lcd.lock()
if page == MODELTYPE_MENU then
modelTypeMenu(event)
elseif page == ENGINE_MENU then
engineMenu(event)
elseif page == AILERONS_MENU then
aileronsMenu(event)
end