diff --git a/src/BF/bf.lua b/src/BF/bf.lua index a61c46b2..eb4da1c0 100644 --- a/src/BF/bf.lua +++ b/src/BF/bf.lua @@ -9,6 +9,8 @@ assert(loadScript(radio.preLoad))() assert(loadScript(protocol.transport))() assert(loadScript(SCRIPT_HOME.."/MSP/common.lua"))() +isTelemetryScript = false + local run_ui = assert(loadScript(SCRIPT_HOME.."/ui.lua"))() return { run=run_ui } diff --git a/src/SCRIPTS/BF/MSP/messages.lua b/src/SCRIPTS/BF/MSP/messages.lua index da922df2..c778be8a 100644 --- a/src/SCRIPTS/BF/MSP/messages.lua +++ b/src/SCRIPTS/BF/MSP/messages.lua @@ -1,85 +1,85 @@ -MSP_PID_FORMAT = { - read = 112, -- MSP_PID - write = 202, -- MSP_SET_PID - minBytes = 8, - fields = { - -- P - { vals = { 1 } }, - { vals = { 4 } }, - { vals = { 7 } }, - -- I - { vals = { 2 } }, - { vals = { 5 } }, - { vals = { 8 } }, - -- D - { vals = { 3 } }, - { vals = { 6 } }, - }, -} - -MSP_PID_ADVANCED_FORMAT = { - read = 94, -- MSP_PID_ADVANCED - write = 95, -- MSP_SET_PID_ADVANCED - minBytes = 23, - fields = { - -- weight - { vals = { 10 }, scale = 100 }, - -- transition - { vals = { 9 }, scale = 100 }, - }, -} - -local INTRO_DELAY = 1600 -local READOUT_DELAY = 500 - -function extractMspValues(cmd, rx_buf, msgFormat, msgValues) - if cmd == nil or rx_buf == nil then - return - end - if cmd ~= msgFormat.read then - return - end - if #(rx_buf) > 0 then - msgValues.raw = {} - for i=1,#(rx_buf) do - msgValues.raw[i] = rx_buf[i] - end - - msgValues.values = {} - for i=1,#(msgFormat.fields) do - if (#(msgValues.raw) or 0) >= msgFormat.minBytes then - local f = msgFormat.fields[i] - if f.vals then - local value = 0; - for idx=1, #(f.vals) do - local raw_val = msgValues.raw[f.vals[idx]] - raw_val = bit32.lshift(raw_val, (idx-1)*8) - value = bit32.bor(value, raw_val) - end - msgValues.values[i] = value/(f.scale or 1) - end - end - end - end -end - -function readoutMsp(msgFormat, msg) - local t = getTime() - if msg.lastTrigger == nil or msg.lastTrigger + INTRO_DELAY <= t then - playFile(msg.intro) - msg.lastTrigger = t - elseif msg.reqTS == nil or msg.reqTS + READOUT_DELAY <= t then - protocol.mspRead(msgFormat.read) - msg.reqTS = t - else - local cmd, rx_buf = mspPollReply() - extractMspValues(cmd, rx_buf, msgFormat, msg) - if msg.raw then - for i=1,#(msg.readoutValues) do - playNumber(msg.values[msg.readoutValues[i]], 0) - end - msg.raw = nil - end - end - mspProcessTxQ() -end +MSP_PID_FORMAT = { + read = 112, -- MSP_PID + write = 202, -- MSP_SET_PID + minBytes = 8, + fields = { + -- P + { vals = { 1 } }, + { vals = { 4 } }, + { vals = { 7 } }, + -- I + { vals = { 2 } }, + { vals = { 5 } }, + { vals = { 8 } }, + -- D + { vals = { 3 } }, + { vals = { 6 } }, + }, +} + +MSP_PID_ADVANCED_FORMAT = { + read = 94, -- MSP_PID_ADVANCED + write = 95, -- MSP_SET_PID_ADVANCED + minBytes = 23, + fields = { + -- weight + { vals = { 10 }, scale = 100 }, + -- transition + { vals = { 9 }, scale = 100 }, + }, +} + +local INTRO_DELAY = 1600 +local READOUT_DELAY = 500 + +function extractMspValues(cmd, rx_buf, msgFormat, msgValues) + if cmd == nil or rx_buf == nil then + return + end + if cmd ~= msgFormat.read then + return + end + if #(rx_buf) > 0 then + msgValues.raw = {} + for i=1,#(rx_buf) do + msgValues.raw[i] = rx_buf[i] + end + + msgValues.values = {} + for i=1,#(msgFormat.fields) do + if (#(msgValues.raw) or 0) >= msgFormat.minBytes then + local f = msgFormat.fields[i] + if f.vals then + local value = 0; + for idx=1, #(f.vals) do + local raw_val = msgValues.raw[f.vals[idx]] + raw_val = bit32.lshift(raw_val, (idx-1)*8) + value = bit32.bor(value, raw_val) + end + msgValues.values[i] = value/(f.scale or 1) + end + end + end + end +end + +function readoutMsp(msgFormat, msg) + local t = getTime() + if msg.lastTrigger == nil or msg.lastTrigger + INTRO_DELAY <= t then + playFile(msg.intro) + msg.lastTrigger = t + elseif msg.reqTS == nil or msg.reqTS + READOUT_DELAY <= t then + protocol.mspRead(msgFormat.read) + msg.reqTS = t + else + local cmd, rx_buf = mspPollReply() + extractMspValues(cmd, rx_buf, msgFormat, msg) + if msg.raw then + for i=1,#(msg.readoutValues) do + playNumber(msg.values[msg.readoutValues[i]], 0) + end + msg.raw = nil + end + end + mspProcessTxQ() +end diff --git a/src/SCRIPTS/BF/events.lua b/src/SCRIPTS/BF/events.lua deleted file mode 100644 index eedecb76..00000000 --- a/src/SCRIPTS/BF/events.lua +++ /dev/null @@ -1,29 +0,0 @@ - -return -{ - press = { - minus = EVT_MINUS_FIRST, - plus = EVT_PLUS_FIRST, - pageDown = EVT_PAGEDN_FIRST, - pageUp = EVT_PAGEUP_FIRST or EVT_LEFT_BREAK - }, - longPress = { - enter = EVT_ENTER_LONG, - menu = EVT_MENU_LONG or EVT_RIGHT_LONG - }, - repeatPress = { - minus = EVT_MINUS_REPT, - plus = EVT_PLUS_REPT - }, - release = { - enter = EVT_ENTER_BREAK or EVT_ROT_BREAK, - exit = EVT_EXIT_BREAK, - menu = EVT_MENU_BREAK or EVT_RIGHT_BREAK, - minus = EVT_MINUS_BREAK, - plus = EVT_PLUS_BREAK - }, - dial = { - left = EVT_ROT_LEFT or EVT_UP_BREAK, - right = EVT_ROT_RIGHT or EVT_DOWN_BREAK - } -} diff --git a/src/SCRIPTS/BF/radios.lua b/src/SCRIPTS/BF/radios.lua index f4516acc..84cb77c3 100644 --- a/src/SCRIPTS/BF/radios.lua +++ b/src/SCRIPTS/BF/radios.lua @@ -33,26 +33,14 @@ local supportedPlatforms = { local supportedRadios = { - ["x3"] = supportedPlatforms.x7, - ["x7"] = supportedPlatforms.x7, - ["x7s"] = supportedPlatforms.x7, - ["t12"] = supportedPlatforms.x7, - ["xlite"] = supportedPlatforms.x7, - ["xlites"] = supportedPlatforms.x7, - ["x9lite"] = supportedPlatforms.x7, - ["x9d"] = supportedPlatforms.x9, - ["x9d+"] = supportedPlatforms.x9, - ["x9d+2019"] = supportedPlatforms.x9, - ["x9e"] = supportedPlatforms.x9, - ["x10"] = supportedPlatforms.horus, - ["x10express"] = supportedPlatforms.horus, - ["x12s"] = supportedPlatforms.horus, - ["NV14"] = supportedPlatforms.nv14, - ["t16"] = supportedPlatforms.horus, + ["128x64"] = supportedPlatforms.x7, + ["212x64"] = supportedPlatforms.x9, + ["480x272"] = supportedPlatforms.horus, + ["320x480"] = supportedPlatforms.nv14, } local ver, rad, maj, min, rev = getVersion() -local radio = supportedRadios[rad] +local radio = supportedRadios[tostring(LCD_W) .. "x" .. tostring(LCD_H)] if not radio then error("Radio not supported: "..rad) diff --git a/src/SCRIPTS/BF/ui.lua b/src/SCRIPTS/BF/ui.lua index f61c7568..e4430fed 100644 --- a/src/SCRIPTS/BF/ui.lua +++ b/src/SCRIPTS/BF/ui.lua @@ -1,5 +1,3 @@ -local userEvent = assert(loadScript(SCRIPT_HOME.."/events.lua"))() - local pageStatus = { display = 2, @@ -302,22 +300,22 @@ function run_ui(event) -- process send queue mspProcessTxQ() -- navigation - if (event == userEvent.longPress.menu) then -- Taranis QX7 / X9 + if isTelemetryScript and event == EVT_VIRTUAL_MENU_LONG then -- telemetry script menuActive = 1 currentState = pageStatus.displayMenu - elseif userEvent.press.pageDown and (event == userEvent.longPress.enter) then -- Horus + elseif (not isTelemetryScript) and event == EVT_VIRTUAL_ENTER_LONG then -- standalone menuActive = 1 killEnterBreak = 1 currentState = pageStatus.displayMenu -- menu is currently displayed elseif currentState == pageStatus.displayMenu then - if event == userEvent.release.exit then + if event == EVT_VIRTUAL_EXIT then currentState = pageStatus.display - elseif event == userEvent.release.plus or event == userEvent.dial.left then + elseif event == EVT_VIRTUAL_PREV then incMenu(-1) - elseif event == userEvent.release.minus or event == userEvent.dial.right then + elseif event == EVT_VIRTUAL_NEXT then incMenu(1) - elseif event == userEvent.release.enter then + elseif event == EVT_VIRTUAL_ENTER then if killEnterBreak == 1 then killEnterBreak = 0 else @@ -327,30 +325,31 @@ function run_ui(event) end -- normal page viewing elseif currentState <= pageStatus.display then - if event == userEvent.press.pageUp then + if event == EVT_VIRTUAL_PREV_PAGE then incPage(-1) - elseif event == userEvent.release.menu or event == userEvent.press.pageDown then + killEvents(event) -- X10/T16 issue: pageUp is a long press + elseif event == EVT_VIRTUAL_NEXT_PAGE or event == EVT_VIRTUAL_MENU then incPage(1) - elseif event == userEvent.release.plus or event == userEvent.repeatPress.plus or event == userEvent.dial.left then + elseif event == EVT_VIRTUAL_PREV or event == EVT_VIRTUAL_PREV_REPT then incLine(-1) - elseif event == userEvent.release.minus or event == userEvent.repeatPress.minus or event == userEvent.dial.right then + elseif event == EVT_VIRTUAL_NEXT or event == EVT_VIRTUAL_NEXT_REPT then incLine(1) - elseif event == userEvent.release.enter then + elseif event == EVT_VIRTUAL_ENTER then local field = Page.fields[currentLine] local idx = field.i or currentLine if Page.values and Page.values[idx] and (field.ro ~= true) then currentState = pageStatus.editing end - elseif event == userEvent.release.exit then + elseif event == EVT_VIRTUAL_EXIT then return protocol.exitFunc(); end -- editing value elseif currentState == pageStatus.editing then - if (event == userEvent.release.exit) or (event == userEvent.release.enter) then + if event == EVT_VIRTUAL_EXIT or event == EVT_VIRTUAL_ENTER then currentState = pageStatus.display - elseif event == userEvent.press.plus or event == userEvent.repeatPress.plus or event == userEvent.dial.right then + elseif event == EVT_VIRTUAL_INC or event == EVT_VIRTUAL_INC_REPT then incValue(1) - elseif event == userEvent.press.minus or event == userEvent.repeatPress.minus or event == userEvent.dial.left then + elseif event == EVT_VIRTUAL_DEC or event == EVT_VIRTUAL_DEC_REPT then incValue(-1) end end diff --git a/src/SCRIPTS/FUNCTIONS/pids.lua b/src/SCRIPTS/FUNCTIONS/pids.lua index 35a151b2..2b207643 100644 --- a/src/SCRIPTS/FUNCTIONS/pids.lua +++ b/src/SCRIPTS/FUNCTIONS/pids.lua @@ -1,44 +1,44 @@ -SCRIPT_HOME = "/SCRIPTS/BF" - -assert(loadScript(SCRIPT_HOME.."/MSP/messages.lua"))() - -local msg_p = { - intro = "p.wav", - readoutValues = {1, 2, 3}, -} - -local msg_i = { - intro = "i.wav", - readoutValues = {4, 5, 6}, -} - -local msg_d = { - intro = "d.wav", - readoutValues = {7, 8}, -} - -local msg_dsetpt = { - intro = "dsetpt.wav", - readoutValues = {1, 2}, -} - -local pidSelectorField = nil - -local function init_pids() - pidSelectorField = getFieldInfo("trim-thr") -end - -local function run_pids() - local pidSelector = getValue(pidSelectorField.id) - if pidSelector > 33 and pidSelector < 99 then - readoutMsp(MSP_PID_FORMAT, msg_p) - elseif pidSelector > 99 and pidSelector < 165 then - readoutMsp(MSP_PID_FORMAT, msg_i) - elseif pidSelector > 165 and pidSelector < 231 then - readoutMsp(MSP_PID_FORMAT, msg_d) - elseif pidSelector > -99 and pidSelector < -33 then - readoutMsp(MSP_PID_ADVANCED_FORMAT, msg_dsetpt) - end -end - -return { init = init_pids, run = run_pids } \ No newline at end of file +SCRIPT_HOME = "/SCRIPTS/BF" + +assert(loadScript(SCRIPT_HOME.."/MSP/messages.lua"))() + +local msg_p = { + intro = "p.wav", + readoutValues = {1, 2, 3}, +} + +local msg_i = { + intro = "i.wav", + readoutValues = {4, 5, 6}, +} + +local msg_d = { + intro = "d.wav", + readoutValues = {7, 8}, +} + +local msg_dsetpt = { + intro = "dsetpt.wav", + readoutValues = {1, 2}, +} + +local pidSelectorField = nil + +local function init_pids() + pidSelectorField = getFieldInfo("trim-thr") +end + +local function run_pids() + local pidSelector = getValue(pidSelectorField.id) + if pidSelector > 33 and pidSelector < 99 then + readoutMsp(MSP_PID_FORMAT, msg_p) + elseif pidSelector > 99 and pidSelector < 165 then + readoutMsp(MSP_PID_FORMAT, msg_i) + elseif pidSelector > 165 and pidSelector < 231 then + readoutMsp(MSP_PID_FORMAT, msg_d) + elseif pidSelector > -99 and pidSelector < -33 then + readoutMsp(MSP_PID_ADVANCED_FORMAT, msg_dsetpt) + end +end + +return { init = init_pids, run = run_pids } diff --git a/src/SCRIPTS/TELEMETRY/bf.lua b/src/SCRIPTS/TELEMETRY/bf.lua index 906ac8fa..1e2ea964 100644 --- a/src/SCRIPTS/TELEMETRY/bf.lua +++ b/src/SCRIPTS/TELEMETRY/bf.lua @@ -9,6 +9,8 @@ assert(loadScript(radio.preLoad))() assert(loadScript(protocol.transport))() assert(loadScript(SCRIPT_HOME.."/MSP/common.lua"))() +isTelemetryScript = true + local run_ui = assert(loadScript(SCRIPT_HOME.."/ui.lua"))() local background = assert(loadScript(SCRIPT_HOME.."/background.lua"))()