From 3ee37466fd5904cb71818790181d9cc04e6eadb4 Mon Sep 17 00:00:00 2001 From: 3djc Date: Fri, 21 Sep 2018 19:04:56 +0200 Subject: [PATCH] Xlite/X7 multi wizard update (now includes switches) --- .../taranis-x7/SCRIPTS/WIZARD/multi.lua | 158 ++++++++++++++++-- 1 file changed, 143 insertions(+), 15 deletions(-) diff --git a/radio/sdcard/taranis-x7/SCRIPTS/WIZARD/multi.lua b/radio/sdcard/taranis-x7/SCRIPTS/WIZARD/multi.lua index 6c5c9fe52..a1072cd44 100755 --- a/radio/sdcard/taranis-x7/SCRIPTS/WIZARD/multi.lua +++ b/radio/sdcard/taranis-x7/SCRIPTS/WIZARD/multi.lua @@ -19,7 +19,10 @@ local THROTTLE_PAGE = 0 local ROLL_PAGE = 1 local PITCH_PAGE = 2 local YAW_PAGE = 3 -local CONFIRMATION_PAGE = 4 +local ARM_PAGE = 4 +local BEEPER_PAGE = 5 +local MODE_PAGE = 6 +local CONFIRMATION_PAGE = 7 -- Navigation variables local page = THROTTLE_PAGE @@ -28,12 +31,17 @@ local edit = false local field = 0 local fieldsMax = 0 local comboBoxMode = 0 -- Scrap variable +local validSwitch = {} -- Model settings local thrCH1 = 0 local rollCH1 = 0 local yawCH1 = 0 local pitchCH1 = 0 +local armSW1 = 1 +local beeperSW1 = 1 +local modeSW1 = 1 +local switches = {} -- Common functions local lastBlink = 0 @@ -50,10 +58,10 @@ end local function fieldIncDec(event, value, max, force) if edit or force==true then - if event == EVT_ROT_RIGHT or event == EVT_UP_BREAK then + if event == EVT_ROT_RIGHT then value = (value + max) dirty = true - elseif event == EVT_ROT_LEFT or event == EVT_DOWN_BREAK then + elseif event == EVT_ROT_LEFT then value = (value + max + 2) dirty = true end @@ -64,12 +72,12 @@ end local function valueIncDec(event, value, min, max) if edit then - if event == EVT_ROT_RIGHT or event == EVT_RIGHT_BREAK then + if event == EVT_ROT_RIGHT or event == EVT_RIGHT_FIRST then if value < max then value = (value + 1) dirty = true end - elseif event == EVT_ROT_LEFT or event == EVT_LEFT_BREAK then + elseif event == EVT_ROT_LEFT or event == EVT_LEFT_FIRST then if value > min then value = (value - 1) dirty = true @@ -91,11 +99,11 @@ local function navigate(event, fieldMax, prevPage, nextPage) dirty = blinkChanged() end else - if event == EVT_PAGE_BREAK or event==EVT_RIGHT_BREAK then + if event == EVT_PAGE_BREAK or event == EVT_RIGHT_FIRST then page = nextPage field = 0 dirty = true - elseif event == EVT_PAGE_LONG or event==EVT_LEFT_BREAK then + elseif event == EVT_PAGE_LONG or event == EVT_LEFT_FIRST then page = prevPage field = 0 killEvents(event); @@ -127,12 +135,45 @@ local function channelIncDec(event, value) return value end +local function switchValueIncDec(event, value, min, max) + if edit then + if event == EVT_ROT_RIGHT or event == EVT_RIGHT_FIRST then + if value < max then + value = (value + 1) + dirty = true + end + elseif event == EVT_ROT_LEFT or event == EVT_LEFT_FIRST then + if value > min then + value = (value - 1) + dirty = true + end + end + end + return value +end + +local function switchIncDec(event, value) + if not edit and event==EVT_MENU_BREAK then + servoPage = value + dirty = true + else + value = switchValueIncDec(event, value, 1, #switches) + end + return value +end + -- Init function local function init() thrCH1 = defaultChannel(2) rollCH1 = defaultChannel(3) yawCH1 = defaultChannel(0) pitchCH1 = defaultChannel(1) + local ver, radio, maj, minor, rev = getVersion() + if string.match(radio, "x7") then + switches = {"SA", "SB", "SC", "SD", "SF", "SH"} + else + switches = {"SA", "SB", "SC", "SD"} + end end -- Throttle Menu @@ -219,10 +260,84 @@ local function yawMenu(event) yawCH1 = channelIncDec(event, yawCH1) end +-- Arm Menu +local function drawArmMenu() + lcd.clear() + lcd.drawText(1, 0, "Multicopter", 0) + lcd.drawFilledRectangle(0, 0, LCD_W, 8, FILL_WHITE) + lcd.drawCombobox(0, 8, LCD_W, {"Arm"}, comboBoxMode, getFieldFlags(1)) + lcd.drawText(5, 30, "Assign AUX1", 0); + lcd.drawText(5, 40, ">>>", 0); + lcd.drawText(25, 40, switches[armSW1], getFieldFlags(0)) + fieldsMax = 0 +end + +local function armMenu(event) + if dirty then + dirty = false + drawArmMenu() + end + navigate(event, fieldsMax, page-1, page+1) + armSW1 = switchIncDec(event, armSW1) +end + +-- Beeper Menu +local function drawbeeperMenu() + lcd.clear() + lcd.drawText(1, 0, "Multicopter", 0) + lcd.drawFilledRectangle(0, 0, LCD_W, 8, FILL_WHITE) + lcd.drawCombobox(0, 8, LCD_W, {"Beeper"}, comboBoxMode, getFieldFlags(1)) + lcd.drawText(5, 30, "Assign AUX2", 0); + lcd.drawText(5, 40, ">>>", 0); + lcd.drawText(25, 40, switches[beeperSW1], getFieldFlags(0)) + fieldsMax = 0 +end + +local function beeperMenu(event) + if dirty then + dirty = false + drawbeeperMenu() + end + navigate(event, fieldsMax, page-1, page+1) + beeperSW1 = switchIncDec(event, beeperSW1) +end + +-- Mode Menu +local function drawmodeMenu() + lcd.clear() + lcd.drawText(1, 0, "Multicopter", 0) + lcd.drawFilledRectangle(0, 0, LCD_W, 8, FILL_WHITE) + lcd.drawCombobox(0, 8, LCD_W, {"Mode"}, comboBoxMode, getFieldFlags(1)) + lcd.drawText(5, 30, "Assign AUX3", 0); + lcd.drawText(5, 40, ">>>", 0); + lcd.drawText(25, 40, switches[modeSW1], getFieldFlags(0)) + fieldsMax = 0 +end + +local function modeMenu(event) + if dirty then + dirty = false + drawmodeMenu() + end + navigate(event, fieldsMax, page-1, page+1) + modeSW1 = switchIncDec(event, modeSW1) +end + -- Confirmation Menu local function drawNextLine(x, y, label, channel) lcd.drawText(x, y, label, 0); - lcd.drawSource(x+52, y, MIXSRC_CH1+channel, 0) + lcd.drawSource(x+50, y, MIXSRC_CH1+channel, 0) + y = y + 8 + if y > 50 then + y = 12 + x = 120 + end + return x, y +end + +local function drawNextSWLine(x, y, label, switch) + lcd.drawText(x, y, label, 0); + lcd.drawText(x+42, y, switches[switch], 0) y = y + 8 if y > 50 then y = 12 @@ -232,15 +347,20 @@ local function drawNextLine(x, y, label, channel) end local function drawConfirmationMenu() - local x = 22 + local x = 1 local y = 12 lcd.clear() lcd.drawText(0, 1, "Ready to go?", 0); lcd.drawFilledRectangle(0, 0, LCD_W, 9, 0) - x, y = drawNextLine(x, y, "Throttle", thrCH1) - x, y = drawNextLine(x, y, "Roll", rollCH1) - x, y = drawNextLine(x, y, "Pitch", pitchCH1) - x, y = drawNextLine(x, y, "Yaw", yawCH1) + x, y = drawNextLine(x, y, "Throttle:", thrCH1) + x, y = drawNextLine(x, y, "Roll:", rollCH1) + x, y = drawNextLine(x, y, "Pitch:", pitchCH1) + x, y = drawNextLine(x, y, "Yaw:", yawCH1) + local x = 72 + local y = 12 + x, y = drawNextSWLine(x, y, "Arm:", armSW1) + x, y = drawNextSWLine(x, y, "Beeper:", beeperSW1) + x, y = drawNextSWLine(x, y, "Mode:", modeSW1) lcd.drawText(0, LCD_H-8, "[Enter Long] to confirm", 0); lcd.drawFilledRectangle(0, LCD_H-9, LCD_W, 9, 0) fieldsMax = 0 @@ -260,10 +380,13 @@ end local function applySettings() model.defaultInputs() model.deleteMixes() - addMix(thrCH1, MIXSRC_FIRST_INPUT+defaultChannel(2), "Engine") + addMix(thrCH1, MIXSRC_FIRST_INPUT+defaultChannel(2), "Throttle") addMix(rollCH1, MIXSRC_FIRST_INPUT+defaultChannel(3), "Roll") addMix(yawCH1, MIXSRC_FIRST_INPUT+defaultChannel(0), "Yaw") addMix(pitchCH1, MIXSRC_FIRST_INPUT+defaultChannel(1), "Pitch") + addMix(4, MIXSRC_SA + armSW1 - 1, "Arm") + addMix(5, MIXSRC_SA + beeperSW1 - 1, "Beeper") + addMix(6, MIXSRC_SA + modeSW1 - 1, "Mode") end local function confirmationMenu(event) @@ -290,7 +413,6 @@ local function run(event) if event == nil then error("Cannot be run as a model script!") end - if page == THROTTLE_PAGE then throttleMenu(event) elseif page == ROLL_PAGE then @@ -299,6 +421,12 @@ local function run(event) yawMenu(event) elseif page == PITCH_PAGE then pitchMenu(event) + elseif page == ARM_PAGE then + armMenu(event) + elseif page == BEEPER_PAGE then + beeperMenu(event) + elseif page == MODE_PAGE then + modeMenu(event) elseif page == CONFIRMATION_PAGE then return confirmationMenu(event) end