New UI merged
@@ -0,0 +1,121 @@
|
||||
---- #########################################################################
|
||||
---- # #
|
||||
---- # Copyright (C) OpenTX #
|
||||
-----# #
|
||||
---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
|
||||
---- # #
|
||||
---- # This program is free software; you can redistribute it and/or modify #
|
||||
---- # it under the terms of the GNU General Public License version 2 as #
|
||||
---- # published by the Free Software Foundation. #
|
||||
---- # #
|
||||
---- # This program is distributed in the hope that it will be useful #
|
||||
---- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
---- # GNU General Public License for more details. #
|
||||
---- # #
|
||||
---- #########################################################################
|
||||
local devices = { }
|
||||
local lineIndex = 1
|
||||
local pageOffset = 0
|
||||
|
||||
local function createDevice(id, name)
|
||||
local device = {
|
||||
id = id,
|
||||
name = name,
|
||||
timeout = 0
|
||||
}
|
||||
return device
|
||||
end
|
||||
|
||||
local function getDevice(name)
|
||||
for i=1, #devices do
|
||||
if devices[i].name == name then
|
||||
return devices[i]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function parseDeviceInfoMessage(data)
|
||||
local id = data[2]
|
||||
local name = ""
|
||||
local i = 3
|
||||
while data[i] ~= 0 do
|
||||
name = name .. string.char(data[i])
|
||||
i = i + 1
|
||||
end
|
||||
local device = getDevice(name)
|
||||
if device == nil then
|
||||
device = createDevice(id, name)
|
||||
devices[#devices + 1] = device
|
||||
end
|
||||
local time = getTime()
|
||||
device.timeout = time + 3000 -- 30s
|
||||
if lineIndex == 0 then
|
||||
lineIndex = 1
|
||||
end
|
||||
end
|
||||
|
||||
local devicesRefreshTimeout = 0
|
||||
local function refreshNext()
|
||||
local command, data = crossfireTelemetryPop()
|
||||
if command == nil then
|
||||
local time = getTime()
|
||||
if time > devicesRefreshTimeout then
|
||||
devicesRefreshTimeout = time + 100 -- 1s
|
||||
crossfireTelemetryPush(0x28, { 0x00, 0xEA })
|
||||
end
|
||||
elseif command == 0x29 then
|
||||
parseDeviceInfoMessage(data)
|
||||
end
|
||||
end
|
||||
|
||||
local function selectDevice(step)
|
||||
lineIndex = 1 + ((lineIndex + step - 1 + #devices) % #devices)
|
||||
end
|
||||
|
||||
-- Init
|
||||
local function init()
|
||||
lineIndex = 0
|
||||
pageOffset = 0
|
||||
end
|
||||
|
||||
NoCross = { 110, LCD_H - 28, "Waiting for Crossfire devices...", TEXT_COLOR + INVERS + BLINK }
|
||||
|
||||
-- Main
|
||||
local function run(event)
|
||||
if event == nil then
|
||||
error("Cannot be run as a model script!")
|
||||
return 2
|
||||
elseif event == EVT_EXIT_BREAK then
|
||||
return 2
|
||||
elseif event == EVT_ROT_LEFT then
|
||||
selectDevice(1)
|
||||
elseif event == EVT_ROT_RIGHT then
|
||||
selectDevice(-1)
|
||||
end
|
||||
|
||||
lcd.clear()
|
||||
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
|
||||
lcd.drawText(1, 5,"CROSSFIRE SETUP", MENU_TITLE_COLOR)
|
||||
|
||||
|
||||
if #devices == 0 then
|
||||
lcd.drawText(NoCross[1],NoCross[2],NoCross[3],NoCross[4])
|
||||
else
|
||||
for i=1, #devices do
|
||||
local attr = (lineIndex == i and INVERS or 0)
|
||||
if event == EVT_ROT_BREAK and attr == INVERS then
|
||||
crossfireTelemetryPush(0x28, { devices[i].id, 0xEA })
|
||||
return "device.lua"
|
||||
end
|
||||
lcd.drawText(5, i*22+10, devices[i].name, attr)
|
||||
end
|
||||
end
|
||||
|
||||
refreshNext()
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
return { init=init, run=run }
|
||||
@@ -0,0 +1,533 @@
|
||||
---- #########################################################################
|
||||
---- # #
|
||||
---- # Copyright (C) OpenTX #
|
||||
-----# #
|
||||
---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
|
||||
---- # #
|
||||
---- # This program is free software; you can redistribute it and/or modify #
|
||||
---- # it under the terms of the GNU General Public License version 2 as #
|
||||
---- # published by the Free Software Foundation. #
|
||||
---- # #
|
||||
---- # This program is distributed in the hope that it will be useful #
|
||||
---- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
---- # GNU General Public License for more details. #
|
||||
---- # #
|
||||
---- #########################################################################
|
||||
local deviceId = 0
|
||||
local deviceName = ""
|
||||
local lineIndex = 0
|
||||
local pageOffset = 0
|
||||
local edit = false
|
||||
local charIndex = 1
|
||||
local fieldPopup
|
||||
local fieldTimeout = 0
|
||||
local fieldId = 1
|
||||
local fieldChunk = 0
|
||||
local fieldData = {}
|
||||
local fields = {}
|
||||
|
||||
local function getField(line)
|
||||
local counter = 1
|
||||
for i = 1, #fields do
|
||||
local field = fields[i]
|
||||
if not field.hidden then
|
||||
if counter < line then
|
||||
counter = counter + 1
|
||||
else
|
||||
return field
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function initLineIndex()
|
||||
lineIndex = 0
|
||||
for i = 1, #fields do
|
||||
local field = getField(i)
|
||||
if field and field.type ~= 11 and field.type ~= 12 and field.name ~= nil then
|
||||
lineIndex = i
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Change display attribute to current field
|
||||
local function incrField(step)
|
||||
local field = getField(lineIndex)
|
||||
if field.type == 10 then
|
||||
local byte = 32
|
||||
if charIndex <= #field.value then
|
||||
byte = string.byte(field.value, charIndex) + step
|
||||
end
|
||||
if byte < 32 then
|
||||
byte = 32
|
||||
elseif byte > 122 then
|
||||
byte = 122
|
||||
end
|
||||
if charIndex <= #field.value then
|
||||
field.value = string.sub(field.value, 1, charIndex-1) .. string.char(byte) .. string.sub(field.value, charIndex+1)
|
||||
else
|
||||
field.value = field.value .. string.char(byte)
|
||||
end
|
||||
else
|
||||
local min, max = 0, 0
|
||||
if field.type <= 5 then
|
||||
min = field.min
|
||||
max = field.max
|
||||
step = field.step * step
|
||||
elseif field.type == 9 then
|
||||
min = 0
|
||||
max = #field.values - 1
|
||||
end
|
||||
if (step < 0 and field.value > min) or (step > 0 and field.value < max) then
|
||||
field.value = field.value + step
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Select the next or previous editable field
|
||||
local function selectField(step)
|
||||
local newLineIndex = lineIndex
|
||||
local field
|
||||
repeat
|
||||
newLineIndex = newLineIndex + step
|
||||
if newLineIndex == 0 then
|
||||
newLineIndex = #fields
|
||||
elseif newLineIndex == 1 + #fields then
|
||||
newLineIndex = 1
|
||||
pageOffset = 0
|
||||
end
|
||||
field = getField(newLineIndex)
|
||||
until newLineIndex == lineIndex or (field and field.type ~= 11 and field.name)
|
||||
lineIndex = newLineIndex
|
||||
if lineIndex > 11 + pageOffset then -- NOTE: increased from 7 to 11 to allow 11 lines in Horus display
|
||||
pageOffset = lineIndex - 11 -- NOTE: increased from 7 to 11 to allow 11 lines in Horus display
|
||||
elseif lineIndex <= pageOffset then
|
||||
pageOffset = lineIndex - 1
|
||||
end
|
||||
end
|
||||
|
||||
local function split(str)
|
||||
local t = {}
|
||||
local i = 1
|
||||
for s in string.gmatch(str, "([^;]+)") do
|
||||
t[i] = s
|
||||
i = i + 1
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
local function fieldGetString(data, offset)
|
||||
local result = ""
|
||||
while data[offset] ~= 0 do
|
||||
result = result .. string.char(data[offset])
|
||||
offset = offset + 1
|
||||
end
|
||||
offset = offset + 1
|
||||
return result, offset
|
||||
end
|
||||
|
||||
local function parseDeviceInfoMessage(data)
|
||||
local offset
|
||||
deviceId = data[2]
|
||||
deviceName, offset = fieldGetString(data, 3)
|
||||
local fields_count = data[offset+12]
|
||||
for i=1, fields_count do
|
||||
fields[i] = { name=nil }
|
||||
end
|
||||
end
|
||||
|
||||
local function fieldGetValue(data, offset, size)
|
||||
local result = 0
|
||||
for i=0, size-1 do
|
||||
result = bit32.lshift(result, 8) + data[offset + i]
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function fieldUnsignedLoad(field, data, offset, size)
|
||||
field.value = fieldGetValue(data, offset, size)
|
||||
field.min = fieldGetValue(data, offset+size, size)
|
||||
field.max = fieldGetValue(data, offset+2*size, size)
|
||||
field.default = fieldGetValue(data, offset+3*size, size)
|
||||
field.unit, offset = fieldGetString(data, offset+4*size)
|
||||
field.step = 1
|
||||
end
|
||||
|
||||
local function fieldUnsignedToSigned(field, size)
|
||||
local bandval = bit32.lshift(0x80, (size-1)*8)
|
||||
field.value = field.value - bit32.band(field.value, bandval) * 2
|
||||
field.min = field.min - bit32.band(field.min, bandval) * 2
|
||||
field.max = field.max - bit32.band(field.max, bandval) * 2
|
||||
field.default = field.default - bit32.band(field.default, bandval) * 2
|
||||
end
|
||||
|
||||
local function fieldSignedLoad(field, data, offset, size)
|
||||
fieldUnsignedLoad(field, data, offset, size)
|
||||
fieldUnsignedToSigned(field, size)
|
||||
end
|
||||
|
||||
local function fieldIntSave(index, value, size)
|
||||
local frame = { deviceId, 0xEA, index }
|
||||
for i=size-1, 0, -1 do
|
||||
frame[#frame + 1] = (bit32.rshift(value, 8*i) % 256)
|
||||
end
|
||||
crossfireTelemetryPush(0x2D, frame)
|
||||
end
|
||||
|
||||
local function fieldUnsignedSave(field, size)
|
||||
local value = field.value
|
||||
fieldIntSave(field.id, value, size)
|
||||
end
|
||||
|
||||
local function fieldSignedSave(field, size)
|
||||
local value = field.value
|
||||
if value < 0 then
|
||||
value = bit32.lshift(0x100, (size-1)*8) + value
|
||||
end
|
||||
fieldIntSave(field.id, value, size)
|
||||
end
|
||||
|
||||
local function fieldIntDisplay(field, y, attr)
|
||||
-- lcd.drawNumber(140, y, field.value, LEFT + attr) -- NOTE: original code getLastPos not available in Horus
|
||||
-- lcd.drawText(lcd.getLastPos(), y, field.unit, attr) -- NOTE: original code getLastPos not available in Horus
|
||||
lcd.drawText(140, y, field.value .. field.unit, attr) -- NOTE: Concenated fields instead of get lastPos
|
||||
end
|
||||
|
||||
-- UINT8
|
||||
local function fieldUint8Load(field, data, offset)
|
||||
fieldUnsignedLoad(field, data, offset, 1)
|
||||
end
|
||||
|
||||
local function fieldUint8Save(field)
|
||||
fieldUnsignedSave(field, 1)
|
||||
end
|
||||
|
||||
-- INT8
|
||||
local function fieldInt8Load(field, data, offset)
|
||||
fieldSignedLoad(field, data, offset, 1)
|
||||
end
|
||||
|
||||
local function fieldInt8Save(field)
|
||||
fieldSignedSave(field, 1)
|
||||
end
|
||||
|
||||
-- UINT16
|
||||
local function fieldUint16Load(field, data, offset)
|
||||
fieldUnsignedLoad(field, data, offset, 2)
|
||||
end
|
||||
|
||||
local function fieldUint16Save(field)
|
||||
fieldUnsignedSave(field, 2)
|
||||
end
|
||||
|
||||
-- INT16
|
||||
local function fieldInt16Load(field, data, offset)
|
||||
fieldSignedLoad(field, data, offset, 2)
|
||||
end
|
||||
|
||||
local function fieldInt16Save(field)
|
||||
fieldSignedSave(field, 2)
|
||||
end
|
||||
|
||||
-- FLOAT
|
||||
local function fieldFloatLoad(field, data, offset)
|
||||
field.value = fieldGetValue(data, offset, 4)
|
||||
field.min = fieldGetValue(data, offset+4, 4)
|
||||
field.max = fieldGetValue(data, offset+8, 4)
|
||||
field.default = fieldGetValue(data, offset+12, 4)
|
||||
fieldUnsignedToSigned(field, 4)
|
||||
field.prec = data[offset+16]
|
||||
if field.prec > 2 then
|
||||
field.prec = 2
|
||||
end
|
||||
field.step = fieldGetValue(data, offset+17, 4)
|
||||
field.unit, offset = fieldGetString(data, offset+21)
|
||||
end
|
||||
|
||||
local function fieldFloatDisplay(field, y, attr)
|
||||
local attrnum
|
||||
if field.prec == 1 then
|
||||
attrnum = LEFT + attr + PREC1
|
||||
elseif field.prec == 2 then
|
||||
attrnum = LEFT + attr + PREC2
|
||||
else
|
||||
attrnum = LEFT + attr
|
||||
end
|
||||
-- lcd.drawNumber(140, y, field.value, attrnum) -- NOTE: original code getLastPos not available in Horus
|
||||
-- lcd.drawText(lcd.getLastPos(), y, field.unit, attr) -- NOTE: original code getLastPos not available in Horus
|
||||
lcd.drawText(140, y, field.value .. field.unit, attr) -- NOTE: Concenated fields instead of get lastPos
|
||||
end
|
||||
|
||||
local function fieldFloatSave(field)
|
||||
fieldUnsignedSave(field, 4)
|
||||
end
|
||||
|
||||
-- TEXT SELECTION
|
||||
local function fieldTextSelectionLoad(field, data, offset)
|
||||
local values
|
||||
values, offset = fieldGetString(data, offset)
|
||||
if values ~= "" then
|
||||
field.values = split(values)
|
||||
end
|
||||
field.value = data[offset]
|
||||
field.min = data[offset+1]
|
||||
field.max = data[offset+2]
|
||||
field.default = data[offset+3]
|
||||
field.unit, offset = fieldGetString(data, offset+4)
|
||||
end
|
||||
|
||||
local function fieldTextSelectionSave(field)
|
||||
crossfireTelemetryPush(0x2D, { deviceId, 0xEA, field.id, field.value })
|
||||
end
|
||||
|
||||
local function fieldTextSelectionDisplay(field, y, attr)
|
||||
-- lcd.drawText(140, y, field.values[field.value+1], attr) -- NOTE: original code getLastPos not available in Horus
|
||||
-- lcd.drawText(lcd.getLastPos(), y, field.unit, attr) -- NOTE: original code getLastPos not available in Horus
|
||||
lcd.drawText(140, y, field.values[field.value+1] .. field.unit, attr) -- NOTE: Concenated fields instead of get lastPos
|
||||
end
|
||||
|
||||
-- STRING
|
||||
local function fieldStringLoad(field, data, offset)
|
||||
field.value, offset = fieldGetString(data, offset)
|
||||
if #data >= offset then
|
||||
field.maxlen = data[offset]
|
||||
end
|
||||
end
|
||||
|
||||
local function fieldStringSave(field)
|
||||
local frame = { deviceId, 0xEA, field.id }
|
||||
for i=1, string.len(field.value) do
|
||||
frame[#frame + 1] = string.byte(field.value, i)
|
||||
end
|
||||
frame[#frame + 1] = 0
|
||||
crossfireTelemetryPush(0x2D, frame)
|
||||
end
|
||||
|
||||
local function fieldStringDisplay(field, y, attr)
|
||||
if edit == true and attr then
|
||||
-- lcd.drawText(140, y, field.value, FIXEDWIDTH) -- NOTE: FIXEDWIDTH unknown....
|
||||
-- lcd.drawText(134+6*charIndex, y, string.sub(field.value, charIndex, charIndex), FIXEDWIDTH + attr) -- NOTE: FIXEDWIDTH unknown....
|
||||
lcd.drawText(140, y, field.value, attr)
|
||||
lcd.drawText(134+6*charIndex, y, string.sub(field.value, charIndex, charIndex), attr)
|
||||
else
|
||||
lcd.drawText(140, y, field.value, attr)
|
||||
end
|
||||
end
|
||||
|
||||
local function fieldCommandLoad(field, data, offset)
|
||||
field.status = data[offset]
|
||||
field.timeout = data[offset+1]
|
||||
field.info, offset = fieldGetString(data, offset+2)
|
||||
if field.status < 2 or field.status > 3 then
|
||||
fieldPopup = nil
|
||||
end
|
||||
end
|
||||
|
||||
local function fieldCommandSave(field)
|
||||
if field.status == 0 then
|
||||
field.status = 1
|
||||
crossfireTelemetryPush(0x2D, { deviceId, 0xEA, field.id, field.status })
|
||||
fieldPopup = field
|
||||
fieldTimeout = getTime() + field.timeout
|
||||
end
|
||||
end
|
||||
|
||||
local function fieldCommandDisplay(field, y, attr)
|
||||
lcd.drawText(1, y, field.name, attr)
|
||||
if field.info ~= "" then
|
||||
lcd.drawText(140, y, "[" .. field.info .. "]")
|
||||
end
|
||||
end
|
||||
|
||||
local functions = {
|
||||
{ load=fieldUint8Load, save=fieldUint8Save, display=fieldIntDisplay },
|
||||
{ load=fieldInt8Load, save=fieldInt8Save, display=fieldIntDisplay },
|
||||
{ load=fieldUint16Load, save=fieldUint16Save, display=fieldIntDisplay },
|
||||
{ load=fieldInt16Load, save=fieldInt16Save, display=fieldIntDisplay },
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
{ load=fieldFloatLoad, save=fieldFloatSave, display=fieldFloatDisplay },
|
||||
{ load=fieldTextSelectionLoad, save=fieldTextSelectionSave, display=fieldTextSelectionDisplay },
|
||||
{ load=fieldStringLoad, save=fieldStringSave, display=fieldStringDisplay },
|
||||
nil,
|
||||
{ load=fieldStringLoad, save=fieldStringSave, display=fieldStringDisplay },
|
||||
{ load=fieldCommandLoad, save=fieldCommandSave, display=fieldCommandDisplay },
|
||||
}
|
||||
|
||||
local function parseParameterInfoMessage(data)
|
||||
if data[2] ~= deviceId or data[3] ~= fieldId then
|
||||
fieldData = {}
|
||||
fieldChunk = 0
|
||||
return
|
||||
end
|
||||
local field = fields[fieldId]
|
||||
local chunks = data[4]
|
||||
for i=5, #data do
|
||||
fieldData[#fieldData + 1] = data[i]
|
||||
end
|
||||
if chunks > 0 then
|
||||
fieldChunk = fieldChunk + 1
|
||||
else
|
||||
fieldChunk = 0
|
||||
field.id = fieldId
|
||||
field.parent = fieldData[1]
|
||||
field.type = fieldData[2] % 128
|
||||
field.hidden = (bit32.rshift(fieldData[2], 7) == 1)
|
||||
local name, i = fieldGetString(fieldData, 3)
|
||||
if name ~= "" then
|
||||
local indent = ""
|
||||
local parent = field.parent
|
||||
while parent ~= 0 do
|
||||
indent = indent .. " "
|
||||
parent = fields[parent].parent
|
||||
end
|
||||
field.name = indent .. name
|
||||
end
|
||||
if functions[field.type+1] then
|
||||
functions[field.type+1].load(field, fieldData, i)
|
||||
end
|
||||
if not fieldPopup then
|
||||
if lineIndex == 0 and field.hidden ~= true and field.type and field.type ~= 11 and field.type ~= 12 then
|
||||
initLineIndex()
|
||||
end
|
||||
fieldId = 1 + (fieldId % #fields)
|
||||
end
|
||||
fieldData = {}
|
||||
end
|
||||
end
|
||||
|
||||
local function refreshNext()
|
||||
local command, data = crossfireTelemetryPop()
|
||||
if command == nil then
|
||||
local time = getTime()
|
||||
if fieldPopup then
|
||||
if time > fieldTimeout then
|
||||
local frame = { deviceId, 0xEA, fieldPopup.id }
|
||||
crossfireTelemetryPush(0x2D, frame)
|
||||
fieldTimeout = time + fieldPopup.timeout
|
||||
end
|
||||
elseif time > fieldTimeout and not edit then
|
||||
crossfireTelemetryPush(0x2C, { deviceId, 0xEA, fieldId, fieldChunk })
|
||||
fieldTimeout = time + 200 -- 2s
|
||||
end
|
||||
elseif command == 0x29 then
|
||||
parseDeviceInfoMessage(data)
|
||||
elseif command == 0x2B then
|
||||
parseParameterInfoMessage(data)
|
||||
fieldTimeout = 0
|
||||
end
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function runDevicePage(event)
|
||||
if event == EVT_EXIT_BREAK then -- exit script
|
||||
if edit == true then
|
||||
edit = false
|
||||
local field = getField(lineIndex)
|
||||
fieldTimeout = getTime() + 200 -- 2s
|
||||
fieldId, fieldChunk = field.id, 0
|
||||
fieldData = {}
|
||||
functions[field.type+1].save(field)
|
||||
else
|
||||
return "crossfire.lua"
|
||||
end
|
||||
elseif event == EVT_ROT_BREAK then -- toggle editing/selecting current field
|
||||
local field = getField(lineIndex)
|
||||
if field.name then
|
||||
if field.type == 10 then
|
||||
if edit == false then
|
||||
edit = true
|
||||
charIndex = 1
|
||||
else
|
||||
charIndex = charIndex + 1
|
||||
end
|
||||
elseif field.type < 11 then
|
||||
edit = not edit
|
||||
end
|
||||
if edit == false then
|
||||
fieldTimeout = getTime() + 200 -- 2s
|
||||
fieldId, fieldChunk = field.id, 0
|
||||
fieldData = {}
|
||||
functions[field.type+1].save(field)
|
||||
end
|
||||
end
|
||||
elseif edit then
|
||||
if event == EVT_ROT_LEFT then
|
||||
incrField(1)
|
||||
elseif event == EVT_ROT_RIGHT then
|
||||
incrField(-1)
|
||||
end
|
||||
else
|
||||
if event == EVT_ROT_RIGHT then
|
||||
selectField(1)
|
||||
elseif event == EVT_ROT_LEFT then
|
||||
selectField(-1)
|
||||
end
|
||||
end
|
||||
|
||||
lcd.clear()
|
||||
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
|
||||
lcd.drawText(1, 5,deviceName, MENU_TITLE_COLOR)
|
||||
|
||||
for y = 1, 11 do
|
||||
local field = getField(pageOffset+y)
|
||||
if not field then
|
||||
break
|
||||
elseif field.name == nil then
|
||||
lcd.drawText(1, y*22+10, "...")
|
||||
else
|
||||
local attr = lineIndex == (pageOffset+y) and ((edit == true and BLINK or 0) + INVERS) or 0
|
||||
lcd.drawText(1, y*22+10, field.name)
|
||||
if functions[field.type+1] then
|
||||
functions[field.type+1].display(field, y*22+10, attr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
local function runPopupPage(event)
|
||||
local result
|
||||
if fieldPopup.status == 3 then
|
||||
result = popupConfirmation(fieldPopup.info, event)
|
||||
else
|
||||
result = popupWarning(fieldPopup.info, event)
|
||||
end
|
||||
if result == "OK" then
|
||||
crossfireTelemetryPush(0x2D, { deviceId, 0xEA, fieldPopup.id, 4 })
|
||||
elseif result == "CANCEL" then
|
||||
crossfireTelemetryPush(0x2D, { deviceId, 0xEA, fieldPopup.id, 5 })
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Init
|
||||
local function init()
|
||||
lineIndex, edit = 0, false
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function run(event)
|
||||
if event == nil then
|
||||
error("Cannot be run as a model script!")
|
||||
return 2
|
||||
end
|
||||
|
||||
local result
|
||||
if fieldPopup ~= nil then
|
||||
result = runPopupPage(event)
|
||||
else
|
||||
result = runDevicePage(event)
|
||||
end
|
||||
|
||||
refreshNext()
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return { init=init, run=run }
|
||||
@@ -0,0 +1,2 @@
|
||||
You can put firmware for your modules or radio in this folder.
|
||||
Files in this folder are NOT automaticaly applied.
|
||||
@@ -0,0 +1,3 @@
|
||||
2.2 : BMP renamed to IMAGES for consistency between Taranis and Horus.
|
||||
You can put your model and other graphic files in this directory.
|
||||
Format include bmp and png (including png with transparancy).
|
||||
@@ -0,0 +1 @@
|
||||
Logs files created by "SD Logs" special function will be stored in this directory.
|
||||
@@ -0,0 +1 @@
|
||||
This directory is for lua functions scripts.
|
||||
@@ -0,0 +1 @@
|
||||
This directory is for lua mixer scripts.
|
||||
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 77 KiB |
|
After Width: | Height: | Size: 659 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 506 B |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,485 @@
|
||||
---- #########################################################################
|
||||
---- # #
|
||||
---- # Copyright (C) OpenTX #
|
||||
-----# #
|
||||
---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
|
||||
---- # #
|
||||
---- # This program is free software; you can redistribute it and/or modify #
|
||||
---- # it under the terms of the GNU General Public License version 2 as #
|
||||
---- # published by the Free Software Foundation. #
|
||||
---- # #
|
||||
---- # This program is distributed in the hope that it will be useful #
|
||||
---- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
---- # GNU General Public License for more details. #
|
||||
---- # #
|
||||
---- #########################################################################
|
||||
local VALUE = 0
|
||||
local COMBO = 1
|
||||
|
||||
local edit = false
|
||||
local page = 1
|
||||
local current = 1
|
||||
local pages = {}
|
||||
local fields = {}
|
||||
|
||||
-- load common Bitmaps
|
||||
local ImgMarkBg = Bitmap.open("img/mark_bg.png")
|
||||
local BackgroundImg = Bitmap.open("img/background.png")
|
||||
local ImgPlane = Bitmap.open("img/plane.png")
|
||||
local ImgPageUp = Bitmap.open("img/pageup.png")
|
||||
local ImgPageDn = Bitmap.open("img/pagedn.png")
|
||||
|
||||
|
||||
-- Change display attribute to current field
|
||||
local function addField(step)
|
||||
local field = fields[current]
|
||||
local min, max
|
||||
if field[3] == VALUE then
|
||||
min = field[6]
|
||||
max = field[7]
|
||||
elseif field[3] == COMBO then
|
||||
min = 0
|
||||
max = #(field[6]) - 1
|
||||
end
|
||||
if (step < 0 and field[5] > min) or (step > 0 and field[5] < max) then
|
||||
field[5] = field[5] + step
|
||||
end
|
||||
end
|
||||
|
||||
-- Select the next or previous page
|
||||
local function selectPage(step)
|
||||
page = 1 + ((page + step - 1 + #pages) % #pages)
|
||||
edit = false
|
||||
current = 1
|
||||
end
|
||||
|
||||
-- Select the next or previous editable field
|
||||
local function selectField(step)
|
||||
repeat
|
||||
current = 1 + ((current + step - 1 + #fields) % #fields)
|
||||
until fields[current][4]==1
|
||||
end
|
||||
|
||||
-- Redraw the current page
|
||||
local function redrawFieldsPage(event)
|
||||
|
||||
for index = 1, 10, 1 do
|
||||
local field = fields[index]
|
||||
if field == nil then
|
||||
break
|
||||
end
|
||||
|
||||
local attr = current == (index) and ((edit == true and BLINK or 0) + INVERS) or 0
|
||||
attr = attr + TEXT_COLOR
|
||||
|
||||
if field[4] == 1 then
|
||||
if field[3] == VALUE then
|
||||
lcd.drawNumber(field[1], field[2], field[5], LEFT + attr)
|
||||
elseif field[3] == COMBO then
|
||||
if field[5] >= 0 and field[5] < #(field[6]) then
|
||||
lcd.drawText(field[1],field[2], field[6][1+field[5]], attr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function updateField(field)
|
||||
local value = field[5]
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function runFieldsPage(event)
|
||||
if event == EVT_EXIT_BREAK then -- exit script
|
||||
return 2
|
||||
elseif event == EVT_ENTER_BREAK or event == EVT_ROT_BREAK then -- toggle editing/selecting current field
|
||||
if fields[current][5] ~= 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_ROT_RIGHT or event == EVT_PLUS_REPT then
|
||||
addField(1)
|
||||
elseif event == EVT_MINUS_FIRST or event == EVT_ROT_LEFT or event == EVT_MINUS_REPT then
|
||||
addField(-1)
|
||||
end
|
||||
else
|
||||
if event == EVT_MINUS_FIRST or event == EVT_ROT_RIGHT then
|
||||
selectField(1)
|
||||
elseif event == EVT_PLUS_FIRST or event == EVT_ROT_LEFT then
|
||||
selectField(-1)
|
||||
end
|
||||
end
|
||||
redrawFieldsPage(event)
|
||||
return 0
|
||||
end
|
||||
|
||||
-- set visibility flags starting with SECOND field of fields
|
||||
local function setFieldsVisible(...)
|
||||
local arg={...}
|
||||
local cnt = 2
|
||||
for i,v in ipairs(arg) do
|
||||
fields[cnt][4] = v
|
||||
cnt = cnt + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- draws one letter mark
|
||||
local function drawMark(x, y, name)
|
||||
lcd.drawBitmap(ImgMarkBg, x, y)
|
||||
lcd.drawText(x+8, y+3, name, TEXT_COLOR)
|
||||
end
|
||||
|
||||
|
||||
local MotorFields = {
|
||||
{50, 50, COMBO, 1, 1, { "No", "Yes"} },
|
||||
{50, 127, COMBO, 1, 2, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } },
|
||||
}
|
||||
|
||||
local ImgEngine
|
||||
|
||||
local function runMotorConfig(event)
|
||||
lcd.clear()
|
||||
if ImgEngine == nil then
|
||||
ImgEngine = Bitmap.open("img/prop.png")
|
||||
end
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageDn, 455, 95)
|
||||
lcd.drawBitmap(ImgEngine, 310, 50)
|
||||
lcd.setColor(CUSTOM_COLOR, lcd.RGB(255, 255, 255))
|
||||
fields = MotorFields
|
||||
lcd.drawText(40, 20, "Does your model have a motor ?", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 45, 200, 30, CUSTOM_COLOR)
|
||||
fields[2][4]=0
|
||||
if fields[1][5] == 1 then
|
||||
lcd.drawText(40, 100, "What channel is it on ?", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
fields[2][4]=1
|
||||
end
|
||||
local result = runFieldsPage(event)
|
||||
return result
|
||||
end
|
||||
|
||||
-- fields format : {[1]x, [2]y, [3]COMBO, [4]visible, [5]default, [6]{values}}
|
||||
-- fields format : {[1]x, [2]y, [3]VALUE, [4]visible, [5]default, [6]min, [7]max}
|
||||
local AilFields = {
|
||||
{50, 50, COMBO, 1, 2, { "None", "One, or two with Y cable", "Two"} },
|
||||
{50, 127, COMBO, 1, 0, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, -- Ail1 chan
|
||||
{50, 167, COMBO, 1, 4, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, -- Ail2 chan
|
||||
}
|
||||
|
||||
local ImgAilR
|
||||
local ImgAilL
|
||||
|
||||
local function runAilConfig(event)
|
||||
lcd.clear()
|
||||
if ImgAilR == nil then
|
||||
ImgAilR = Bitmap.open("img/rail.png")
|
||||
ImgAilL = Bitmap.open("img/lail.png")
|
||||
end
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageUp, 0, 95)
|
||||
lcd.drawBitmap(ImgPageDn, 455, 95)
|
||||
lcd.drawBitmap(ImgPlane, 252, 100)
|
||||
fields = AilFields
|
||||
if fields[1][5] == 1 then
|
||||
lcd.drawBitmap(ImgAilR, 274, 123)
|
||||
lcd.drawBitmap(ImgAilL, 395, 235)
|
||||
drawMark(308, 115, "A")
|
||||
drawMark(422, 220, "A")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
setFieldsVisible(1, 0)
|
||||
elseif fields[1][5] == 2 then
|
||||
lcd.drawBitmap(ImgAilR, 274, 123)
|
||||
lcd.drawBitmap(ImgAilL, 395, 235)
|
||||
drawMark(308, 115, "A")
|
||||
drawMark(422, 220, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
setFieldsVisible(1, 1)
|
||||
else
|
||||
setFieldsVisible(0, 0)
|
||||
end
|
||||
lcd.drawText(40, 20, "Number of ailerons on your model ?", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 45, 400, 30, CUSTOM_COLOR)
|
||||
local result = runFieldsPage(event)
|
||||
return result
|
||||
end
|
||||
|
||||
local FlapsFields = {
|
||||
{50, 50, COMBO, 1, 0, { "No", "Yes, on one channel", "Yes, on two channels"} },
|
||||
{50, 127, COMBO, 1, 6, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } },
|
||||
{50, 167, COMBO, 1, 7, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } },
|
||||
}
|
||||
|
||||
local ImgFlp
|
||||
|
||||
local function runFlapsConfig(event)
|
||||
lcd.clear()
|
||||
if ImgFlp == nil then
|
||||
ImgFlp = Bitmap.open("img/flap.png")
|
||||
end
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageUp, 0, 95)
|
||||
lcd.drawBitmap(ImgPageDn, 455, 95)
|
||||
lcd.drawBitmap(ImgPlane, 252, 100)
|
||||
fields = FlapsFields
|
||||
if fields[1][5] == 1 then
|
||||
lcd.drawBitmap(ImgFlp, 315, 160)
|
||||
lcd.drawBitmap(ImgFlp, 358, 202)
|
||||
drawMark(332, 132, "A")
|
||||
drawMark(412, 215, "A")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
setFieldsVisible(1, 0)
|
||||
elseif fields[1][5] == 2 then
|
||||
lcd.drawBitmap(ImgFlp, 315, 160)
|
||||
lcd.drawBitmap(ImgFlp, 358, 202)
|
||||
drawMark(332, 132, "A")
|
||||
drawMark(412, 215, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
setFieldsVisible(1, 1)
|
||||
else
|
||||
setFieldsVisible(0, 0)
|
||||
end
|
||||
lcd.drawText(40, 20, "Does your model have flaps ?", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 45, 400, 30, CUSTOM_COLOR)
|
||||
local result = runFieldsPage(event)
|
||||
return result
|
||||
end
|
||||
|
||||
local TailFields = {
|
||||
{50, 50, COMBO, 1, 1, { "1 channel for Elevator, no Rudder", "One chan for Elevator, one for Rudder", "Two chans for Elevator, one for Rudder", "V Tail"} },
|
||||
{50, 127, COMBO, 1, 1, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, --ele
|
||||
{50, 167, COMBO, 1, 3, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, --rud
|
||||
{50, 207, COMBO, 0, 5, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, --ele2
|
||||
}
|
||||
|
||||
local ImgTail
|
||||
local ImgVTail
|
||||
local ImgTailRud
|
||||
|
||||
local function runTailConfig(event)
|
||||
lcd.clear()
|
||||
if ImgTail == nil then
|
||||
ImgTail = Bitmap.open("img/tail.png")
|
||||
ImgVTail = Bitmap.open("img/vtail.png")
|
||||
ImgTailRud = Bitmap.open("img/tailrud.png")
|
||||
end
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageUp, 0, 95)
|
||||
lcd.drawBitmap(ImgPageDn, 455, 95)
|
||||
fields = TailFields
|
||||
if fields[1][5] == 0 then
|
||||
lcd.drawBitmap(ImgTail, 252, 100)
|
||||
drawMark(360, 125, "A")
|
||||
drawMark(390, 155, "A")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
setFieldsVisible(1, 0, 0)
|
||||
end
|
||||
if fields[1][5] == 1 then
|
||||
lcd.drawBitmap(ImgTail, 252, 100)
|
||||
lcd.drawBitmap(ImgTailRud, 340, 100)
|
||||
drawMark(415, 150, "A")
|
||||
drawMark(380, 120, "A")
|
||||
drawMark(390, 185, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
setFieldsVisible(1, 1, 0)
|
||||
end
|
||||
if fields[1][5] == 2 then
|
||||
lcd.drawBitmap(ImgTail, 252, 100)
|
||||
lcd.drawBitmap(ImgTailRud, 340, 100)
|
||||
drawMark(415, 150, "A")
|
||||
drawMark(380, 120, "C")
|
||||
drawMark(390, 185, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
lcd.drawFilledRectangle(40, 202, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 204, "C")
|
||||
setFieldsVisible(1, 1, 1)
|
||||
end
|
||||
if fields[1][5] == 3 then
|
||||
lcd.drawBitmap(ImgVTail, 252, 100)
|
||||
drawMark(315, 110, "A")
|
||||
drawMark(382, 120, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
setFieldsVisible(1, 1, 0)
|
||||
end
|
||||
lcd.drawText(40, 20, "Pick the tail config of your model", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 45, 400, 30, CUSTOM_COLOR)
|
||||
local result = runFieldsPage(event)
|
||||
return result
|
||||
end
|
||||
|
||||
local lineIndex
|
||||
local function drawNextLine(text, text2)
|
||||
lcd.drawText(40, lineIndex, text, TEXT_COLOR)
|
||||
lcd.drawText(250, lineIndex, text2 + 1, TEXT_COLOR)
|
||||
lineIndex = lineIndex + 20
|
||||
end
|
||||
|
||||
local ConfigSummaryFields = {
|
||||
{110, 250, COMBO, 1, 0, { "No, I need to change something", "Yes, all is well, create the plane !"} },
|
||||
}
|
||||
|
||||
local ImgSummary
|
||||
|
||||
local function runConfigSummary(event)
|
||||
lcd.clear()
|
||||
if ImgSummary == nil then
|
||||
ImgSummary = Bitmap.open("img/summary.png")
|
||||
end
|
||||
fields = ConfigSummaryFields
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageUp, 0, 95)
|
||||
lcd.drawBitmap(ImgSummary, 300, 60)
|
||||
lineIndex = 40
|
||||
-- motors
|
||||
if(MotorFields[1][5] == 1) then
|
||||
drawNextLine("Motor chan :", MotorFields[2][5])
|
||||
elseif (MotorFields[1][5] == 2) then
|
||||
drawNextLine("Motor 1 chan :", MotorFields[2][5])
|
||||
drawNextLine("Motor 2 chan :", MotorFields[3][5])
|
||||
end
|
||||
-- ail
|
||||
if(AilFields[1][5] == 1) then
|
||||
drawNextLine("Aileron chan :",AilFields[2][5])
|
||||
elseif (AilFields[1][5] == 2) then
|
||||
drawNextLine("Aileron 1 chan :",AilFields[2][5])
|
||||
drawNextLine("Aileron 2 chan :",AilFields[3][5])
|
||||
end
|
||||
-- flaps
|
||||
if(FlapsFields[1][5] == 1) then
|
||||
drawNextLine("Flaps chan :",FlapsFields[2][5])
|
||||
elseif (FlapsFields[1][5] == 2) then
|
||||
drawNextLine("Flaps 1 chan :",FlapsFields[2][5])
|
||||
drawNextLine("Flaps 2 chan :",FlapsFields[3][5])
|
||||
end
|
||||
-- tail
|
||||
if(TailFields[1][5] == 0) then
|
||||
drawNextLine("Elevator chan :",TailFields[2][5])
|
||||
elseif (TailFields[1][5] == 1) then
|
||||
drawNextLine("Elevator chan :",TailFields[2][5])
|
||||
drawNextLine("Rudder chan :",TailFields[3][5])
|
||||
elseif (TailFields[1][5] == 2) then
|
||||
drawNextLine("Elevator 1 chan :",TailFields[2][5])
|
||||
drawNextLine("Rudder chan :",TailFields[3][5])
|
||||
drawNextLine("Elevator 2 chan :",TailFields[4][5])
|
||||
elseif (TailFields[1][5] == 3) then
|
||||
drawNextLine("V-Tail elevator :", TailFields[2][5])
|
||||
drawNextLine("V-Tail rudder :", TailFields[3][5])
|
||||
end
|
||||
local result = runFieldsPage(event)
|
||||
if(fields[1][5] == 1 and edit == false) then
|
||||
selectPage(1)
|
||||
end
|
||||
return result
|
||||
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 createModel(event)
|
||||
lcd.clear()
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgSummary, 300, 60)
|
||||
model.defaultInputs()
|
||||
model.deleteMixes()
|
||||
-- motor
|
||||
if(MotorFields[1][5] == 1) then
|
||||
addMix(MotorFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(2), "Motor")
|
||||
elseif (MotorFields[1][5] == 2) then
|
||||
addMix(MotorFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(2), "Motor1")
|
||||
addMix(MotorFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(2), "Motor2")
|
||||
end
|
||||
-- Ailerons
|
||||
if(AilFields[1][5] == 1) then
|
||||
addMix(AilFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(3), "Ail")
|
||||
elseif (AilFields[1][5] == 2) then
|
||||
addMix(AilFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(3), "AilL")
|
||||
addMix(AilFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(3), "AilR", -100)
|
||||
end
|
||||
-- Flaps
|
||||
if(FlapsFields[1][5] == 1) then
|
||||
addMix(FlapsFields[2][5], MIXSRC_SA, "Flaps")
|
||||
elseif (FlapsFields[1][5] == 2) then
|
||||
addMix(FlapsFields[2][5], MIXSRC_SA, "FlapsL")
|
||||
addMix(FlapsFields[3][5], MIXSRC_SA, "FlapsR")
|
||||
end
|
||||
-- Tail
|
||||
if(TailFields[1][5] == 0) then
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "Elev")
|
||||
elseif (TailFields[1][5] == 1) then
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "Elev")
|
||||
addMix(TailFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(0), "Rudder")
|
||||
elseif (TailFields[1][5] == 2) then
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "ElevL")
|
||||
addMix(TailFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(0), "Rudder")
|
||||
addMix(TailFields[4][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "ElevR")
|
||||
elseif (TailFields[1][5] == 3) then
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "V-EleL", 50)
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(0), "V-RudL", 50, 1)
|
||||
addMix(TailFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "V-EleR", 50)
|
||||
addMix(TailFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(0), "V-RudR", -50, 1)
|
||||
end
|
||||
lcd.drawText(70, 90, "Model successfully created !", TEXT_COLOR)
|
||||
lcd.drawText(100, 130, "Press RTN to exit", TEXT_COLOR)
|
||||
return 2
|
||||
end
|
||||
|
||||
-- Init
|
||||
local function init()
|
||||
current, edit = 1, false
|
||||
pages = {
|
||||
runMotorConfig,
|
||||
runAilConfig,
|
||||
runFlapsConfig,
|
||||
runTailConfig,
|
||||
runConfigSummary,
|
||||
createModel,
|
||||
}
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function run(event)
|
||||
if event == nil then
|
||||
error("Cannot be run as a model script!")
|
||||
return 2
|
||||
elseif (event == EVT_PAGE_BREAK or event == EVT_PAGEDN_FIRST) and page < #pages-1 then
|
||||
selectPage(1)
|
||||
elseif (event == EVT_PAGE_LONG or event == EVT_PAGEUP_FIRST) and page > 1 then
|
||||
killEvents(event);
|
||||
selectPage(-1)
|
||||
end
|
||||
|
||||
local result = pages[page](event)
|
||||
return result
|
||||
end
|
||||
|
||||
return { init=init, run=run }
|
||||
|
After Width: | Height: | Size: 7.0 KiB |
|
After Width: | Height: | Size: 77 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 506 B |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 10 KiB |
@@ -0,0 +1,485 @@
|
||||
---- #########################################################################
|
||||
---- # #
|
||||
---- # Copyright (C) OpenTX #
|
||||
-----# #
|
||||
---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
|
||||
---- # #
|
||||
---- # This program is free software; you can redistribute it and/or modify #
|
||||
---- # it under the terms of the GNU General Public License version 2 as #
|
||||
---- # published by the Free Software Foundation. #
|
||||
---- # #
|
||||
---- # This program is distributed in the hope that it will be useful #
|
||||
---- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
---- # GNU General Public License for more details. #
|
||||
---- # #
|
||||
---- #########################################################################
|
||||
local VALUE = 0
|
||||
local COMBO = 1
|
||||
|
||||
local edit = false
|
||||
local page = 1
|
||||
local current = 1
|
||||
local pages = {}
|
||||
local fields = {}
|
||||
|
||||
-- load common Bitmaps
|
||||
local ImgMarkBg = Bitmap.open("img/mark_bg.png")
|
||||
local BackgroundImg = Bitmap.open("img/background.png")
|
||||
local ImgPlane = Bitmap.open("img/plane.png")
|
||||
local ImgPageUp = Bitmap.open("img/pageup.png")
|
||||
local ImgPageDn = Bitmap.open("img/pagedn.png")
|
||||
|
||||
|
||||
-- Change display attribute to current field
|
||||
local function addField(step)
|
||||
local field = fields[current]
|
||||
local min, max
|
||||
if field[3] == VALUE then
|
||||
min = field[6]
|
||||
max = field[7]
|
||||
elseif field[3] == COMBO then
|
||||
min = 0
|
||||
max = #(field[6]) - 1
|
||||
end
|
||||
if (step < 0 and field[5] > min) or (step > 0 and field[5] < max) then
|
||||
field[5] = field[5] + step
|
||||
end
|
||||
end
|
||||
|
||||
-- Select the next or previous page
|
||||
local function selectPage(step)
|
||||
page = 1 + ((page + step - 1 + #pages) % #pages)
|
||||
edit = false
|
||||
current = 1
|
||||
end
|
||||
|
||||
-- Select the next or previous editable field
|
||||
local function selectField(step)
|
||||
repeat
|
||||
current = 1 + ((current + step - 1 + #fields) % #fields)
|
||||
until fields[current][4]==1
|
||||
end
|
||||
|
||||
-- Redraw the current page
|
||||
local function redrawFieldsPage(event)
|
||||
|
||||
for index = 1, 10, 1 do
|
||||
local field = fields[index]
|
||||
if field == nil then
|
||||
break
|
||||
end
|
||||
|
||||
local attr = current == (index) and ((edit == true and BLINK or 0) + INVERS) or 0
|
||||
attr = attr + TEXT_COLOR
|
||||
|
||||
if field[4] == 1 then
|
||||
if field[3] == VALUE then
|
||||
lcd.drawNumber(field[1], field[2], field[5], LEFT + attr)
|
||||
elseif field[3] == COMBO then
|
||||
if field[5] >= 0 and field[5] < #(field[6]) then
|
||||
lcd.drawText(field[1],field[2], field[6][1+field[5]], attr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function updateField(field)
|
||||
local value = field[5]
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function runFieldsPage(event)
|
||||
if event == EVT_EXIT_BREAK then -- exit script
|
||||
return 2
|
||||
elseif event == EVT_ENTER_BREAK or event == EVT_ROT_BREAK then -- toggle editing/selecting current field
|
||||
if fields[current][5] ~= 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_ROT_RIGHT or event == EVT_PLUS_REPT then
|
||||
addField(1)
|
||||
elseif event == EVT_MINUS_FIRST or event == EVT_ROT_LEFT or event == EVT_MINUS_REPT then
|
||||
addField(-1)
|
||||
end
|
||||
else
|
||||
if event == EVT_MINUS_FIRST or event == EVT_ROT_RIGHT then
|
||||
selectField(1)
|
||||
elseif event == EVT_PLUS_FIRST or event == EVT_ROT_LEFT then
|
||||
selectField(-1)
|
||||
end
|
||||
end
|
||||
redrawFieldsPage(event)
|
||||
return 0
|
||||
end
|
||||
|
||||
-- set visibility flags starting with SECOND field of fields
|
||||
local function setFieldsVisible(...)
|
||||
local arg={...}
|
||||
local cnt = 2
|
||||
for i,v in ipairs(arg) do
|
||||
fields[cnt][4] = v
|
||||
cnt = cnt + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- draws one letter mark
|
||||
local function drawMark(x, y, name)
|
||||
lcd.drawBitmap(ImgMarkBg, x, y)
|
||||
lcd.drawText(x+8, y+3, name, TEXT_COLOR)
|
||||
end
|
||||
|
||||
|
||||
local MotorFields = {
|
||||
{50, 50, COMBO, 1, 1, { "No", "Yes"} },
|
||||
{50, 127, COMBO, 1, 2, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } },
|
||||
}
|
||||
|
||||
local ImgEngine
|
||||
|
||||
local function runMotorConfig(event)
|
||||
lcd.clear()
|
||||
if ImgEngine == nil then
|
||||
ImgEngine = Bitmap.open("img/prop.png")
|
||||
end
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageDn, 455, 95)
|
||||
lcd.drawBitmap(ImgEngine, 310, 50)
|
||||
lcd.setColor(CUSTOM_COLOR, lcd.RGB(255, 255, 255))
|
||||
fields = MotorFields
|
||||
lcd.drawText(40, 20, "Does your model have a motor ?", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 45, 200, 30, CUSTOM_COLOR)
|
||||
fields[2][4]=0
|
||||
if fields[1][5] == 1 then
|
||||
lcd.drawText(40, 100, "What channel is it on ?", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
fields[2][4]=1
|
||||
end
|
||||
local result = runFieldsPage(event)
|
||||
return result
|
||||
end
|
||||
|
||||
-- fields format : {[1]x, [2]y, [3]COMBO, [4]visible, [5]default, [6]{values}}
|
||||
-- fields format : {[1]x, [2]y, [3]VALUE, [4]visible, [5]default, [6]min, [7]max}
|
||||
local AilFields = {
|
||||
{50, 50, COMBO, 1, 2, { "None", "One, or two with Y cable", "Two"} },
|
||||
{50, 127, COMBO, 1, 0, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, -- Ail1 chan
|
||||
{50, 167, COMBO, 1, 4, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, -- Ail2 chan
|
||||
}
|
||||
|
||||
local ImgAilR
|
||||
local ImgAilL
|
||||
|
||||
local function runAilConfig(event)
|
||||
lcd.clear()
|
||||
if ImgAilR == nil then
|
||||
ImgAilR = Bitmap.open("img/rail.png")
|
||||
ImgAilL = Bitmap.open("img/lail.png")
|
||||
end
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageUp, 0, 95)
|
||||
lcd.drawBitmap(ImgPageDn, 455, 95)
|
||||
lcd.drawBitmap(ImgPlane, 252, 100)
|
||||
fields = AilFields
|
||||
if fields[1][5] == 1 then
|
||||
lcd.drawBitmap(ImgAilR, 324, 123)
|
||||
lcd.drawBitmap(ImgAilL, 275, 210)
|
||||
drawMark(362, 132, "A")
|
||||
drawMark(302, 227, "A")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
setFieldsVisible(1, 0)
|
||||
elseif fields[1][5] == 2 then
|
||||
lcd.drawBitmap(ImgAilR, 324, 123)
|
||||
lcd.drawBitmap(ImgAilL, 275, 210)
|
||||
drawMark(362, 132, "A")
|
||||
drawMark(302, 227, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
setFieldsVisible(1, 1)
|
||||
else
|
||||
setFieldsVisible(0, 0)
|
||||
end
|
||||
lcd.drawText(40, 20, "Number of ailerons on your model ?", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 45, 400, 30, CUSTOM_COLOR)
|
||||
local result = runFieldsPage(event)
|
||||
return result
|
||||
end
|
||||
|
||||
local FlapsFields = {
|
||||
{50, 50, COMBO, 1, 0, { "No", "Yes, on one channel", "Yes, on two channels"} },
|
||||
{50, 127, COMBO, 1, 6, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } },
|
||||
{50, 167, COMBO, 1, 7, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } },
|
||||
}
|
||||
|
||||
local ImgFlp
|
||||
|
||||
local function runFlapsConfig(event)
|
||||
lcd.clear()
|
||||
if ImgFlp == nil then
|
||||
ImgFlp = Bitmap.open("img/flap.png")
|
||||
end
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageUp, 0, 95)
|
||||
lcd.drawBitmap(ImgPageDn, 455, 95)
|
||||
lcd.drawBitmap(ImgPlane, 252, 100)
|
||||
fields = FlapsFields
|
||||
if fields[1][5] == 1 then
|
||||
lcd.drawBitmap(ImgFlp, 315, 143)
|
||||
lcd.drawBitmap(ImgFlp, 285, 191)
|
||||
drawMark(362, 132, "A")
|
||||
drawMark(302, 227, "A")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
setFieldsVisible(1, 0)
|
||||
elseif fields[1][5] == 2 then
|
||||
lcd.drawBitmap(ImgFlp, 315, 143)
|
||||
lcd.drawBitmap(ImgFlp, 285, 191)
|
||||
drawMark(362, 132, "A")
|
||||
drawMark(302, 227, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
setFieldsVisible(1, 1)
|
||||
else
|
||||
setFieldsVisible(0, 0)
|
||||
end
|
||||
lcd.drawText(40, 20, "Does your model have flaps ?", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 45, 400, 30, CUSTOM_COLOR)
|
||||
local result = runFieldsPage(event)
|
||||
return result
|
||||
end
|
||||
|
||||
local TailFields = {
|
||||
{50, 50, COMBO, 1, 1, { "1 channel for Elevator, no Rudder", "One chan for Elevator, one for Rudder", "Two chans for Elevator, one for Rudder", "V Tail"} },
|
||||
{50, 127, COMBO, 1, 1, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, --ele
|
||||
{50, 167, COMBO, 1, 3, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, --rud
|
||||
{50, 207, COMBO, 0, 5, { "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8" } }, --ele2
|
||||
}
|
||||
|
||||
local ImgTail
|
||||
local ImgVTail
|
||||
local ImgTailRud
|
||||
|
||||
local function runTailConfig(event)
|
||||
lcd.clear()
|
||||
if ImgTail == nil then
|
||||
ImgTail = Bitmap.open("img/tail.png")
|
||||
ImgVTail = Bitmap.open("img/vtail.png")
|
||||
ImgTailRud = Bitmap.open("img/tailrud.png")
|
||||
end
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageUp, 0, 95)
|
||||
lcd.drawBitmap(ImgPageDn, 455, 95)
|
||||
fields = TailFields
|
||||
if fields[1][5] == 0 then
|
||||
lcd.drawBitmap(ImgTail, 252, 100)
|
||||
drawMark(275, 120, "A")
|
||||
drawMark(390, 155, "A")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
setFieldsVisible(1, 0, 0)
|
||||
end
|
||||
if fields[1][5] == 1 then
|
||||
lcd.drawBitmap(ImgTail, 252, 100)
|
||||
lcd.drawBitmap(ImgTailRud, 340, 100)
|
||||
drawMark(275, 120, "A")
|
||||
drawMark(390, 155, "A")
|
||||
drawMark(370, 112, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
setFieldsVisible(1, 1, 0)
|
||||
end
|
||||
if fields[1][5] == 2 then
|
||||
lcd.drawBitmap(ImgTail, 252, 100)
|
||||
lcd.drawBitmap(ImgTailRud, 340, 100)
|
||||
drawMark(275, 120, "A")
|
||||
drawMark(390, 155, "C")
|
||||
drawMark(370, 112, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
lcd.drawFilledRectangle(40, 202, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 204, "C")
|
||||
setFieldsVisible(1, 1, 1)
|
||||
end
|
||||
if fields[1][5] == 3 then
|
||||
lcd.drawBitmap(ImgVTail, 252, 100)
|
||||
drawMark(315, 110, "A")
|
||||
drawMark(382, 120, "B")
|
||||
lcd.drawFilledRectangle(40, 122, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 124, "A")
|
||||
lcd.drawFilledRectangle(40, 162, 100, 30, CUSTOM_COLOR)
|
||||
drawMark(152, 164, "B")
|
||||
setFieldsVisible(1, 1, 0)
|
||||
end
|
||||
lcd.drawText(40, 20, "Pick the tail config of your model", TEXT_COLOR)
|
||||
lcd.drawFilledRectangle(40, 45, 400, 30, CUSTOM_COLOR)
|
||||
local result = runFieldsPage(event)
|
||||
return result
|
||||
end
|
||||
|
||||
local lineIndex
|
||||
local function drawNextLine(text, text2)
|
||||
lcd.drawText(40, lineIndex, text, TEXT_COLOR)
|
||||
lcd.drawText(250, lineIndex, text2 + 1, TEXT_COLOR)
|
||||
lineIndex = lineIndex + 20
|
||||
end
|
||||
|
||||
local ConfigSummaryFields = {
|
||||
{110, 250, COMBO, 1, 0, { "No, I need to change something", "Yes, all is well, create the plane !"} },
|
||||
}
|
||||
|
||||
local ImgSummary
|
||||
|
||||
local function runConfigSummary(event)
|
||||
lcd.clear()
|
||||
if ImgSummary == nil then
|
||||
ImgSummary = Bitmap.open("img/summary.png")
|
||||
end
|
||||
fields = ConfigSummaryFields
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgPageUp, 0, 95)
|
||||
lcd.drawBitmap(ImgSummary, 300, 60)
|
||||
lineIndex = 40
|
||||
-- motors
|
||||
if(MotorFields[1][5] == 1) then
|
||||
drawNextLine("Motor chan :", MotorFields[2][5])
|
||||
elseif (MotorFields[1][5] == 2) then
|
||||
drawNextLine("Motor 1 chan :", MotorFields[2][5])
|
||||
drawNextLine("Motor 2 chan :", MotorFields[3][5])
|
||||
end
|
||||
-- ail
|
||||
if(AilFields[1][5] == 1) then
|
||||
drawNextLine("Aileron chan :",AilFields[2][5])
|
||||
elseif (AilFields[1][5] == 2) then
|
||||
drawNextLine("Aileron 1 chan :",AilFields[2][5])
|
||||
drawNextLine("Aileron 2 chan :",AilFields[3][5])
|
||||
end
|
||||
-- flaps
|
||||
if(FlapsFields[1][5] == 1) then
|
||||
drawNextLine("Flaps chan :",FlapsFields[2][5])
|
||||
elseif (FlapsFields[1][5] == 2) then
|
||||
drawNextLine("Flaps 1 chan :",FlapsFields[2][5])
|
||||
drawNextLine("Flaps 2 chan :",FlapsFields[3][5])
|
||||
end
|
||||
-- tail
|
||||
if(TailFields[1][5] == 0) then
|
||||
drawNextLine("Elevator chan :",TailFields[2][5])
|
||||
elseif (TailFields[1][5] == 1) then
|
||||
drawNextLine("Elevator chan :",TailFields[2][5])
|
||||
drawNextLine("Rudder chan :",TailFields[3][5])
|
||||
elseif (TailFields[1][5] == 2) then
|
||||
drawNextLine("Elevator 1 chan :",TailFields[2][5])
|
||||
drawNextLine("Rudder chan :",TailFields[3][5])
|
||||
drawNextLine("Elevator 2 chan :",TailFields[4][5])
|
||||
elseif (TailFields[1][5] == 3) then
|
||||
drawNextLine("V-Tail elevator :", TailFields[2][5])
|
||||
drawNextLine("V-Tail rudder :", TailFields[3][5])
|
||||
end
|
||||
local result = runFieldsPage(event)
|
||||
if(fields[1][5] == 1 and edit == false) then
|
||||
selectPage(1)
|
||||
end
|
||||
return result
|
||||
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 createModel(event)
|
||||
lcd.clear()
|
||||
lcd.drawBitmap(BackgroundImg, 0, 0)
|
||||
lcd.drawBitmap(ImgSummary, 300, 60)
|
||||
model.defaultInputs()
|
||||
model.deleteMixes()
|
||||
-- motor
|
||||
if(MotorFields[1][5] == 1) then
|
||||
addMix(MotorFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(2), "Motor")
|
||||
elseif (MotorFields[1][5] == 2) then
|
||||
addMix(MotorFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(2), "Motor1")
|
||||
addMix(MotorFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(2), "Motor2")
|
||||
end
|
||||
-- Ailerons
|
||||
if(AilFields[1][5] == 1) then
|
||||
addMix(AilFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(3), "Ail")
|
||||
elseif (AilFields[1][5] == 2) then
|
||||
addMix(AilFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(3), "AilL")
|
||||
addMix(AilFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(3), "AilR", -100)
|
||||
end
|
||||
-- Flaps
|
||||
if(FlapsFields[1][5] == 1) then
|
||||
addMix(FlapsFields[2][5], MIXSRC_SA, "Flaps")
|
||||
elseif (FlapsFields[1][5] == 2) then
|
||||
addMix(FlapsFields[2][5], MIXSRC_SA, "FlapsL")
|
||||
addMix(FlapsFields[3][5], MIXSRC_SA, "FlapsR")
|
||||
end
|
||||
-- Tail
|
||||
if(TailFields[1][5] == 0) then
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "Elev")
|
||||
elseif (TailFields[1][5] == 1) then
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "Elev")
|
||||
addMix(TailFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(0), "Rudder")
|
||||
elseif (TailFields[1][5] == 2) then
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "ElevL")
|
||||
addMix(TailFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(0), "Rudder")
|
||||
addMix(TailFields[4][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "ElevR")
|
||||
elseif (TailFields[1][5] == 3) then
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "V-EleL", 50)
|
||||
addMix(TailFields[2][5], MIXSRC_FIRST_INPUT+defaultChannel(0), "V-RudL", 50, 1)
|
||||
addMix(TailFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(1), "V-EleR", 50)
|
||||
addMix(TailFields[3][5], MIXSRC_FIRST_INPUT+defaultChannel(0), "V-RudR", -50, 1)
|
||||
end
|
||||
lcd.drawText(70, 90, "Model successfully created !", TEXT_COLOR)
|
||||
lcd.drawText(100, 130, "Press RTN to exit", TEXT_COLOR)
|
||||
return 2
|
||||
end
|
||||
|
||||
-- Init
|
||||
local function init()
|
||||
current, edit = 1, false
|
||||
pages = {
|
||||
runMotorConfig,
|
||||
runAilConfig,
|
||||
runFlapsConfig,
|
||||
runTailConfig,
|
||||
runConfigSummary,
|
||||
createModel,
|
||||
}
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function run(event)
|
||||
if event == nil then
|
||||
error("Cannot be run as a model script!")
|
||||
return 2
|
||||
elseif (event == EVT_PAGE_BREAK or event == EVT_PAGEDN_FIRST) and page < #pages-1 then
|
||||
selectPage(1)
|
||||
elseif (event == EVT_PAGE_LONG or event == EVT_PAGEUP_FIRST) and page > 1 then
|
||||
killEvents(event);
|
||||
selectPage(-1)
|
||||
end
|
||||
|
||||
local result = pages[page](event)
|
||||
return result
|
||||
end
|
||||
|
||||
return { init=init, run=run }
|
||||
@@ -0,0 +1,318 @@
|
||||
---- #########################################################################
|
||||
---- # #
|
||||
---- # Copyright (C) OpenTX #
|
||||
-----# #
|
||||
---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
|
||||
---- # #
|
||||
---- # This program is free software; you can redistribute it and/or modify #
|
||||
---- # it under the terms of the GNU General Public License version 2 as #
|
||||
---- # published by the Free Software Foundation. #
|
||||
---- # #
|
||||
---- # This program is distributed in the hope that it will be useful #
|
||||
---- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
---- # GNU General Public License for more details. #
|
||||
---- # #
|
||||
---- #########################################################################
|
||||
local VALUE = 0
|
||||
local COMBO = 1
|
||||
|
||||
local COLUMN_2 = 300
|
||||
|
||||
local edit = false
|
||||
local page = 1
|
||||
local current = 1
|
||||
local refreshState = 0
|
||||
local refreshIndex = 0
|
||||
local calibrationState = 0
|
||||
local pageOffset = 0
|
||||
local calibrationStep = 0
|
||||
local pages = {}
|
||||
local fields = {}
|
||||
local modifications = {}
|
||||
local wingBitmaps = {}
|
||||
local mountBitmaps = {}
|
||||
|
||||
local configFields = {
|
||||
{"Wing type:", COMBO, 0x80, nil, { "Normal", "Delta", "VTail" } },
|
||||
{"Mounting type:", COMBO, 0x81, nil, { "Horz", "Horz rev.", "Vert", "Vert rev." } },
|
||||
}
|
||||
local wingBitmapsFile = {"img/plane_b.png", "img/delta_b.png", "img/planev_b.png"}
|
||||
local mountBitmapsFile = {"img/up.png", "img/down.png", "img/vert.png", "img/vert-r.png"}
|
||||
|
||||
local settingsFields = {
|
||||
{"SxR functions:", COMBO, 0x9C, nil, { "Disable", "Enable" } },
|
||||
{"Quick Mode:", COMBO, 0xAA, nil, { "Disable", "Enable" } },
|
||||
{"CH5 mode:", COMBO, 0xA8, nil, { "AIL2", "AUX1" } },
|
||||
{"CH6 mode:", COMBO, 0xA9, nil, { "ELE2", "AUX2" } },
|
||||
{"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 } },
|
||||
{"AIL2 direction:", COMBO, 0x9A, nil, { "Normal", "Invers" }, { 255, 0 } },
|
||||
{"ELE2 direction:", COMBO, 0x9B, nil, { "Normal", "Invers" }, { 255, 0 } },
|
||||
{"AIL stabilize gain:", VALUE, 0x85, nil, 0, 200, "%"},
|
||||
{"ELE stabilize gain:", VALUE, 0x86, nil, 0, 200, "%"},
|
||||
{"RUD stabilize gain:", VALUE, 0x87, nil, 0, 200, "%"},
|
||||
{"AIL auto level gain:", VALUE, 0x88, nil, 0, 200, "%"},
|
||||
{"ELE auto level gain:", VALUE, 0x89, nil, 0, 200, "%"},
|
||||
{"ELE upright gain:", VALUE, 0x8C, nil, 0, 200, "%"},
|
||||
{"RUD upright gain:", VALUE, 0x8D, nil, 0, 200, "%"},
|
||||
{"AIL crab gain:", VALUE, 0x8E, nil, 0, 200, "%"},
|
||||
{"RUD crab gain:", VALUE, 0x90, nil, 0, 200, "%"},
|
||||
{"AIL auto angle offset:", VALUE, 0x91, nil, -20, 20, "%", 0x6C},
|
||||
{"ELE auto angle offset:", VALUE, 0x92, nil, -20, 20, "%", 0x6C},
|
||||
{"ELE upright angle offset:", VALUE, 0x95, nil, -20, 20, "%", 0x6C},
|
||||
{"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},
|
||||
}
|
||||
|
||||
local calibrationFields = {
|
||||
{"X:", VALUE, 0x9E, 0, -100, 100, "%"},
|
||||
{"Y:", VALUE, 0x9F, 0, -100, 100, "%"},
|
||||
{"Z:", VALUE, 0xA0, 0, -100, 100, "%"}
|
||||
}
|
||||
|
||||
local function drawScreenTitle(title,page, pages)
|
||||
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
|
||||
lcd.drawText(1, 5, title, MENU_TITLE_COLOR)
|
||||
lcd.drawText(LCD_W-40, 5, page.."/"..pages, MENU_TITLE_COLOR)
|
||||
end
|
||||
|
||||
-- Change display attribute to current field
|
||||
local function addField(step)
|
||||
local field = fields[current]
|
||||
local min, max
|
||||
if field[2] == VALUE then
|
||||
min = field[5]
|
||||
max = field[6]
|
||||
elseif field[2] == COMBO then
|
||||
min = 0
|
||||
max = #(field[5]) - 1
|
||||
end
|
||||
if (step < 0 and field[4] > min) or (step > 0 and field[4] < max) then
|
||||
field[4] = field[4] + step
|
||||
end
|
||||
end
|
||||
|
||||
-- Select the next or previous page
|
||||
local function selectPage(step)
|
||||
page = 1 + ((page + step - 1 + #pages) % #pages)
|
||||
refreshIndex = 0
|
||||
calibrationStep = 0
|
||||
pageOffset = 0
|
||||
end
|
||||
|
||||
-- Select the next or previous editable field
|
||||
local function selectField(step)
|
||||
current = 1 + ((current + step - 1 + #fields) % #fields)
|
||||
if current > 7 + pageOffset then
|
||||
pageOffset = current - 7
|
||||
elseif current <= pageOffset then
|
||||
pageOffset = current - 1
|
||||
end
|
||||
end
|
||||
|
||||
local function drawProgressBar()
|
||||
local width = (300 * refreshIndex) / #fields
|
||||
lcd.drawRectangle(100, 10, 300, 6)
|
||||
lcd.drawFilledRectangle(102, 13, width, 2);
|
||||
end
|
||||
|
||||
-- Redraw the current page
|
||||
local function redrawFieldsPage(event)
|
||||
lcd.clear()
|
||||
drawScreenTitle("SxR", page, #pages)
|
||||
|
||||
if refreshIndex < #fields then
|
||||
drawProgressBar()
|
||||
end
|
||||
|
||||
for index = 1, 10, 1 do
|
||||
local field = fields[pageOffset+index]
|
||||
if field == nil then
|
||||
break
|
||||
end
|
||||
|
||||
local attr = current == (pageOffset+index) and ((edit == true and BLINK or 0) + INVERS) or 0
|
||||
attr = attr + TEXT_COLOR
|
||||
|
||||
lcd.drawText(1, 30+20*index, field[1], TEXT_COLOR)
|
||||
|
||||
if field[4] == nil then
|
||||
lcd.drawText(COLUMN_2, 30+20*index, "---", attr)
|
||||
else
|
||||
if field[2] == VALUE then
|
||||
lcd.drawNumber(COLUMN_2, 30+20*index, field[4], LEFT + attr)
|
||||
elseif field[2] == COMBO then
|
||||
if field[4] >= 0 and field[4] < #(field[5]) then
|
||||
lcd.drawText(COLUMN_2, 30+20*index, field[5][1+field[4]], attr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function telemetryRead(field)
|
||||
return sportTelemetryPush(0x17, 0x30, 0x0C30, field)
|
||||
end
|
||||
|
||||
local function telemetryWrite(field, value)
|
||||
return sportTelemetryPush(0x17, 0x31, 0x0C30, field + value*256)
|
||||
end
|
||||
|
||||
local telemetryPopTimeout = 0
|
||||
local function refreshNext()
|
||||
if refreshState == 0 then
|
||||
if calibrationState == 1 then
|
||||
if telemetryWrite(0x9D, calibrationStep) == true then
|
||||
refreshState = 1
|
||||
calibrationState = 2
|
||||
telemetryPopTimeout = getTime() + 120 -- normal delay is 500ms
|
||||
end
|
||||
elseif #modifications > 0 then
|
||||
telemetryWrite(modifications[1][1], modifications[1][2])
|
||||
modifications[1] = nil
|
||||
elseif refreshIndex < #fields then
|
||||
local field = fields[refreshIndex + 1]
|
||||
if telemetryRead(field[3]) == true then
|
||||
refreshState = 1
|
||||
telemetryPopTimeout = getTime() + 80 -- normal delay is 500ms
|
||||
end
|
||||
end
|
||||
elseif refreshState == 1 then
|
||||
local physicalId, primId, dataId, value = sportTelemetryPop()
|
||||
if physicalId == 0x1A and primId == 0x32 and dataId == 0x0C30 then
|
||||
local fieldId = value % 256
|
||||
if calibrationState == 2 then
|
||||
if fieldId == 0x9D then
|
||||
refreshState = 0
|
||||
calibrationState = 0
|
||||
calibrationStep = (calibrationStep + 1) % 7
|
||||
end
|
||||
else
|
||||
local field = fields[refreshIndex + 1]
|
||||
if fieldId == field[3] then
|
||||
local value = math.floor(value / 256)
|
||||
if field[3] == 0xAA then
|
||||
value = bit32.band(value, 0x0001)
|
||||
end
|
||||
if field[3] >= 0x9E and field[3] <= 0xA0 then
|
||||
local b1 = value % 256
|
||||
local b2 = math.floor(value / 256)
|
||||
value = b1*256 + b2
|
||||
value = value - bit32.band(value, 0x8000) * 2
|
||||
end
|
||||
if field[2] == COMBO and #field == 6 then
|
||||
for index = 1, #(field[6]), 1 do
|
||||
if value == field[6][index] then
|
||||
value = index - 1
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif field[2] == VALUE and #field == 8 then
|
||||
value = value - field[8] + field[5]
|
||||
end
|
||||
fields[refreshIndex + 1][4] = value
|
||||
refreshIndex = refreshIndex + 1
|
||||
refreshState = 0
|
||||
end
|
||||
end
|
||||
elseif getTime() > telemetryPopTimeout then
|
||||
fields[refreshIndex + 1][4] = nil
|
||||
refreshIndex = refreshIndex + 1
|
||||
refreshState = 0
|
||||
calibrationState = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function updateField(field)
|
||||
local value = field[4]
|
||||
if field[2] == COMBO and #field == 6 then
|
||||
value = field[6][1+value]
|
||||
elseif field[2] == VALUE and #field == 8 then
|
||||
value = value + field[8] - field[5]
|
||||
end
|
||||
modifications[#modifications+1] = { field[3], value }
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function runFieldsPage(event)
|
||||
if event == EVT_EXIT_BREAK then -- exit script
|
||||
return 2
|
||||
elseif event == EVT_ENTER_BREAK or event == EVT_ROT_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_ROT_RIGHT or event == EVT_PLUS_REPT then
|
||||
addField(1)
|
||||
elseif event == EVT_MINUS_FIRST or event == EVT_ROT_LEFT or event == EVT_MINUS_REPT then
|
||||
addField(-1)
|
||||
end
|
||||
else
|
||||
if event == EVT_MINUS_FIRST or event == EVT_ROT_RIGHT then
|
||||
selectField(1)
|
||||
elseif event == EVT_PLUS_FIRST or event == EVT_ROT_LEFT then
|
||||
selectField(-1)
|
||||
end
|
||||
end
|
||||
redrawFieldsPage(event)
|
||||
return 0
|
||||
end
|
||||
|
||||
local function runConfigPage(event)
|
||||
fields = configFields
|
||||
local result = runFieldsPage(event)
|
||||
if fields[1][4] ~= nil then
|
||||
if wingBitmaps[1 + fields[1][4]] == nil then
|
||||
wingBitmaps[1 + fields[1][4]] = Bitmap.open(wingBitmapsFile[1 + fields[1][4]])
|
||||
end
|
||||
lcd.drawBitmap(wingBitmaps[1 + fields[1][4]], 10, 90)
|
||||
end
|
||||
if fields[2][4] ~= nil then
|
||||
if mountBitmaps[1 + fields[2][4]] == nil then
|
||||
mountBitmaps[1 + fields[2][4]] = Bitmap.open(mountBitmapsFile[1 + fields[2][4]])
|
||||
end
|
||||
lcd.drawBitmap(mountBitmaps[1 + fields[2][4]], 190, 110)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function runSettingsPage(event)
|
||||
fields = settingsFields
|
||||
return runFieldsPage(event)
|
||||
end
|
||||
|
||||
-- Init
|
||||
local function init()
|
||||
current, edit, refreshState, refreshIndex = 1, false, 0, 0
|
||||
pages = {
|
||||
runConfigPage,
|
||||
runSettingsPage,
|
||||
}
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function run(event)
|
||||
if event == nil then
|
||||
error("Cannot be run as a model script!")
|
||||
return 2
|
||||
elseif event == EVT_PAGE_BREAK or event == EVT_PAGEDN_FIRST then
|
||||
selectPage(1)
|
||||
elseif event == EVT_PAGE_LONG or event == EVT_PAGEUP_FIRST then
|
||||
killEvents(event);
|
||||
selectPage(-1)
|
||||
end
|
||||
|
||||
local result = pages[page](event)
|
||||
refreshNext()
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return { init=init, run=run }
|
||||
@@ -0,0 +1,357 @@
|
||||
---- #########################################################################
|
||||
---- # #
|
||||
---- # Copyright (C) OpenTX #
|
||||
-----# #
|
||||
---- # License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html #
|
||||
---- # #
|
||||
---- # This program is free software; you can redistribute it and/or modify #
|
||||
---- # it under the terms of the GNU General Public License version 2 as #
|
||||
---- # published by the Free Software Foundation. #
|
||||
---- # #
|
||||
---- # This program is distributed in the hope that it will be useful #
|
||||
---- # but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
---- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
---- # GNU General Public License for more details. #
|
||||
---- # #
|
||||
---- #########################################################################
|
||||
local VALUE = 0
|
||||
local COMBO = 1
|
||||
|
||||
local COLUMN_2 = 300
|
||||
|
||||
local edit = false
|
||||
local page = 1
|
||||
local current = 1
|
||||
local refreshState = 0
|
||||
local refreshIndex = 0
|
||||
local calibrationState = 0
|
||||
local pageOffset = 0
|
||||
local calibrationStep = 0
|
||||
local pages = {}
|
||||
local fields = {}
|
||||
local modifications = {}
|
||||
local wingBitmaps = {}
|
||||
local mountBitmaps = {}
|
||||
local calibBitmaps = {}
|
||||
|
||||
local configFields = {
|
||||
{"Wing type:", COMBO, 0x80, nil, { "Normal", "Delta", "VTail" } },
|
||||
{"Mounting type:", COMBO, 0x81, nil, { "Horz", "Horz rev.", "Vert", "Vert rev." } },
|
||||
}
|
||||
local calibrationPositions = { "up", "down", "left", "right", "forward", "back" }
|
||||
local wingBitmapsFile = {"img/plane_b.png", "img/delta_b.png", "img/planev_b.png"}
|
||||
local mountBitmapsFile = {"img/up.png", "img/down.png", "img/vert.png", "img/vert-r.png"}
|
||||
local calibBitmapsFile = {"img/up.png", "img/down.png", "img/left.png", "img/right.png", "img/forward.png", "img/back.png"}
|
||||
|
||||
local settingsFields = {
|
||||
{"SxR functions:", COMBO, 0x9C, nil, { "Disable", "Enable" } },
|
||||
{"CH5 mode:", COMBO, 0xA8, nil, { "AIL2", "AUX1" } },
|
||||
{"CH6 mode:", COMBO, 0xA9, nil, { "ELE2", "AUX2" } },
|
||||
{"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 } },
|
||||
{"AIL2 direction:", COMBO, 0x9A, nil, { "Normal", "Invers" }, { 255, 0 } },
|
||||
{"ELE2 direction:", COMBO, 0x9B, nil, { "Normal", "Invers" }, { 255, 0 } },
|
||||
{"AIL stabilize gain:", VALUE, 0x85, nil, 0, 200, "%"},
|
||||
{"ELE stabilize gain:", VALUE, 0x86, nil, 0, 200, "%"},
|
||||
{"RUD stabilize gain:", VALUE, 0x87, nil, 0, 200, "%"},
|
||||
{"AIL auto level gain:", VALUE, 0x88, nil, 0, 200, "%"},
|
||||
{"ELE auto level gain:", VALUE, 0x89, nil, 0, 200, "%"},
|
||||
{"ELE upright gain:", VALUE, 0x8C, nil, 0, 200, "%"},
|
||||
{"RUD upright gain:", VALUE, 0x8D, nil, 0, 200, "%"},
|
||||
{"AIL crab gain:", VALUE, 0x8E, nil, 0, 200, "%"},
|
||||
{"RUD crab gain:", VALUE, 0x90, nil, 0, 200, "%"},
|
||||
{"AIL auto angle offset:", VALUE, 0x91, nil, -20, 20, "%", 0x6C},
|
||||
{"ELE auto angle offset:", VALUE, 0x92, nil, -20, 20, "%", 0x6C},
|
||||
{"ELE upright angle offset:", VALUE, 0x95, nil, -20, 20, "%", 0x6C},
|
||||
{"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},
|
||||
}
|
||||
|
||||
local calibrationFields = {
|
||||
{"X:", VALUE, 0x9E, 0, -100, 100, "%"},
|
||||
{"Y:", VALUE, 0x9F, 0, -100, 100, "%"},
|
||||
{"Z:", VALUE, 0xA0, 0, -100, 100, "%"}
|
||||
}
|
||||
|
||||
local function drawScreenTitle(title,page, pages)
|
||||
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
|
||||
lcd.drawText(1, 5, title, MENU_TITLE_COLOR)
|
||||
lcd.drawText(LCD_W-40, 5, page.."/"..pages, MENU_TITLE_COLOR)
|
||||
end
|
||||
|
||||
-- Change display attribute to current field
|
||||
local function addField(step)
|
||||
local field = fields[current]
|
||||
local min, max
|
||||
if field[2] == VALUE then
|
||||
min = field[5]
|
||||
max = field[6]
|
||||
elseif field[2] == COMBO then
|
||||
min = 0
|
||||
max = #(field[5]) - 1
|
||||
end
|
||||
if (step < 0 and field[4] > min) or (step > 0 and field[4] < max) then
|
||||
field[4] = field[4] + step
|
||||
end
|
||||
end
|
||||
|
||||
-- Select the next or previous page
|
||||
local function selectPage(step)
|
||||
page = 1 + ((page + step - 1 + #pages) % #pages)
|
||||
refreshIndex = 0
|
||||
calibrationStep = 0
|
||||
pageOffset = 0
|
||||
end
|
||||
|
||||
-- Select the next or previous editable field
|
||||
local function selectField(step)
|
||||
current = 1 + ((current + step - 1 + #fields) % #fields)
|
||||
if current > 7 + pageOffset then
|
||||
pageOffset = current - 7
|
||||
elseif current <= pageOffset then
|
||||
pageOffset = current - 1
|
||||
end
|
||||
end
|
||||
|
||||
local function drawProgressBar()
|
||||
local width = (300 * refreshIndex) / #fields
|
||||
lcd.drawRectangle(100, 10, 300, 6)
|
||||
lcd.drawFilledRectangle(102, 13, width, 2);
|
||||
end
|
||||
|
||||
-- Redraw the current page
|
||||
local function redrawFieldsPage(event)
|
||||
lcd.clear()
|
||||
drawScreenTitle("SxR", page, #pages)
|
||||
|
||||
if refreshIndex < #fields then
|
||||
drawProgressBar()
|
||||
end
|
||||
|
||||
for index = 1, 10, 1 do
|
||||
local field = fields[pageOffset+index]
|
||||
if field == nil then
|
||||
break
|
||||
end
|
||||
|
||||
local attr = current == (pageOffset+index) and ((edit == true and BLINK or 0) + INVERS) or 0
|
||||
attr = attr + TEXT_COLOR
|
||||
|
||||
lcd.drawText(1, 30+20*index, field[1], TEXT_COLOR)
|
||||
|
||||
if field[4] == nil then
|
||||
lcd.drawText(COLUMN_2, 30+20*index, "---", attr)
|
||||
else
|
||||
if field[2] == VALUE then
|
||||
lcd.drawNumber(COLUMN_2, 30+20*index, field[4], LEFT + attr)
|
||||
elseif field[2] == COMBO then
|
||||
if field[4] >= 0 and field[4] < #(field[5]) then
|
||||
lcd.drawText(COLUMN_2, 30+20*index, field[5][1+field[4]], attr)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function telemetryRead(field)
|
||||
return sportTelemetryPush(0x17, 0x30, 0x0C30, field)
|
||||
end
|
||||
|
||||
local function telemetryWrite(field, value)
|
||||
return sportTelemetryPush(0x17, 0x31, 0x0C30, field + value*256)
|
||||
end
|
||||
|
||||
local telemetryPopTimeout = 0
|
||||
local function refreshNext()
|
||||
if refreshState == 0 then
|
||||
if calibrationState == 1 then
|
||||
if telemetryWrite(0x9D, calibrationStep) == true then
|
||||
refreshState = 1
|
||||
calibrationState = 2
|
||||
telemetryPopTimeout = getTime() + 80 -- normal delay is 500ms
|
||||
end
|
||||
elseif #modifications > 0 then
|
||||
telemetryWrite(modifications[1][1], modifications[1][2])
|
||||
modifications[1] = nil
|
||||
elseif refreshIndex < #fields then
|
||||
local field = fields[refreshIndex + 1]
|
||||
if telemetryRead(field[3]) == true then
|
||||
refreshState = 1
|
||||
telemetryPopTimeout = getTime() + 80 -- normal delay is 500ms
|
||||
end
|
||||
end
|
||||
elseif refreshState == 1 then
|
||||
local physicalId, primId, dataId, value = sportTelemetryPop()
|
||||
if physicalId == 0x1A and primId == 0x32 and dataId == 0x0C30 then
|
||||
local fieldId = value % 256
|
||||
if calibrationState == 2 then
|
||||
if fieldId == 0x9D then
|
||||
refreshState = 0
|
||||
calibrationState = 0
|
||||
calibrationStep = (calibrationStep + 1) % 7
|
||||
end
|
||||
else
|
||||
local field = fields[refreshIndex + 1]
|
||||
if fieldId == field[3] then
|
||||
local value = math.floor(value / 256)
|
||||
value = bit32.band(value, 0xffff)
|
||||
if field[3] >= 0x9E and field[3] <= 0xA0 then
|
||||
local b1 = value % 256
|
||||
local b2 = math.floor(value / 256)
|
||||
value = b1*256 + b2
|
||||
value = value - bit32.band(value, 0x8000) * 2
|
||||
end
|
||||
if field[2] == COMBO and #field == 6 then
|
||||
for index = 1, #(field[6]), 1 do
|
||||
if value == field[6][index] then
|
||||
value = index - 1
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif field[2] == VALUE and #field == 8 then
|
||||
value = value - field[8] + field[5]
|
||||
end
|
||||
fields[refreshIndex + 1][4] = value
|
||||
refreshIndex = refreshIndex + 1
|
||||
refreshState = 0
|
||||
end
|
||||
end
|
||||
elseif getTime() > telemetryPopTimeout then
|
||||
refreshState = 0
|
||||
calibrationState = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function updateField(field)
|
||||
local value = field[4]
|
||||
if field[2] == COMBO and #field == 6 then
|
||||
value = field[6][1+value]
|
||||
elseif field[2] == VALUE and #field == 8 then
|
||||
value = value + field[8] - field[5]
|
||||
end
|
||||
modifications[#modifications+1] = { field[3], value }
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function runFieldsPage(event)
|
||||
if event == EVT_EXIT_BREAK then -- exit script
|
||||
return 2
|
||||
elseif event == EVT_ENTER_BREAK or event == EVT_ROT_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_ROT_RIGHT or event == EVT_PLUS_REPT then
|
||||
addField(1)
|
||||
elseif event == EVT_MINUS_FIRST or event == EVT_ROT_LEFT or event == EVT_MINUS_REPT then
|
||||
addField(-1)
|
||||
end
|
||||
else
|
||||
if event == EVT_MINUS_FIRST or event == EVT_ROT_RIGHT then
|
||||
selectField(1)
|
||||
elseif event == EVT_PLUS_FIRST or event == EVT_ROT_LEFT then
|
||||
selectField(-1)
|
||||
end
|
||||
end
|
||||
redrawFieldsPage(event)
|
||||
return 0
|
||||
end
|
||||
|
||||
local function runConfigPage(event)
|
||||
fields = configFields
|
||||
local result = runFieldsPage(event)
|
||||
if fields[1][4] ~= nil then
|
||||
if wingBitmaps[1 + fields[1][4]] == nil then
|
||||
wingBitmaps[1 + fields[1][4]] = Bitmap.open(wingBitmapsFile[1 + fields[1][4]])
|
||||
end
|
||||
lcd.drawBitmap(wingBitmaps[1 + fields[1][4]], 10, 90)
|
||||
end
|
||||
if fields[2][4] ~= nil then
|
||||
if mountBitmaps[1 + fields[2][4]] == nil then
|
||||
mountBitmaps[1 + fields[2][4]] = Bitmap.open(mountBitmapsFile[1 + fields[2][4]])
|
||||
end
|
||||
lcd.drawBitmap(mountBitmaps[1 + fields[2][4]], 190, 110)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
local function runSettingsPage(event)
|
||||
fields = settingsFields
|
||||
return runFieldsPage(event)
|
||||
end
|
||||
|
||||
local function runCalibrationPage(event)
|
||||
fields = calibrationFields
|
||||
if refreshIndex == #fields then
|
||||
refreshIndex = 0
|
||||
end
|
||||
lcd.clear()
|
||||
drawScreenTitle("SxR", page, #pages)
|
||||
if(calibrationStep < 6) then
|
||||
local position = calibrationPositions[1 + calibrationStep]
|
||||
lcd.drawText(100, 50, "Place the SxR in the following position", TEXT_COLOR)
|
||||
if calibBitmaps[calibrationStep + 1] == nil then
|
||||
calibBitmaps[calibrationStep + 1] = Bitmap.open(calibBitmapsFile[calibrationStep + 1])
|
||||
end
|
||||
lcd.drawBitmap(calibBitmaps[calibrationStep + 1], 200, 70)
|
||||
for index = 1, 3, 1 do
|
||||
local field = fields[index]
|
||||
lcd.drawText(70, 80+20*index, field[1]..":", TEXT_COLOR)
|
||||
lcd.drawNumber(90, 80+20*index, field[4]/10, LEFT+PREC2)
|
||||
end
|
||||
|
||||
local attr = calibrationState == 0 and INVERS or 0
|
||||
lcd.drawText(160, 220, "Press [Enter] when ready", attr)
|
||||
else
|
||||
lcd.drawText(160, 50, "Calibration completed", 0)
|
||||
lcd.drawBitmap(Bitmap.open("img/done.bmp"),200, 100)
|
||||
lcd.drawText(160, 220, "Press [RTN] when ready", attr)
|
||||
end
|
||||
if calibrationStep > 6 and (event == EVT_ENTER_BREAK or event == EVT_EXIT_BREAK) then
|
||||
return 2
|
||||
elseif event == EVT_ENTER_BREAK then
|
||||
calibrationState = 1
|
||||
elseif event == EVT_EXIT_BREAK then
|
||||
if calibrationStep > 0 then
|
||||
calibrationStep = 0
|
||||
end
|
||||
end
|
||||
return 0
|
||||
|
||||
end
|
||||
|
||||
-- Init
|
||||
local function init()
|
||||
current, edit, refreshState, refreshIndex = 1, false, 0, 0
|
||||
pages = {
|
||||
-- runConfigPage,
|
||||
-- runSettingsPage,
|
||||
runCalibrationPage
|
||||
}
|
||||
end
|
||||
|
||||
-- Main
|
||||
local function run(event)
|
||||
if event == nil then
|
||||
error("Cannot be run as a model script!")
|
||||
return 2
|
||||
elseif event == EVT_PAGE_BREAK or event == EVT_PAGEDN_FIRST then
|
||||
selectPage(1)
|
||||
elseif event == EVT_PAGE_LONG or event == EVT_PAGEUP_FIRST then
|
||||
killEvents(event);
|
||||
selectPage(-1)
|
||||
end
|
||||
|
||||
local result = pages[page](event)
|
||||
refreshNext()
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return { init=init, run=run }
|
||||
|
After Width: | Height: | Size: 9.0 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 7.7 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 161 KiB |
|
After Width: | Height: | Size: 335 B |
|
After Width: | Height: | Size: 293 B |
|
After Width: | Height: | Size: 491 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 873 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 978 B |
|
After Width: | Height: | Size: 674 B |
|
After Width: | Height: | Size: 814 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 807 B |
|
After Width: | Height: | Size: 671 B |
|
After Width: | Height: | Size: 796 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 980 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 604 B |
|
After Width: | Height: | Size: 811 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 698 B |
|
After Width: | Height: | Size: 543 B |
|
After Width: | Height: | Size: 530 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 954 B |
|
After Width: | Height: | Size: 1013 B |
|
After Width: | Height: | Size: 841 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 575 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 686 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.2 KiB |