Skip to content

Virtual events (WiP) #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/BF/bf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
170 changes: 85 additions & 85 deletions src/SCRIPTS/BF/MSP/messages.lua
Original file line number Diff line number Diff line change
@@ -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
29 changes: 0 additions & 29 deletions src/SCRIPTS/BF/events.lua

This file was deleted.

22 changes: 5 additions & 17 deletions src/SCRIPTS/BF/radios.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 16 additions & 17 deletions src/SCRIPTS/BF/ui.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local userEvent = assert(loadScript(SCRIPT_HOME.."/events.lua"))()

local pageStatus =
{
display = 2,
Expand Down Expand Up @@ -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
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file looks so much cleaner now! 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, a matter of taste as it seems :-) Anyway, that saves a bit of memory by avoiding the userEvent structure.

incValue(-1)
end
end
Expand Down
Loading