local command1 = 0
local command2 = 0
local command3 = 0
local command4 = 0
local command5 = 0
local command6 = 0
local command7 = 0
local command8 = 0
local alarm1 = 0
local alarm2 = 0
local selected = 0
local commanddisplay = {}
local function loadBrandBack()
back = Bitmap.open("8COMMANDS_img/back1.png")
end
local function init()
for i=0,31,1 do
commanddisplay[i] = '#'
end
loadBrandBack()
--request config data from sensor
sportTelemetryPush(0x1B, 0x30, 0x5200, 0x01)
end
local function loadWaitBack()
--back = Bitmap.open("/scripts/tools/8COMMANDS_img/back_ecu.png")
end
local function loadBrandBack()
back = Bitmap.open("/SCRIPTS/TOOLS/8COMMANDS_img/back1.png")
end
local function run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_EXIT_BREAK then
return 2
elseif event == EVT_MODEL_FIRST then
--todo
elseif event == EVT_ENTER_BREAK or event == EVT_SYS_FIRST then
--todo
elseif event == EVT_ENTER_LONG or event == EVT_TELEM_FIRST then
if selected == 0 then
sportTelemetryPush(0x1B, 0x31, 0x5200, command1)
elseif selected == 1 then
sportTelemetryPush(0x1B, 0x31, 0x5201, command2)
elseif selected == 2 then
sportTelemetryPush(0x1B, 0x31, 0x5202, command3)
elseif selected == 3 then
sportTelemetryPush(0x1B, 0x31, 0x5203, command4)
elseif selected == 4 then
sportTelemetryPush(0x1B, 0x31, 0x5204, command5)
elseif selected == 5 then
sportTelemetryPush(0x1B, 0x31, 0x5205, command6)
elseif selected == 6 then
sportTelemetryPush(0x1B, 0x31, 0x5206, command7)
elseif selected == 7 then
sportTelemetryPush(0x1B, 0x31, 0x5207, command8)
end
elseif event == EVT_PAGE_BREAK or event == EVT_PAGEDN_FIRST then
if selected == 0 then
selected = 1
elseif selected == 1 then
selected = 2
elseif selected == 2 then
selected = 3
elseif selected == 3 then
selected = 4
elseif selected == 4 then
selected = 5
elseif selected == 5 then
selected = 6
elseif selected == 6 then
selected = 7
end
elseif event == EVT_PAGE_LONG or event == EVT_PAGEUP_FIRST then
if selected == 7 then
selected = 6
elseif selected == 6 then
selected = 5
elseif selected == 5 then
selected = 4
elseif selected == 4 then
selected = 3
elseif selected == 3 then
selected = 2
elseif selected == 2 then
selected = 1
elseif selected == 1 then
selected = 0
end
elseif event == EVT_PLUS_FIRST or event == EVT_ROT_RIGHT or event == EVT_PLUS_REPT then
if selected == 0 then
command1 = 1
elseif selected == 1 then
command2 = 1
elseif selected == 2 then
command3 = 1
elseif selected == 3 then
command4 = 1
elseif selected == 4 then
command5 = 1
elseif selected == 5 then
command6 = 1
elseif selected == 6 then
command7 = 1
elseif selected == 7 then
command8 = 1
end
elseif event == EVT_MINUS_FIRST or event == EVT_ROT_LEFT or event == EVT_MINUS_REPT then
if selected == 0 then
command1 = 0
elseif selected == 1 then
command2 = 0
elseif selected == 2 then
command3 = 0
elseif selected == 3 then
command4 = 0
elseif selected == 4 then
command5 = 0
elseif selected == 5 then
command6 = 0
elseif selected == 6 then
command7 = 0
elseif selected == 7 then
command8 = 0
end
end
local physicalId, primId, dataId, value = sportTelemetryPop()
while physicalId ~= nil do
if dataId == 0x5200 then
command1 = value
sportTelemetryPush(0x1B, 0x30, 0x5201, 0x02)
elseif dataId == 0x5201 then
command2 = value
elseif dataId == 0x5202 then
command3 = value
elseif dataId == 0x5203 then
command4 = value
elseif dataId == 0x5204 then
command5 = value
elseif dataId == 0x5205 then
command6 = value
elseif dataId == 0x5206 then
command7 = value
elseif dataId == 0x5207 then
command8 = value
end
physicalId, primId, dataId, value = sportTelemetryPop()
end
lcd.clear()
lcd.drawFilledRectangle(0, 0, LCD_W, LCD_H, TEXT_BGCOLOR)
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, "Command Sensor Config", MENU_TITLE_COLOR)
lcd.drawText(1, 30, "command1: ", TEXT_COLOR)
if selected == 0 then
if command1 == 1 then
lcd.drawText(100, 30, "ON", LEFT + TEXT_COLOR + INVERS)
else
lcd.drawText(100, 30, "OFF", LEFT + TEXT_COLOR + INVERS)
end
else
if command1 == 1 then
lcd.drawText(100, 30, "ON", LEFT + TEXT_COLOR)
else
lcd.drawText(100, 30, "OFF", LEFT + TEXT_COLOR)
end
end
lcd.drawText(1, 55, "command2: ", TEXT_COLOR)
if selected == 1 then
if command2 == 1 then
lcd.drawText(100, 55, "ON", LEFT + TEXT_COLOR + INVERS)
else
lcd.drawText(100, 55, "OFF", LEFT + TEXT_COLOR + INVERS)
end
else
if command2 == 1 then
lcd.drawText(100, 55, "ON", LEFT + TEXT_COLOR)
else
lcd.drawText(100, 55, "OFF", LEFT + TEXT_COLOR)
end
end
lcd.drawText(1, 80, "command3: ", TEXT_COLOR)
if selected == 2 then
if command3 == 1 then
lcd.drawText(100, 80, "ON", LEFT + TEXT_COLOR + INVERS)
else
lcd.drawText(100, 80, "OFF", LEFT + TEXT_COLOR + INVERS)
end
else
if command3 == 1 then
lcd.drawText(100, 80, "ON", LEFT + TEXT_COLOR)
else
lcd.drawText(100, 80, "OFF", LEFT + TEXT_COLOR)
end
end
-- -------------------------------------
lcd.drawText(1, 105, "command4: ", TEXT_COLOR)
if selected == 3 then
if command4 == 1 then
lcd.drawText(100, 105, "ON", LEFT + TEXT_COLOR + INVERS)
else
lcd.drawText(100, 105, "OFF", LEFT + TEXT_COLOR + INVERS)
end
else
if command4 == 1 then
lcd.drawText(100, 105, "ON", LEFT + TEXT_COLOR)
else
lcd.drawText(100, 105, "OFF", LEFT + TEXT_COLOR)
end
end
lcd.drawText(1, 130, "command5: ", TEXT_COLOR)
if selected == 4 then
if command5 == 1 then
lcd.drawText(100, 130, "ON", LEFT + TEXT_COLOR + INVERS)
else
lcd.drawText(100, 130, "OFF", LEFT + TEXT_COLOR + INVERS)
end
else
if command5 == 1 then
lcd.drawText(100, 130, "ON", LEFT + TEXT_COLOR)
else
lcd.drawText(100, 130, "OFF", LEFT + TEXT_COLOR)
end
end
lcd.drawText(1, 155, "command6: ", TEXT_COLOR)
if selected == 5 then
if command6 == 1 then
lcd.drawText(100, 155, "ON", LEFT + TEXT_COLOR + INVERS)
else
lcd.drawText(100, 155, "OFF", LEFT + TEXT_COLOR + INVERS)
end
else
if command6 == 1 then
lcd.drawText(100, 155, "ON", LEFT + TEXT_COLOR)
else
lcd.drawText(100, 155, "OFF", LEFT + TEXT_COLOR)
end
end
lcd.drawText(1, 180, "command7: ", TEXT_COLOR)
if selected == 6 then
if command7 == 1 then
lcd.drawText(100, 180, "ON", LEFT + TEXT_COLOR + INVERS)
else
lcd.drawText(100, 180, "OFF", LEFT + TEXT_COLOR + INVERS)
end
else
if command7 == 1 then
lcd.drawText(100, 180, "ON", LEFT + TEXT_COLOR)
else
lcd.drawText(100, 180, "OFF", LEFT + TEXT_COLOR)
end
end
lcd.drawText(1, 205, "command8: ", TEXT_COLOR)
if selected == 7 then
if command8 == 1 then
lcd.drawText(100, 205, "ON", LEFT + TEXT_COLOR + INVERS)
else
lcd.drawText(100, 205, "OFF", LEFT + TEXT_COLOR + INVERS)
end
else
if command8 == 1 then
lcd.drawText(100, 205, "ON", LEFT + TEXT_COLOR)
else
lcd.drawText(100, 205, "OFF", LEFT + TEXT_COLOR)
end
end
lcd.drawText(1, 240, "Use TELE to update the selected value ", TEXT_COLOR)
lcd.setColor(CUSTOM_COLOR, WHITE)
lcd.drawText(170, 103, "Command " .. selected + 1 .. " ready !", CUSTOM_COLOR + DBLSIZE)
lcd.setColor(CUSTOM_COLOR, BLACK)
lcd.drawText(173, 100, "Command " .. selected + 1 .. " ready !", CUSTOM_COLOR + DBLSIZE)
return 0
end
return { init=init, run=run }