From 79b461eda85b5e7c40316df260b39241736e29bf Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Tue, 3 Jun 2014 18:53:14 +0200 Subject: [PATCH] Added multicopter wizard page to OpenTX lua wizard. The images are just place holders. --- radio/wizard/multi-pitch.bmp | Bin 0 -> 1466 bytes radio/wizard/multi-roll.bmp | Bin 0 -> 1466 bytes radio/wizard/multi-thr.bmp | Bin 0 -> 1466 bytes radio/wizard/multi-yaw.bmp | Bin 0 -> 1466 bytes radio/wizard/multi.lua | 306 +++++++++++++++++++++++++++++++++++ radio/wizard/wizard.lua | 1 + 6 files changed, 307 insertions(+) create mode 100644 radio/wizard/multi-pitch.bmp create mode 100644 radio/wizard/multi-roll.bmp create mode 100644 radio/wizard/multi-thr.bmp create mode 100644 radio/wizard/multi-yaw.bmp create mode 100755 radio/wizard/multi.lua diff --git a/radio/wizard/multi-pitch.bmp b/radio/wizard/multi-pitch.bmp new file mode 100644 index 0000000000000000000000000000000000000000..5ec1543302f851cf3c9784343cd424e750fd41f4 GIT binary patch literal 1466 zcmb7@zfK!L5XL76A_a+ne8h-^|>f{lmcu$rxZg#@xf)#{59bSTVpi z*L1GqmgoM#*YAwpGnN({&a#a1Jf~W%M)i7~8jS`un@wu9TGVd0snh9Duh*k~zfZ&A zkVc~sjmKk}OePfO2WQAM>=$rhF}{F%mFl{Hn^F?Y^C%BN42*lSLhM@MD9KK;%(Hi* z*KV{TUgdtqV@gr6%)jB5QWRJOt4Oj+oNYC&R-$ga*BzK_C|0Vb#ziCCr}lD|!_vPR z$&=6=95;W2Dcpbif5zN!!UMn4BUo+0OOuPQ=}|s?;_e?1o(}Pk{gKb4X=|4cNg@q^ z{pL{jh}SrTi)!jro`G2j!r`L#m#iv(1r~^C)`<9Zus&bi##hTB)!S|dn}0t}V|QFu z!X1Ub1K5}Av3)+4@*?=M?3OoM@~FTnoLu4QV_6P15tsj?!ik*2ck|`+Ty)}{=<(=& zI?ALn*6~R5a|{IvGM?7Y`@14M;reHn#VGF$_p3#C%)-V-&LDPX{UPMZh5IZxmy1$L zvHta8pA@*hxSZdPeB(U-+v!vkAZFv$>7Y56}Vz}Cyqw7xq|N%P2e`}=|n0JaD-4uSWCE+Pa{ZTIorK@Nbc2Pn(m~B^Yq?cSYk4LE)ZcV zO?$IQU-XBR_`+cC+{OpO(GSxu@b%(2fn>w0b6NBU1bwe%_>J^gu3vj`^n3dg18)+6 zRWk53J3rj?KGD^8g|+eteDtjwJ^#2XYSvf*SJKw;&$A0B?;$aH|8^pLi3`h#A~sF% oK^v&R&95aF&|JUbu{18|^WEAPDX|NDZphbIipcmSZ+<}d4}q*b`2YX_ literal 0 HcmV?d00001 diff --git a/radio/wizard/multi-thr.bmp b/radio/wizard/multi-thr.bmp new file mode 100644 index 0000000000000000000000000000000000000000..6547592d63414028c3605f8a8b1dbf24580f3ea2 GIT binary patch literal 1466 zcmb7^y-Gtt5QRrkK`gEy*0B^U@&ppFv66rum0OAZ%BA+=gf>h-!b8VzYSo6>5vq}^^yr_+&MuP6O}Uj~DLj7B3FkH<2ZOk_Hp zO8niBp|EgR!pXv)JebtRCHmxO2ETcd$4CR`LA(&3=Qv7A05W=KdbbxotA1(ZD_bbE#|H7f)Mm${zB$B6dK*_UYl+~&xg|l$i_iul055FHuE5E8h6aeXNbf!r?$3TjdrL4H6~s&T9$g<1>J%S9@uN~I!Ih(Vw$ zQmS^PGIFKvSQ%nDgs_?SX7_Y!oWcV;dpmF5eC=N6X!b}bGu6ksUg(R+F3v}-p zAmUC)`&83Y93{a)H_#Zn!MAQ`AkOm^uT!EYHM=`_oBf*)`QcJ#=FDkYtaPAMx{H-jQxdJ3Er%q-o z|9FM?cY)zP=vmiiCoSE53F&QXYS|-VD&irn_wTNf8?Ev9 WMAknW?Ct#27%I;HhbQ)UaPkkNw>pFX literal 0 HcmV?d00001 diff --git a/radio/wizard/multi.lua b/radio/wizard/multi.lua new file mode 100755 index 000000000..176ef8297 --- /dev/null +++ b/radio/wizard/multi.lua @@ -0,0 +1,306 @@ +-- Multicopter Wizard pages +local THROTTLE_PAGE = 0 +local ROLL_PAGE = 1 +local PITCH_PAGE = 2 +local YAW_PAGE = 3 +local CONFIRMATION_PAGE = 4 + +-- Navigation variables +local page = THROTTLE_PAGE +local dirty = true +local edit = false +local field = 0 +local fieldsMax = 0 +local comboBoxMode = 0 -- Scrap variable + +-- Model settings +local thrCH1 = 0 +local rollCH1 = 0 +local yawCH1 = 0 +local pitchCH1 = 0 + +-- 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 fieldIncDec(event, value, max, force) + if edit or force==true then + if event == EVT_PLUS_BREAK then + value = (value + max) + dirty = true + elseif event == EVT_MINUS_BREAK then + value = (value + max + 2) + dirty = true + end + value = (value % (max+1)) + end + return value +end + +local function valueIncDec(event, value, min, max) + if edit then + if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT then + if value < max then + value = (value + 1) + dirty = true + end + elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT then + if value > min then + value = (value - 1) + dirty = true + end + end + end + return value +end + +local function navigate(event, fieldMax, prevPage, nextPage) + if event == EVT_ENTER_BREAK then + edit = not edit + dirty = true + elseif edit then + if event == EVT_EXIT_BREAK then + edit = false + dirty = true + elseif not dirty then + dirty = blinkChanged() + end + else + if event == EVT_PAGE_BREAK then + page = nextPage + field = 0 + dirty = true + elseif event == EVT_PAGE_LONG then + page = prevPage + field = 0 + killEvents(event); + dirty = true + else + field = fieldIncDec(event, field, fieldMax, true) + end + end +end + +local function getFieldFlags(position) + flags = 0 + if field == position then + flags = INVERS + if edit then + flags = INVERS + BLINK + end + end + return flags +end + +local function channelIncDec(event, value) + if not edit and event==EVT_MENU_BREAK then + servoPage = value + dirty = true + else + value = valueIncDec(event, value, 0, 15) + end + return value +end + +-- Init function +local function init() + thrCH1 = defaultChannel(2) + rollCH1 = defaultChannel(3) + yawCH1 = defaultChannel(0) + pitchCH1 = defaultChannel(1) +end + +-- Throttle Menu +local function drawThrottleMenu() + lcd.clear() + lcd.drawText(1, 0, "Select multicopter throttle channel", 0) + lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE) + lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1)) + lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H, DOTTED, 0) + lcd.drawPixmap(132, 18, "multi-thr.bmp") + lcd.drawText(20, LCD_H-16, "Assign Throttle", 0); + lcd.drawText(20, LCD_H-8, "Channel", 0); + lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0); + lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+thrCH1, getFieldFlags(0)) + fieldsMax = 0 +end + +local function throttleMenu(event) + if dirty then + dirty = false + drawThrottleMenu() + end + navigate(event, fieldsMax, page, page+1) + thrCH1 = channelIncDec(event, thrCH1) +end + +-- Roll Menu +local function drawRollMenu() + lcd.clear() + lcd.drawText(1, 0, "Select multicopter roll channel", 0) + lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE) + lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1)) + lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H, DOTTED, 0) + lcd.drawPixmap(132, 18, "multi-roll.bmp") + lcd.drawText(20, LCD_H-16, "Assign Roll", 0); + lcd.drawText(20, LCD_H-8, "Channel", 0); + lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0); + lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+rollCH1, getFieldFlags(0)) + fieldsMax = 0 +end + +local function rollMenu(event) + if dirty then + dirty = false + drawRollMenu() + end + navigate(event, fieldsMax, page-1, page+1) + rollCH1 = channelIncDec(event, rollCH1) +end + +-- Pitch Menu +local function drawPitchMenu() + lcd.clear() + lcd.drawText(1, 0, "Select multicopter pitch channel", 0) + lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE) + lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1)) + lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H, DOTTED, 0) + lcd.drawPixmap(132, 18, "multi-pitch.bmp") + lcd.drawText(20, LCD_H-16, "Assign Pitch", 0); + lcd.drawText(20, LCD_H-8, "Channel", 0); + lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0); + lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+pitchCH1, getFieldFlags(0)) + fieldsMax = 0 +end + +local function pitchMenu(event) + if dirty then + dirty = false + drawPitchMenu() + end + navigate(event, fieldsMax, page-1, page+1) + pitchCH1 = channelIncDec(event, pitchCH1) +end + +-- Yaw Menu +local function drawYawMenu() + lcd.clear() + lcd.drawText(1, 0, "Select multicopter yaw channel", 0) + lcd.drawFilledRectangle(0, 0, LCD_W, 8, GREY_DEFAULT+FILL_WHITE) + lcd.drawCombobox(0, 8, LCD_W/2, {"..."}, comboBoxMode, getFieldFlags(1)) + lcd.drawLine(LCD_W/2-1, 18, LCD_W/2-1, LCD_H, DOTTED, 0) + lcd.drawPixmap(132, 18, "multi-yaw.bmp") + lcd.drawText(20, LCD_H-16, "Assign Yaw", 0); + lcd.drawText(20, LCD_H-8, "Channel", 0); + lcd.drawText(LCD_W/2-19, LCD_H-8, ">>>", 0); + lcd.drawSource(113, LCD_H-8, MIXSRC_CH1+yawCH1, getFieldFlags(0)) + fieldsMax = 0 +end + +local function yawMenu(event) + if dirty then + dirty = false + drawYawMenu() + end + navigate(event, fieldsMax, page-1, page+1) + yawCH1 = channelIncDec(event, yawCH1) +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) + y = y + 8 + if y > 50 then + y = 12 + x = 120 + end + return x, y +end + +local function drawConfirmationMenu() + local x = 22 + local y = 12 + lcd.clear() + lcd.drawText(48, 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) + lcd.drawText(48, LCD_H-8, "[Enter Long] to confirm", 0); + lcd.drawFilledRectangle(0, LCD_H-9, LCD_W, 9, 0) + lcd.drawPixmap(LCD_W-18, 0, "confirm-tick.bmp") + lcd.drawPixmap(0, LCD_H-17, "confirm-plane.bmp") + fieldsMax = 0 +end + +local function addMix(channel, input, name, weight, index) + local mix = { source=input, name=name } + if weight ~= nil then + mix.weight = weight + end + if index == nil then + index = 0 + end + model.insertMix(channel, index, mix) +end + +local function applySettings() + model.defaultInputs() + model.deleteMixes() + 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") +end + +local function confirmationMenu(event) + if dirty then + dirty = false + drawConfirmationMenu() + end + + navigate(event, fieldsMax, YAW_PAGE, page) + + if event == EVT_EXIT_BREAK then + return 2 + elseif event == EVT_ENTER_LONG then + killEvents(event) + applySettings() + return 2 + else + return 0 + end +end + +-- Main +local function run(event) + if event == nil then + error("Cannot be run as a model script!") + end + lcd.lock() + if page == THROTTLE_PAGE then + throttleMenu(event) + elseif page == ROLL_PAGE then + rollMenu(event) + elseif page == YAW_PAGE then + yawMenu(event) + elseif page == PITCH_PAGE then + pitchMenu(event) + elseif page == CONFIRMATION_PAGE then + return confirmationMenu(event) + end + return 0 +end + +return { init=init, run=run } diff --git a/radio/wizard/wizard.lua b/radio/wizard/wizard.lua index 3d6345134..22ac3db46 100755 --- a/radio/wizard/wizard.lua +++ b/radio/wizard/wizard.lua @@ -50,6 +50,7 @@ local function modelTypeMenu(event) elseif modelType == MODELTYPE_DELTA then return "delta.lua" elseif modelType == MODELTYPE_QUAD then + return "multi.lua" end dirty = true else