[Taranis] S6R script splitted into 3 pages, bitmaps added, calibration added (still no answer from X6R)

This commit is contained in:
Bertrand Songis
2016-05-17 23:43:13 +02:00
parent f27a87dea4
commit c13b5d064c
14 changed files with 146 additions and 37 deletions
@@ -4,15 +4,21 @@ local COMBO = 1
local COLUMN_2 = 150
local edit = false
local page = 1
local current = 1
local refreshState = 0
local refreshIndex = 0
local pageOffset = 0
local calibrationStep = 1
local pages = { }
local fields = {
local configFields = {
{"Wing type:", COMBO, 0x80, nil, { "Normal", "Delta", "VTail" } },
{"Mounting type:", COMBO, 0x81, nil, { "Horz", "Horz rev.", "Vert", "Vert rev." } },
}
local settingsFields = {
{"S6R functions:", COMBO, 0x9C, nil, { "Disable", "Enable" } },
{"Wing type:", COMBO, 0x80, nil, { "REA", "DELTA", "VTAIL" } },
{"Mounting type:", COMBO, 0x81, nil, { "Reverse", "Level rev.", "Upright", "Upright rev." } },
{"AIL direction:", COMBO, 0x82, nil, { "Normal", "Invers" }, { 255, 0 } },
{"ELE direction:", COMBO, 0x83, nil, { "Normal", "Invers" }, { 255, 0 } },
{"RUD direction:", COMBO, 0x84, nil, { "Normal", "Invers" }, { 255, 0 } },
@@ -33,7 +39,12 @@ local fields = {
{"RUD upright angle offset:", VALUE, 0x96, nil, -20, 20, "%", 0x6C},
{"AIL crab angle offset:", VALUE, 0x97, nil, -20, 20, "%", 0x6C},
{"RUD crab angle offset:", VALUE, 0x99, nil, -20, 20, "%", 0x6C},
-- {"Calib Accel. position:", COMBO, 0x9D, nil, { "Up", "Down", "Left", "Right", "Forward", "Back" } },
}
local calibrationFields = {
{"X:", VALUE, 0x9E, 0, -100, 100, "%"},
{"Y:", VALUE, 0x9F, 0, -100, 100, "%"},
{"Z:", VALUE, 0xA0, 0, -100, 100, "%"}
}
-- Change display attribute to current field
@@ -51,6 +62,13 @@ local function addField(step)
end
end
-- Select the next or previous page
local function selectPage(step)
page = 1 + ((page + step - 1 + #pages) % #pages)
refreshIndex = 0
calibrationStep = 1
end
-- Select the next or previous editable field
local function selectField(step)
current = 1 + ((current + step - 1 + #fields) % #fields)
@@ -62,15 +80,15 @@ local function selectField(step)
end
local function drawProgressBar()
local width = (160 * refreshIndex) / #fields
lcd.drawRectangle(48, 0, 164, 8)
lcd.drawFilledRectangle(50, 2, width, 4);
local width = (140 * refreshIndex) / #fields
lcd.drawRectangle(30, 1, 144, 6)
lcd.drawFilledRectangle(32, 3, width, 2);
end
-- Redraw the current page
local function redrawPage()
local function redrawFieldsPage()
lcd.clear()
lcd.drawScreenTitle("S6R", 0, 0)
lcd.drawScreenTitle("S6R", page, #pages)
if refreshIndex < #fields then
drawProgressBar()
@@ -78,9 +96,12 @@ local function redrawPage()
for index = 1, 7, 1 do
field = fields[pageOffset+index]
if field == nil then
break
end
attr = current == (pageOffset+index) and ((edit == true and BLINK or 0) + INVERS) or 0
-- display label
lcd.drawText(0, 1+8*index, field[1])
if field[4] == nil then
@@ -107,11 +128,16 @@ local function refreshNext()
telemetryPopTimeout = getTime() + 80 -- normal delay is 500ms
end
end
else
elseif refreshState == 1 then
field = fields[refreshIndex + 1]
physicalId, primId, dataId, value = telemetryPop()
if physicalId == 0x1A and primId == 0x32 and dataId == 0x0C30 and value % 256 == field[3] then
value = math.floor(value / 256)
if field[3] >= 0x9E and field[3] <= 0xA0 then
b1 = value % 256
b2 = math.floor(value / 256)
value = toInt16(b1*256 + b2)
end
if field[2] == COMBO and #field == 6 then
for index = 1, #(field[6]), 1 do
if value == field[6][index] then
@@ -128,9 +154,24 @@ local function refreshNext()
elseif getTime() > telemetryPopTimeout then
refreshState = 0
end
elseif refreshState == 2 then
physicalId, primId, dataId, value = telemetryPop()
if physicalId == 0x1A and primId == 0x32 and dataId == 0x0C30 and value % 256 == 0x9D then
refreshState = 0
calibrationStep = calibrationStep + 1
end
end
end
local function telemetryWrite(field, value)
telemetryPush(0x1A, 0x31, 0x0C30, field + value*256)
end
local function calibrationStart()
refreshState = 2
telemetryWrite(0x9D, calibrationStep)
end
local function updateField(field)
value = field[4]
if field[2] == COMBO and #field == 6 then
@@ -138,12 +179,97 @@ local function updateField(field)
elseif field[2] == VALUE and #field == 8 then
value = value + field[8] - field[5]
end
telemetryPush(0x1A, 0x31, 0x0C30, field[3] + value*256)
telemetryWrite(field[3], value)
end
-- Main
local function runFieldsPage(event)
if event == EVT_EXIT_BREAK then -- exit script
return 2
elseif event == EVT_ENTER_BREAK then -- toggle editing/selecting current field
if fields[current][4] ~= nil then
edit = not edit
if edit == false then
updateField(fields[current])
end
end
elseif edit then
if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT then
addField(1)
elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT then
addField(-1)
end
else
if event == EVT_MINUS_FIRST then
selectField(1)
elseif event == EVT_PLUS_FIRST then
selectField(-1)
end
end
redrawFieldsPage()
return 0
end
local wingBitmaps = { "plane.bmp", "delta.bmp", "vtail.bmp" }
local mountBitmaps = { "horz.bmp", "horz-r.bmp", "vert.bmp", "vert-r.bmp" }
local function runConfigPage(event)
fields = configFields
result = runFieldsPage(event)
if fields[1][4] ~= nil then
lcd.drawPixmap(20, 28, wingBitmaps[1 + fields[1][4]])
end
if fields[2][4] ~= nil then
lcd.drawPixmap(128, 28, mountBitmaps[1 + fields[2][4]])
end
return result
end
local function runSettingsPage(event)
fields = settingsFields
return runFieldsPage(event)
end
local calibrationPositions = { "up", "down", "left", "right", "forward", "back" }
local function runCalibrationPage(event)
fields = calibrationFields
if refreshIndex == #fields then
-- refreshIndex = 0
end
lcd.clear()
lcd.drawScreenTitle("S6R", page, #pages)
local position = calibrationPositions[calibrationStep]
lcd.drawText(0, 9, "Turn the receiver " .. position, 0)
lcd.drawPixmap(10, 19, position .. ".bmp")
for index = 1, 3, 1 do
field = fields[pageOffset+index]
lcd.drawText(80, 12+10*index, field[1], 0)
lcd.drawNumber(90, 12+10*index, field[4]/10, LEFT+PREC2)
end
attr = refreshState == 2 and 0 or INVERS
lcd.drawText(0, 56, "Press [Enter] when ready", attr)
if refreshState == 0 and event == EVT_ENTER_BREAK then
calibrationStart()
elseif event == EVT_EXIT_BREAK then
if calibrationStep > 1 then
calibrationStep = 1
else
return 2
end
end
return 0
end
-- Init
local function init()
current, edit, refreshState, refreshIndex = 1, false, 0, 0
pages = {
runConfigPage,
runSettingsPage,
runCalibrationPage
}
end
-- Main
@@ -151,33 +277,16 @@ local function run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_EXIT_BREAK then -- exit script
return 2
elseif event == EVT_ENTER_BREAK then -- toggle editing/selecting current field
if fields[current][4] ~= nil then
edit = not edit
if edit == false then
updateField(fields[current])
end
end
redrawPage()
elseif edit then
if event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT then
addField(1)
elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT then
addField(-1)
end
redrawPage()
else
if event == EVT_MINUS_FIRST then
selectField(1)
elseif event == EVT_PLUS_FIRST then
selectField(-1)
end
redrawPage()
elseif event == EVT_PAGE_BREAK then
selectPage(1)
elseif event == EVT_PAGE_LONG then
selectPage(-1)
end
result = pages[page](event)
refreshNext()
return 0
return result
end
return { init=init, run=run }
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB