1+ local Log , menuLib , modelLib , DEBUG_ON , SIMULATION_ON = ... -- Get DebugON from parameters
2+ local MAIN_MENU_LIB_VERSION = " 0.55"
3+ local MODEL = modelLib .MODEL
4+
5+ local PHASE = menuLib .PHASE
6+ local LINE_TYPE = menuLib .LINE_TYPE
7+
8+ local lastGoodMenu = 0
9+
10+ -- Creates the menus to Render with the GUI
11+ local function ST_LoadMenu (menuId )
12+ local ctx = menuLib .DSM_Context
13+ menuLib .clearMenuLines ()
14+
15+ if (menuId == 0x1000 ) then -- MAIN MENU
16+ ctx .Menu = { MenuId = 0x1000 , Text = " Main Menu (" .. MODEL .modelName .. " )" , PrevId = 0 , NextId = 0 , BackId = 0 , TextId = 0 }
17+ ctx .MenuLines [0 ] = { Type = LINE_TYPE .MENU , Text = " Model Setup" , ValId = 0xFFF3 ,TextId = 0 }
18+
19+ if (SIMULATION_ON ) then
20+ ctx .MenuLines [4 ] = { Type = LINE_TYPE .MENU , Text = " RX Simulator (GUI dev only)" , ValId = 0xFFF1 , TextId = 0 } -- Menu 0xFFF2 to SIMULATOR
21+ end
22+ ctx .MenuLines [6 ] = { Type = LINE_TYPE .MENU , Text = " Forward Programming RX" , ValId = 0xFFF2 , TextId = 0 } -- Menu 0xFFF2 to Real RX
23+ ctx .SelLine = 6
24+
25+ lastGoodMenu = menuId
26+ else
27+ -- print("NOT IMPLEMENTED")
28+ ctx .Menu = { MenuId = 0x0002 , Text = " NOT IMPLEMENTED" , TextId = 0 , PrevId = 0 , NextId = 0 , BackId = lastGoodMenu }
29+ ctx .SelLine = menuLib .BACK_BUTTON
30+ end
31+
32+ menuLib .PostProcessMenu ()
33+ end
34+
35+ local function Main_Send_Receive ()
36+ local ctx = menuLib .DSM_Context
37+
38+ if ctx .Phase == PHASE .RX_VERSION then -- Just Init RX Version
39+ ctx .RX .Name = " Main Menu"
40+ ctx .RX .Version = MAIN_MENU_LIB_VERSION
41+ ctx .Phase = PHASE .MENU_TITLE
42+ ctx .Menu .MenuId = 0
43+
44+ ctx .Refresh_Display = true
45+ elseif ctx .Phase == PHASE .WAIT_CMD then
46+
47+ elseif ctx .Phase == PHASE .MENU_TITLE then -- request menu title
48+ if ctx .Menu .MenuId == 0 then -- First time loading a menu ?
49+ ST_LoadMenu (0x01000 )
50+ else
51+ ST_LoadMenu (ctx .Menu .MenuId )
52+ end
53+ ctx .Phase = PHASE .WAIT_CMD
54+ ctx .Refresh_Display = true
55+
56+ elseif ctx .Phase == PHASE .VALUE_CHANGING then -- send value
57+ local line = ctx .MenuLines [ctx .SelLine ] -- Updated Value of SELECTED line
58+ -- if (DEBUG_ON) then Log.LOG_write("%3.3f %s: ", menuLib.getElapsedTime(), menuLib.phase2String(ctx.Phase)) end
59+ -- if (DEBUG_ON) then Log.LOG_write("SEND SIM_updateMenuValue(ValueId=0x%X Text=\"%s\" Value=%s)\n", line.ValId, line.Text, menuLib.lineValue2String(line)) end
60+ ctx .Phase = PHASE .VALUE_CHANGING_WAIT
61+
62+ elseif ctx .Phase == PHASE .VALUE_CHANGING_WAIT then
63+ local line = ctx .MenuLines [ctx .SelLine ]
64+
65+ elseif ctx .Phase == PHASE .VALUE_CHANGE_END then -- send value
66+ local line = ctx .MenuLines [ctx .SelLine ] -- Updated Value of SELECTED line
67+ -- if (DEBUG_ON) then Log.LOG_write("%3.3f %s: ", menuLib.getElapsedTime(), menuLib.phase2String(ctx.Phase)) end
68+ -- if (DEBUG_ON) then Log.LOG_write("SEND SIM_updateMenuValue(ValueId=0x%X Text=\"%s\" Value=%s)\n", line.ValId, line.Text, menuLib.lineValue2String(line)) end
69+ -- if (DEBUG_ON) then Log.LOG_write("SEND SIM_validateMenuValue(ValueId=0x%X Text=\"%s\" Value=%s)\n", line.ValId, line.Text, menuLib.lineValue2String(line)) end
70+ ctx .Phase = PHASE .WAIT_CMD
71+
72+ elseif ctx .Phase == PHASE .EXIT then
73+ ctx .Phase = PHASE .EXIT_DONE
74+ return 1
75+ end
76+
77+ return 0
78+ end
79+
80+ local function Main_Init ()
81+ local ctx = menuLib .DSM_Context
82+ ctx .Phase = PHASE .RX_VERSION
83+ end
84+
85+ local function Main_Done ()
86+ local ctx = menuLib .DSM_Context
87+ ctx .Phase = PHASE .EXIT_DONE
88+ end
89+
90+ return { init = Main_Init , run = Main_Send_Receive , done = Main_Done }
0 commit comments