1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-13 11:29:51 +03:00

Multi module config support (#8438)

* Multi module configuration

Co-authored-by: Pascal Langer <pascal_langer@yahoo.fr>
This commit is contained in:
3djc 2021-05-05 15:46:29 +02:00 committed by GitHub
parent b202f85786
commit c06b789f5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 3864 additions and 33 deletions

View file

@ -6,7 +6,7 @@ set(VERSION_REVISION "12")
set(VERSION_SUFFIX $ENV{OPENTX_VERSION_SUFFIX})
set(VERSION_FAMILY ${VERSION_MAJOR}.${VERSION_MINOR})
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}${VERSION_SUFFIX})
set(SDCARD_REVISION "0036")
set(SDCARD_REVISION "0037")
set(SDCARD_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}V${SDCARD_REVISION})
cmake_minimum_required(VERSION 2.8)

View file

@ -6,6 +6,7 @@
14,4,Bayang,DHD_D4,1,Flip,RTH,Pict,Video,HLess,Invert,Rates,TakeOf,EmStop
14,5,Bayang,QX100,1,Flip,RTH,Pict,Video,HLess,Invert,Rates,TakeOf,EmStop
59,0,BayangRX,RX,1,AnAux1,AnAux2,Flip,RTH,Pict,Video
59,1,BayangRX,CPPM,1,AnAux1,AnAux2,Flip,RTH,Pict,Video
41,0,Bugs,3-6-8,0,Arm,Angle,Flip,Pict,Video,LED
42,0,BugsMini,Mini,0,Arm,Angle,Flip,Pict,Video,LED
42,1,BugsMini,3H,0,Arm,Angle,Flip,Pict,Video,LED,AltHol
@ -34,9 +35,9 @@
6,3,DSM,X_11,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,n-a,ThKill
6,4,DSM,AUTO,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,n-a,ThKill
70,0,DSM_RX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
70,1,DSM_RX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
45,0,E01X,E012,1,n-a,Flip,n-a,HLess,RTH
45,1,E01X,E015,1,Arm,Flip,LED,HLess,RTH
45,2,E01X,E016H,1,Stop,Flip,n-a,HLess,RTH
16,0,ESKY,Std,0,Gyro,Pitch
16,1,ESKY,ET4,0,Gyro,Pitch
35,0,ESKY150,4CH,0
@ -54,6 +55,7 @@
28,4,Flysky_AFHDS2A,PWM_IB16,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
28,5,Flysky_AFHDS2A,PPM_IB16,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
56,0,Flysky2A_RX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14
56,1,Flysky2A_RX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14
53,0,Height,5ch,0,Gear
53,1,Height,8ch,0,Gear,Gyro,Flap,Light
25,0,FrSkyV,V8,0,CH5,CH6,CH7,CH8
@ -79,6 +81,8 @@
65,3,FrSkyR9,R9_968_8CH,0,CH5,CH6,CH7,CH8
55,0,FrSkyRX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
55,1,FrSkyRX,CloneTX,0
55,2,FrSkyRX,EraseTX,0
55,3,FrSkyRX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
58,0,FX816,P38,1
20,0,FY326,FY326,1,Flip,RTH,HLess,Expert,Calib
20,1,FY326,FY319,1,Flip,RTH,HLess,Expert,Calib
@ -99,13 +103,14 @@
26,1,Hontai,JJRCX1,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
26,2,Hontai,X5C1,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
26,3,Hontai,FQ777_951,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
57,0,HoTT,Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
57,1,HoTT,No_Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
57,0,HoTT,Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
57,1,HoTT,No_Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
2,0,Hubsan,H107,1,Flip,Light,Pict,Video,HLess
2,1,Hubsan,H301,0,RTH,Light,Stab,Video
2,2,Hubsan,H501,0,RTH,Light,Pict,Video,HLess,GPS_H,ALT_H,Flip,FModes
22,0,J6Pro,Std,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
71,0,JJRC345,Std,1,Flip,HLess,RTH
71,0,JJRC345,JJRC345,1,Flip,HLess,RTH,LED,UNK1,UNK2,UNK3
71,1,JJRC345,SkyTmblr,1,Flip,HLess,RTH,LED,UNK1,UNK2,UNK3
49,0,KF606,Std,1,Trim
9,0,KN,WLToys,0,DRate,THold,IdleUp,Gyro,Ttrim,Atrim,Etrim
9,1,KN,Feilun,0,DRate,THold,IdleUp,Gyro,Ttrim,Atrim,Etrim
@ -122,6 +127,8 @@
17,2,MT99XX,YZ,1,Flip,LED,Pict,Video,HLess
17,3,MT99XX,LS,1,Flip,Invert,Pict,Video,HLess
17,4,MT99XX,FY805,1,Flip,n-a,n-a,n-a,HLess
17,5,MT99XX,A180,0,3D_6G
17,6,MT99XX,Dragon,0,Mode,RTH
44,0,NCC1701,Std,1,Warp
77,0,OMP,M2,0,THold,IdleUp,6G_3D
60,0,Pelikan,PRO_V4,0,CH5,CH6,CH7,CH8
@ -138,10 +145,11 @@
72,0,Q90C,Std,0,FMode,VTX+
74,0,RadioLink,Surface,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
74,1,RadioLink,Air,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
74,2,RadioLink,DumboRC,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
76,0,Realacc,R11,1,Flip,Light,Calib,HLess,RTH,UNK
50,0,Redpine,Fast,0,sCH5,sCH6,sCH7,sCH8,sCH9,sCH10,sCH11,sCH12,sCH13,sCH14,sCH15,sCH16
50,1,Redpine,Slow,0,sCH5,sCH6,sCH7,sCH8,sCH9,sCH10,sCH11,sCH12,sCH13,sCH14,sCH15,sCH16
21,0,SFHSS,Std,0,CH5,CH6,CH7,CH8
21,0,Futaba,SFHSS,0,CH5,CH6,CH7,CH8
19,0,Shenqi,Cycle,1
68,0,Skyartec,Std,0,CH5,CH6,CH7
11,0,SLT,V1,0,Gear,Pitch
@ -174,3 +182,11 @@
8,3,YD717,XinXun,1,Flip,Light,Pict,Video,HLess
8,4,YD717,NiHui,1,Flip,Light,Pict,Video,HLess
52,0,ZSX,280,1,Light
78,0,M-Link,Std,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
79,0,WFLY2,RF20x,0,CH5,CH6,CH7,CH8,CH9,CH10
80,0,E016Hv2,E016Hv2,1,TakLan,EmStop,Flip,Calib,HLess,RTH
81,0,E010r5,E010r5,1,Flip,LED,CALIB,HLess,RTH,GLIDE
82,0,LOLI,Std,0,CH5,CH6,CH7,CH8,1SwSePpPw,2SwSePw,3SwSe,4SwSe,5SwSeSb,6SwSe,7SwSePw,8SwSe
83,0,E129,E129,1,TakLan,EmStop,TrimA,TrimE,TrimR
84,0,JOYSWAY,Std,0
85,0,E016H,Std,1,Stop,Flip,n-a,HLess,RTH

View file

@ -0,0 +1,221 @@
local toolName = "TNS|Multi LOLI RX config|TNE"
---- #########################################################################
---- # #
---- # 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 loli_nok = false
local channels={ { 768, "PWM", 100, 102, "PPM", 50, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH1
{ 768, "PWM", 100, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH2
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH3
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH4
{ 102, "SBUS", 50, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH5
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH6
{ 768, "PWM", 100, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH7
{ -768, "Servo", 0, -2048, "Switch", -100 } } -- CH8
local sel = 1
local edit = false
local blink = 0
local BLINK_SPEED = 15
local function drawScreenTitle(title)
if LCD_W == 480 then
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, title, MENU_TITLE_COLOR)
else
lcd.drawScreenTitle(title, 0, 0)
end
end
local function LOLI_Draw_LCD(event)
local line = 0
lcd.clear()
--Display settings
local lcd_opt = 0
if LCD_W == 480 then
drawScreenTitle("Multi - LOLI RX configuration tool")
x_pos = 152
x_inc = 90
y_pos = 40
y_inc = 20
else
x_pos = 5
x_inc = 30
y_pos = 1
y_inc = 8
lcd_opt = SMLSIZE
end
--Multi Module detection
if loli_nok then
if LCD_W == 480 then
lcd.drawText(10,50,"The LOLI protocol is not selected...", lcd_opt)
else
--Draw on LCD_W=128
lcd.drawText(2,17,"LOLI protocol not selected...",SMLSIZE)
end
return
end
--Display current config
if LCD_W == 480 then
line = line + 1
lcd.drawText(x_pos, y_pos+y_inc*line -2, "Channel", lcd_opt)
lcd.drawText(x_pos+x_inc, y_pos+y_inc*line -2, "Function", lcd_opt)
lcd.drawRectangle(x_pos-4, y_pos+y_inc*line -4 , 2*x_inc +2, 188)
lcd.drawLine(x_pos-4, y_pos+y_inc*line +18, x_pos-4 +2*x_inc +1, y_pos+y_inc*line +18, SOLID, 0)
lcd.drawLine(x_pos+x_inc -5, y_pos+y_inc*line -4, x_pos+x_inc -5, y_pos+y_inc*line -5 +188, SOLID, 0)
line = line + 1
end
local out
for i = 1, 8 do
out = getValue("ch"..(i+8))
lcd.drawText(x_pos, y_pos+y_inc*line, "CH"..i, lcd_opt)
for j = 1, #channels[i], 3 do
if out > channels[i][j] then
if sel == i then
invert = INVERS
if edit == true then
blink = blink + 1
if blink > BLINK_SPEED then
invert = 0
if blink > BLINK_SPEED * 2 then
blink = 0
end
end
end
else
invert = 0
end
lcd.drawText(x_pos+x_inc, y_pos+y_inc*line, channels[i][j+1], lcd_opt + invert)
break
end
end
line = line + 1
end
end
local function LOLI_Change_Value(dir)
local pos = 0
local out
--look for the current position
out = getValue("ch"..(sel+8))
for j = 1, #channels[sel], 3 do
if out > channels[sel][j] then
pos = j
break
end
end
--decrement or increment
if dir < 0 and pos > 1 then
pos = pos - 3
elseif dir > 0 and pos + 3 < #channels[sel] then
pos = pos + 3
else
return
end
--delete all mixers for the selected channel
local num_mix = model.getMixesCount(sel-1 +8)
for i = 1, num_mix do
model.deleteMix(sel-1 +8, 0);
end
--create new mixer
local source_max = getFieldInfo("cyc1")
local val = { name = channels[sel][pos+1],
source = source_max.id - 1, -- MAX=100 on TX16S
weight = channels[sel][pos+2],
offset = 0,
switch = 0,
multiplex = 0,
curveType = 0,
curveValue = 0,
flightModes = 0,
carryTrim = false,
mixWarn = 0,
delayUp = 0,
delayDown = 0,
speedUp = 0,
speedDown = 0 }
model.insertMix(sel-1 +8, 0, val)
end
local function LOLI_Menu(event)
if event == EVT_VIRTUAL_NEXT then
if edit == false then
-- not changing a value
if sel < 8 then
sel = sel + 1
end
else
-- need to inc the value
LOLI_Change_Value(1)
end
elseif event == EVT_VIRTUAL_PREV then
if edit == false then
-- not changing a value
if sel > 1 then
sel = sel - 1
end
else
-- need to dec the value
LOLI_Change_Value(-1)
end
elseif event == EVT_VIRTUAL_ENTER then
if edit == false then
edit = true
blink = BLINK_SPEED
else
edit = false
end
end
end
-- Init
local function LOLI_Init()
local module_conf = model.getModule(0)
if module_conf["Type"] ~= 6 or module_conf["protocol"] ~= 82 then
module_conf = model.getModule(1)
if module_conf["Type"] ~= 6 or module_conf["protocol"] ~= 82 then
loli_nok = true
end
end
end
-- Main
local function LOLI_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
return 2
else
LOLI_Menu(event)
LOLI_Draw_LCD(event)
return 0
end
end
return { init=LOLI_Init, run=LOLI_Run }

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -0,0 +1,499 @@
---- #########################################################################
---- # #
---- # 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. #
---- # #
---- #########################################################################
--###############################################################################
-- Multi buffer for Config description
-- To start operation:
-- Write 0xFF at address 4 will request the buffer to be cleared
-- Write "Conf" at address 0..3
-- Read
-- Read at address 12 gives the current config page
-- Read at address 13..172 gives the current data of the page = 8 lines * 20 caracters
-- Write
-- Write at address 5..11 the command
-- Write 0x01 at address 4 will send the command to the module
-- !! Before exiting the script must write 0 at address 0 for normal operation !!
--###############################################################################
local Version = "v0.1"
local Focus = -1
local Page = 0
local Edit = -1
local Edit_pos = 1
local Menu = { {text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""} }
local Menu_value = {}
local Blink = 0
local Module = {}
local InitialProtocol = 0
function bitand(a, b)
local result = 0
local bitval = 1
while a > 0 and b > 0 do
if a % 2 == 1 and b % 2 == 1 then -- test the rightmost bits
result = result + bitval -- set the current bit
end
bitval = bitval * 2 -- shift left
a = math.floor(a/2) -- shift right
b = math.floor(b/2)
end
return result
end
local function Config_Send(page, line, value)
local i
i = (page*16) + line
multiBuffer( 5, i )
for i = 1 , 6 , 1 do
multiBuffer( 5+i, value[i] )
end
multiBuffer( 4, 1 )
end
local function Config_Release()
Module.protocol = InitialProtocol
model.setModule(1, Module)
local i
for i = 3 , 0 , -1 do
multiBuffer( i, 0 )
end
end
local function Config_Page( )
Config_Send(Page, 0, { 0, 0, 0, 0, 0, 0 })
end
local function Config_Draw_Edit( event )
local i
local text
if Menu[Focus].field_type == 0xD0 then
-- Editable Hex value
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 1
Blink = 0
for i = 1, Menu[Focus].field_len, 1 do
Menu_value[i] = Menu[Focus].field_value[i]
end
end
if Edit == 0 then
-- Not editing value
if event == EVT_VIRTUAL_ENTER then
if Edit_pos > Menu[Focus].field_len then
-- Save or Cancel
Edit = -1
if Edit_pos == Menu[Focus].field_len + 1 then
-- Save
Config_Send(Page, Focus, Menu_value)
end
return
else
-- Switch to edit mode
Edit = 1
end
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Move cursor
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < Menu[Focus].field_len + 2 then
-- Move cursor
Edit_pos = Edit_pos + 1
end
else
-- Editing value
if event == EVT_VIRTUAL_ENTER then
-- End edit
Edit = 0
elseif event == EVT_VIRTUAL_PREV then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] - 1
elseif event == EVT_VIRTUAL_NEXT then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] + 1
end
--Blink
Blink = Blink + 1
if Blink > 30 then
Blink = 0
end
end
--Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
for i = 1, Menu[Focus].field_len, 1 do
if i==Edit_pos and (Edit ~= 1 or Blink > 15) then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170+12*2*(i-1), 110, string.format('%02X', Menu_value[i]), attrib)
else
lcd.drawText(17+6*2*(i-1), 10, string.format('%02X', Menu_value[i]), attrib + SMLSIZE)
end
end
if Edit_pos == Menu[Focus].field_len + 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Save", attrib)
else
lcd.drawText(17, 30, "Save", attrib + SMLSIZE)
end
if Edit_pos == Menu[Focus].field_len + 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "Cancel", attrib)
else
lcd.drawText(77, 30, "Cancel", attrib + SMLSIZE)
end
elseif Menu[Focus].field_type == 0x90 then
-- Action text
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 2
end
if event == EVT_VIRTUAL_ENTER then
-- Exit
Edit = -1
if Edit_pos == 1 then
-- Yes
Config_Send(Page, Focus, { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA } )
end
return
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Switch to Yes
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < 2 then
-- Switch to No
Edit_pos = Edit_pos + 1
end
-- Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
if LCD_W == 480 then
lcd.drawText(170, 110, Menu[Focus].field_text .. "?")
else
lcd.drawText(17, 10, Menu[Focus].field_text .. "?", SMLSIZE)
end
if Edit_pos == 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Yes", attrib)
else
lcd.drawText(17, 30, "Yes", attrib + SMLSIZE)
end
if Edit_pos == 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "No", attrib)
else
lcd.drawText(77, 30, "No", attrib)
end
end
end
local function Config_Next_Prev( event )
-- Next Prev on main menu
local line
if event == EVT_VIRTUAL_PREV then
for line = Focus - 1, 1, -1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
elseif event == EVT_VIRTUAL_NEXT then
for line = Focus + 1, 7, 1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
end
end
local function Config_Draw_Menu()
-- Main menu
local i
local value
local line
local length
local text
lcd.clear()
if LCD_W == 480 then
--Draw title
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, "Multi Config " .. Version, MENU_TITLE_COLOR)
if multiBuffer(13) == 0x00 then
lcd.drawText(10,50,"No Config telemetry...", BLINK)
end
else
--Draw on LCD_W=128
lcd.drawText(1, 0, "Multi Config " .. Version, SMLSIZE)
if multiBuffer(13) == 0x00 then
lcd.drawText(2,17,"No Config telemetry...",SMLSIZE)
end
end
if multiBuffer(13) ~= 0x00 then
if LCD_W == 480 then
--Draw firmware version and channels order
local ch_order = multiBuffer(17)
local channel_names = {}
channel_names[bitand(ch_order,3)+1] = "A"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "E"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "T"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "R"
lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16), MENU_TITLE_COLOR)
--lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16) .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4], MENU_TITLE_COLOR)
else
lcd.drawText(76, 0, "/Fw" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16),SMLSIZE) -- .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4])
end
--Draw Menu
for line = 1, 7, 1 do
--Clear line info
Menu[line].text = ""
Menu[line].field_type = 0
Menu[line].field_len = 0
for i = 1, 7, 1 do
Menu[line].field_value[i] = 0
end
Menu[line].field_text = ""
length = 0
--Read line from buffer
for i = 0, 20-1, 1 do
value=multiBuffer( line*20+13+i )
if value == 0 then
break -- end of line
end
if value > 0x80 and Menu[line].field_type == 0 then
-- Read field type
Menu[line].field_type = bitand(value, 0xF0)
Menu[line].field_len = bitand(value, 0x0F)
length = Menu[line].field_len
if Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 and Focus == -1 then
-- First actionnable field if nothing was selected
Focus = line;
end
else
if Menu[line].field_type == 0 then
-- Text
Menu[line].text = Menu[line].text .. string.char(value)
else
-- Menu specific fields
length = length - 1
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
Menu[line].field_text = Menu[line].field_text .. string.char(value)
else
Menu[line].field_value[Menu[line].field_len-length] = value
end
if length == 0 then
-- End of fields
break
end
end
end
end
-- Display menu text
if Menu[line].text ~= "" then
if Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 or Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
Menu[line].text = Menu[line].text .. ":"
end
if LCD_W == 480 then
lcd.drawText(10,32+20*line,Menu[line].text )
else
lcd.drawText(2,1+8*line,Menu[line].text,SMLSIZE)
end
end
-- Display specific fields
if line == Focus then
attrib = INVERS
else
attrib = 0
end
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
-- Text
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, Menu[line].field_text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, Menu[line].field_text, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 then
-- Decimal value
value = 0
for i = 1, Menu[line].field_len, 1 do
value = value*256 + value
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, value, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, value, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
-- Hex value
text=""
for i = 1, Menu[line].field_len, 1 do
text = text .. string.format('%02X ', Menu[line].field_value[i])
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, text, SMLSIZE + attrib)
end
end
end
end
end
-- Init
local function Config_Init()
--get Module settings and set to config
Module = model.getModule(1)
InitialProtocol = Module.protocol
Module.protocol = 86
model.setModule(1, Module)
for i = 0, 10, 1 do end
--Set protocol to talk to
multiBuffer( 0, string.byte('C') )
--test if value has been written
if multiBuffer( 0 ) ~= string.byte('C') then
error("Not enough memory!")
return 2
end
--Request init of the buffer
multiBuffer( 4, 0xFF )
--Continue buffer init
multiBuffer( 1, string.byte('o') )
multiBuffer( 2, string.byte('n') )
multiBuffer( 3, string.byte('f') )
-- Test set
-- multiBuffer( 12, 0 )
-- multiBuffer( 13, 1 )
-- multiBuffer( 14, 3 )
-- multiBuffer( 15, 2 )
-- multiBuffer( 16, 62 )
-- multiBuffer( 17, 0 + 1*4 + 2*16 + 3*64)
-- multiBuffer( 33, string.byte('G') )
-- multiBuffer( 34, string.byte('l') )
-- multiBuffer( 35, string.byte('o') )
-- multiBuffer( 36, string.byte('b') )
-- multiBuffer( 37, string.byte('a') )
-- multiBuffer( 38, string.byte('l') )
-- multiBuffer( 39, string.byte(' ') )
-- multiBuffer( 40, string.byte('I') )
-- multiBuffer( 41, string.byte('D') )
-- multiBuffer( 42, 0xD0 + 4 )
-- multiBuffer( 43, 0x12 )
-- multiBuffer( 44, 0x34 )
-- multiBuffer( 45, 0x56 )
-- multiBuffer( 46, 0x78 )
-- multiBuffer( 47, 0x9A )
-- multiBuffer( 48, 0xBC )
-- multiBuffer( 53, 0x90 + 9 )
-- multiBuffer( 54, string.byte('R') )
-- multiBuffer( 55, string.byte('e') )
-- multiBuffer( 56, string.byte('s') )
-- multiBuffer( 57, string.byte('e') )
-- multiBuffer( 58, string.byte('t') )
-- multiBuffer( 59, string.byte(' ') )
-- multiBuffer( 60, string.byte('G') )
-- multiBuffer( 61, string.byte('I') )
-- multiBuffer( 62, string.byte('D') )
-- multiBuffer( 63, 0x00 )
end
-- Main
local function Config_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
Config_Release()
return 2
else
Config_Draw_Menu()
if ( event == EVT_VIRTUAL_PREV_PAGE or event == EVT_VIRTUAL_NEXT_PAGE ) and Edit < 1 then
-- Not editing, ok to change page
if event == EVT_VIRTUAL_PREV_PAGE then
killEvents(event)
if Page > 0 then
--Page = Page - 1
--Config_Page()
end
else
--Page = Page + 1
--Config_Page()
end
end
if Focus > 0 then
-- At least one line has an action
if Edit >= 0 then
-- Currently editing
Config_Draw_Edit( event )
elseif event == EVT_VIRTUAL_ENTER then
-- Switch to edit
Config_Draw_Edit( 0 )
elseif event == EVT_VIRTUAL_PREV or event == EVT_VIRTUAL_NEXT then
-- Main menu selection
Config_Next_Prev( event )
end
end
return 0
end
end
return { init=Config_Init, run=Config_Run }

View file

@ -0,0 +1,499 @@
---- #########################################################################
---- # #
---- # 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. #
---- # #
---- #########################################################################
--###############################################################################
-- Multi buffer for Config description
-- To start operation:
-- Write 0xFF at address 4 will request the buffer to be cleared
-- Write "Conf" at address 0..3
-- Read
-- Read at address 12 gives the current config page
-- Read at address 13..172 gives the current data of the page = 8 lines * 20 caracters
-- Write
-- Write at address 5..11 the command
-- Write 0x01 at address 4 will send the command to the module
-- !! Before exiting the script must write 0 at address 0 for normal operation !!
--###############################################################################
local Version = "v0.1"
local Focus = -1
local Page = 0
local Edit = -1
local Edit_pos = 1
local Menu = { {text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""} }
local Menu_value = {}
local Blink = 0
local Module = {}
local InitialProtocol = 0
function bitand(a, b)
local result = 0
local bitval = 1
while a > 0 and b > 0 do
if a % 2 == 1 and b % 2 == 1 then -- test the rightmost bits
result = result + bitval -- set the current bit
end
bitval = bitval * 2 -- shift left
a = math.floor(a/2) -- shift right
b = math.floor(b/2)
end
return result
end
local function Config_Send(page, line, value)
local i
i = (page*16) + line
multiBuffer( 5, i )
for i = 1 , 6 , 1 do
multiBuffer( 5+i, value[i] )
end
multiBuffer( 4, 1 )
end
local function Config_Release()
Module.protocol = InitialProtocol
model.setModule(0, Module)
local i
for i = 3 , 0 , -1 do
multiBuffer( i, 0 )
end
end
local function Config_Page( )
Config_Send(Page, 0, { 0, 0, 0, 0, 0, 0 })
end
local function Config_Draw_Edit( event )
local i
local text
if Menu[Focus].field_type == 0xD0 then
-- Editable Hex value
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 1
Blink = 0
for i = 1, Menu[Focus].field_len, 1 do
Menu_value[i] = Menu[Focus].field_value[i]
end
end
if Edit == 0 then
-- Not editing value
if event == EVT_VIRTUAL_ENTER then
if Edit_pos > Menu[Focus].field_len then
-- Save or Cancel
Edit = -1
if Edit_pos == Menu[Focus].field_len + 1 then
-- Save
Config_Send(Page, Focus, Menu_value)
end
return
else
-- Switch to edit mode
Edit = 1
end
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Move cursor
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < Menu[Focus].field_len + 2 then
-- Move cursor
Edit_pos = Edit_pos + 1
end
else
-- Editing value
if event == EVT_VIRTUAL_ENTER then
-- End edit
Edit = 0
elseif event == EVT_VIRTUAL_PREV then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] - 1
elseif event == EVT_VIRTUAL_NEXT then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] + 1
end
--Blink
Blink = Blink + 1
if Blink > 30 then
Blink = 0
end
end
--Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
for i = 1, Menu[Focus].field_len, 1 do
if i==Edit_pos and (Edit ~= 1 or Blink > 15) then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170+12*2*(i-1), 110, string.format('%02X', Menu_value[i]), attrib)
else
lcd.drawText(17+6*2*(i-1), 10, string.format('%02X', Menu_value[i]), attrib + SMLSIZE)
end
end
if Edit_pos == Menu[Focus].field_len + 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Save", attrib)
else
lcd.drawText(17, 30, "Save", attrib + SMLSIZE)
end
if Edit_pos == Menu[Focus].field_len + 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "Cancel", attrib)
else
lcd.drawText(77, 30, "Cancel", attrib + SMLSIZE)
end
elseif Menu[Focus].field_type == 0x90 then
-- Action text
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 2
end
if event == EVT_VIRTUAL_ENTER then
-- Exit
Edit = -1
if Edit_pos == 1 then
-- Yes
Config_Send(Page, Focus, { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA } )
end
return
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Switch to Yes
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < 2 then
-- Switch to No
Edit_pos = Edit_pos + 1
end
-- Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
if LCD_W == 480 then
lcd.drawText(170, 110, Menu[Focus].field_text .. "?")
else
lcd.drawText(17, 10, Menu[Focus].field_text .. "?", SMLSIZE)
end
if Edit_pos == 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Yes", attrib)
else
lcd.drawText(17, 30, "Yes", attrib + SMLSIZE)
end
if Edit_pos == 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "No", attrib)
else
lcd.drawText(77, 30, "No", attrib)
end
end
end
local function Config_Next_Prev( event )
-- Next Prev on main menu
local line
if event == EVT_VIRTUAL_PREV then
for line = Focus - 1, 1, -1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
elseif event == EVT_VIRTUAL_NEXT then
for line = Focus + 1, 7, 1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
end
end
local function Config_Draw_Menu()
-- Main menu
local i
local value
local line
local length
local text
lcd.clear()
if LCD_W == 480 then
--Draw title
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, "Multi Config " .. Version, MENU_TITLE_COLOR)
if multiBuffer(13) == 0x00 then
lcd.drawText(10,50,"No Config telemetry...", BLINK)
end
else
--Draw on LCD_W=128
lcd.drawText(1, 0, "Multi Config " .. Version, SMLSIZE)
if multiBuffer(13) == 0x00 then
lcd.drawText(2,17,"No Config telemetry...",SMLSIZE)
end
end
if multiBuffer(13) ~= 0x00 then
if LCD_W == 480 then
--Draw firmware version and channels order
local ch_order = multiBuffer(17)
local channel_names = {}
channel_names[bitand(ch_order,3)+1] = "A"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "E"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "T"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "R"
lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16), MENU_TITLE_COLOR)
--lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16) .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4], MENU_TITLE_COLOR)
else
lcd.drawText(76, 0, "/Fw" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16),SMLSIZE) -- .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4])
end
--Draw Menu
for line = 1, 7, 1 do
--Clear line info
Menu[line].text = ""
Menu[line].field_type = 0
Menu[line].field_len = 0
for i = 1, 7, 1 do
Menu[line].field_value[i] = 0
end
Menu[line].field_text = ""
length = 0
--Read line from buffer
for i = 0, 20-1, 1 do
value=multiBuffer( line*20+13+i )
if value == 0 then
break -- end of line
end
if value > 0x80 and Menu[line].field_type == 0 then
-- Read field type
Menu[line].field_type = bitand(value, 0xF0)
Menu[line].field_len = bitand(value, 0x0F)
length = Menu[line].field_len
if Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 and Focus == -1 then
-- First actionnable field if nothing was selected
Focus = line;
end
else
if Menu[line].field_type == 0 then
-- Text
Menu[line].text = Menu[line].text .. string.char(value)
else
-- Menu specific fields
length = length - 1
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
Menu[line].field_text = Menu[line].field_text .. string.char(value)
else
Menu[line].field_value[Menu[line].field_len-length] = value
end
if length == 0 then
-- End of fields
break
end
end
end
end
-- Display menu text
if Menu[line].text ~= "" then
if Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 or Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
Menu[line].text = Menu[line].text .. ":"
end
if LCD_W == 480 then
lcd.drawText(10,32+20*line,Menu[line].text )
else
lcd.drawText(2,1+8*line,Menu[line].text,SMLSIZE)
end
end
-- Display specific fields
if line == Focus then
attrib = INVERS
else
attrib = 0
end
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
-- Text
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, Menu[line].field_text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, Menu[line].field_text, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 then
-- Decimal value
value = 0
for i = 1, Menu[line].field_len, 1 do
value = value*256 + value
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, value, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, value, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
-- Hex value
text=""
for i = 1, Menu[line].field_len, 1 do
text = text .. string.format('%02X ', Menu[line].field_value[i])
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, text, SMLSIZE + attrib)
end
end
end
end
end
-- Init
local function Config_Init()
--get Module settings and set to config
Module = model.getModule(0)
InitialProtocol = Module.protocol
Module.protocol = 86
model.setModule(0, Module)
for i = 0, 10, 1 do end
--Set protocol to talk to
multiBuffer( 0, string.byte('C') )
--test if value has been written
if multiBuffer( 0 ) ~= string.byte('C') then
error("Not enough memory!")
return 2
end
--Request init of the buffer
multiBuffer( 4, 0xFF )
--Continue buffer init
multiBuffer( 1, string.byte('o') )
multiBuffer( 2, string.byte('n') )
multiBuffer( 3, string.byte('f') )
-- Test set
-- multiBuffer( 12, 0 )
-- multiBuffer( 13, 1 )
-- multiBuffer( 14, 3 )
-- multiBuffer( 15, 2 )
-- multiBuffer( 16, 62 )
-- multiBuffer( 17, 0 + 1*4 + 2*16 + 3*64)
-- multiBuffer( 33, string.byte('G') )
-- multiBuffer( 34, string.byte('l') )
-- multiBuffer( 35, string.byte('o') )
-- multiBuffer( 36, string.byte('b') )
-- multiBuffer( 37, string.byte('a') )
-- multiBuffer( 38, string.byte('l') )
-- multiBuffer( 39, string.byte(' ') )
-- multiBuffer( 40, string.byte('I') )
-- multiBuffer( 41, string.byte('D') )
-- multiBuffer( 42, 0xD0 + 4 )
-- multiBuffer( 43, 0x12 )
-- multiBuffer( 44, 0x34 )
-- multiBuffer( 45, 0x56 )
-- multiBuffer( 46, 0x78 )
-- multiBuffer( 47, 0x9A )
-- multiBuffer( 48, 0xBC )
-- multiBuffer( 53, 0x90 + 9 )
-- multiBuffer( 54, string.byte('R') )
-- multiBuffer( 55, string.byte('e') )
-- multiBuffer( 56, string.byte('s') )
-- multiBuffer( 57, string.byte('e') )
-- multiBuffer( 58, string.byte('t') )
-- multiBuffer( 59, string.byte(' ') )
-- multiBuffer( 60, string.byte('G') )
-- multiBuffer( 61, string.byte('I') )
-- multiBuffer( 62, string.byte('D') )
-- multiBuffer( 63, 0x00 )
end
-- Main
local function Config_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
Config_Release()
return 2
else
Config_Draw_Menu()
if ( event == EVT_VIRTUAL_PREV_PAGE or event == EVT_VIRTUAL_NEXT_PAGE ) and Edit < 1 then
-- Not editing, ok to change page
if event == EVT_VIRTUAL_PREV_PAGE then
killEvents(event)
if Page > 0 then
--Page = Page - 1
--Config_Page()
end
else
--Page = Page + 1
--Config_Page()
end
end
if Focus > 0 then
-- At least one line has an action
if Edit >= 0 then
-- Currently editing
Config_Draw_Edit( event )
elseif event == EVT_VIRTUAL_ENTER then
-- Switch to edit
Config_Draw_Edit( 0 )
elseif event == EVT_VIRTUAL_PREV or event == EVT_VIRTUAL_NEXT then
-- Main menu selection
Config_Next_Prev( event )
end
end
return 0
end
end
return { init=Config_Init, run=Config_Run }

View file

Before

Width:  |  Height:  |  Size: 9 KiB

After

Width:  |  Height:  |  Size: 9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before After
Before After

View file

@ -6,6 +6,7 @@
14,4,Bayang,DHD_D4,1,Flip,RTH,Pict,Video,HLess,Invert,Rates,TakeOf,EmStop
14,5,Bayang,QX100,1,Flip,RTH,Pict,Video,HLess,Invert,Rates,TakeOf,EmStop
59,0,BayangRX,RX,1,AnAux1,AnAux2,Flip,RTH,Pict,Video
59,1,BayangRX,CPPM,1,AnAux1,AnAux2,Flip,RTH,Pict,Video
41,0,Bugs,3-6-8,0,Arm,Angle,Flip,Pict,Video,LED
42,0,BugsMini,Mini,0,Arm,Angle,Flip,Pict,Video,LED
42,1,BugsMini,3H,0,Arm,Angle,Flip,Pict,Video,LED,AltHol
@ -34,9 +35,9 @@
6,3,DSM,X_11,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,n-a,ThKill
6,4,DSM,AUTO,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,n-a,ThKill
70,0,DSM_RX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
70,1,DSM_RX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
45,0,E01X,E012,1,n-a,Flip,n-a,HLess,RTH
45,1,E01X,E015,1,Arm,Flip,LED,HLess,RTH
45,2,E01X,E016H,1,Stop,Flip,n-a,HLess,RTH
16,0,ESKY,Std,0,Gyro,Pitch
16,1,ESKY,ET4,0,Gyro,Pitch
35,0,ESKY150,4CH,0
@ -54,6 +55,7 @@
28,4,Flysky_AFHDS2A,PWM_IB16,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
28,5,Flysky_AFHDS2A,PPM_IB16,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
56,0,Flysky2A_RX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14
56,1,Flysky2A_RX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14
53,0,Height,5ch,0,Gear
53,1,Height,8ch,0,Gear,Gyro,Flap,Light
25,0,FrSkyV,V8,0,CH5,CH6,CH7,CH8
@ -79,6 +81,8 @@
65,3,FrSkyR9,R9_968_8CH,0,CH5,CH6,CH7,CH8
55,0,FrSkyRX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
55,1,FrSkyRX,CloneTX,0
55,2,FrSkyRX,EraseTX,0
55,3,FrSkyRX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
58,0,FX816,P38,1
20,0,FY326,FY326,1,Flip,RTH,HLess,Expert,Calib
20,1,FY326,FY319,1,Flip,RTH,HLess,Expert,Calib
@ -99,13 +103,14 @@
26,1,Hontai,JJRCX1,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
26,2,Hontai,X5C1,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
26,3,Hontai,FQ777_951,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
57,0,HoTT,Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
57,1,HoTT,No_Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
57,0,HoTT,Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
57,1,HoTT,No_Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
2,0,Hubsan,H107,1,Flip,Light,Pict,Video,HLess
2,1,Hubsan,H301,0,RTH,Light,Stab,Video
2,2,Hubsan,H501,0,RTH,Light,Pict,Video,HLess,GPS_H,ALT_H,Flip,FModes
22,0,J6Pro,Std,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
71,0,JJRC345,Std,1,Flip,HLess,RTH
71,0,JJRC345,JJRC345,1,Flip,HLess,RTH,LED,UNK1,UNK2,UNK3
71,1,JJRC345,SkyTmblr,1,Flip,HLess,RTH,LED,UNK1,UNK2,UNK3
49,0,KF606,Std,1,Trim
9,0,KN,WLToys,0,DRate,THold,IdleUp,Gyro,Ttrim,Atrim,Etrim
9,1,KN,Feilun,0,DRate,THold,IdleUp,Gyro,Ttrim,Atrim,Etrim
@ -122,6 +127,8 @@
17,2,MT99XX,YZ,1,Flip,LED,Pict,Video,HLess
17,3,MT99XX,LS,1,Flip,Invert,Pict,Video,HLess
17,4,MT99XX,FY805,1,Flip,n-a,n-a,n-a,HLess
17,5,MT99XX,A180,0,3D_6G
17,6,MT99XX,Dragon,0,Mode,RTH
44,0,NCC1701,Std,1,Warp
77,0,OMP,M2,0,THold,IdleUp,6G_3D
60,0,Pelikan,PRO_V4,0,CH5,CH6,CH7,CH8
@ -138,10 +145,11 @@
72,0,Q90C,Std,0,FMode,VTX+
74,0,RadioLink,Surface,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
74,1,RadioLink,Air,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
74,2,RadioLink,DumboRC,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
76,0,Realacc,R11,1,Flip,Light,Calib,HLess,RTH,UNK
50,0,Redpine,Fast,0,sCH5,sCH6,sCH7,sCH8,sCH9,sCH10,sCH11,sCH12,sCH13,sCH14,sCH15,sCH16
50,1,Redpine,Slow,0,sCH5,sCH6,sCH7,sCH8,sCH9,sCH10,sCH11,sCH12,sCH13,sCH14,sCH15,sCH16
21,0,SFHSS,Std,0,CH5,CH6,CH7,CH8
21,0,Futaba,SFHSS,0,CH5,CH6,CH7,CH8
19,0,Shenqi,Cycle,1
68,0,Skyartec,Std,0,CH5,CH6,CH7
11,0,SLT,V1,0,Gear,Pitch
@ -174,3 +182,11 @@
8,3,YD717,XinXun,1,Flip,Light,Pict,Video,HLess
8,4,YD717,NiHui,1,Flip,Light,Pict,Video,HLess
52,0,ZSX,280,1,Light
78,0,M-Link,Std,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
79,0,WFLY2,RF20x,0,CH5,CH6,CH7,CH8,CH9,CH10
80,0,E016Hv2,E016Hv2,1,TakLan,EmStop,Flip,Calib,HLess,RTH
81,0,E010r5,E010r5,1,Flip,LED,CALIB,HLess,RTH,GLIDE
82,0,LOLI,Std,0,CH5,CH6,CH7,CH8,1SwSePpPw,2SwSePw,3SwSe,4SwSe,5SwSeSb,6SwSe,7SwSePw,8SwSe
83,0,E129,E129,1,TakLan,EmStop,TrimA,TrimE,TrimR
84,0,JOYSWAY,Std,0
85,0,E016H,Std,1,Stop,Flip,n-a,HLess,RTH

View file

@ -0,0 +1,221 @@
local toolName = "TNS|Multi LOLI RX config|TNE"
---- #########################################################################
---- # #
---- # 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 loli_nok = false
local channels={ { 768, "PWM", 100, 102, "PPM", 50, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH1
{ 768, "PWM", 100, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH2
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH3
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH4
{ 102, "SBUS", 50, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH5
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH6
{ 768, "PWM", 100, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH7
{ -768, "Servo", 0, -2048, "Switch", -100 } } -- CH8
local sel = 1
local edit = false
local blink = 0
local BLINK_SPEED = 15
local function drawScreenTitle(title)
if LCD_W == 480 then
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, title, MENU_TITLE_COLOR)
else
lcd.drawScreenTitle(title, 0, 0)
end
end
local function LOLI_Draw_LCD(event)
local line = 0
lcd.clear()
--Display settings
local lcd_opt = 0
if LCD_W == 480 then
drawScreenTitle("Multi - LOLI RX configuration tool")
x_pos = 152
x_inc = 90
y_pos = 40
y_inc = 20
else
x_pos = 5
x_inc = 30
y_pos = 1
y_inc = 8
lcd_opt = SMLSIZE
end
--Multi Module detection
if loli_nok then
if LCD_W == 480 then
lcd.drawText(10,50,"The LOLI protocol is not selected...", lcd_opt)
else
--Draw on LCD_W=128
lcd.drawText(2,17,"LOLI protocol not selected...",SMLSIZE)
end
return
end
--Display current config
if LCD_W == 480 then
line = line + 1
lcd.drawText(x_pos, y_pos+y_inc*line -2, "Channel", lcd_opt)
lcd.drawText(x_pos+x_inc, y_pos+y_inc*line -2, "Function", lcd_opt)
lcd.drawRectangle(x_pos-4, y_pos+y_inc*line -4 , 2*x_inc +2, 188)
lcd.drawLine(x_pos-4, y_pos+y_inc*line +18, x_pos-4 +2*x_inc +1, y_pos+y_inc*line +18, SOLID, 0)
lcd.drawLine(x_pos+x_inc -5, y_pos+y_inc*line -4, x_pos+x_inc -5, y_pos+y_inc*line -5 +188, SOLID, 0)
line = line + 1
end
local out
for i = 1, 8 do
out = getValue("ch"..(i+8))
lcd.drawText(x_pos, y_pos+y_inc*line, "CH"..i, lcd_opt)
for j = 1, #channels[i], 3 do
if out > channels[i][j] then
if sel == i then
invert = INVERS
if edit == true then
blink = blink + 1
if blink > BLINK_SPEED then
invert = 0
if blink > BLINK_SPEED * 2 then
blink = 0
end
end
end
else
invert = 0
end
lcd.drawText(x_pos+x_inc, y_pos+y_inc*line, channels[i][j+1], lcd_opt + invert)
break
end
end
line = line + 1
end
end
local function LOLI_Change_Value(dir)
local pos = 0
local out
--look for the current position
out = getValue("ch"..(sel+8))
for j = 1, #channels[sel], 3 do
if out > channels[sel][j] then
pos = j
break
end
end
--decrement or increment
if dir < 0 and pos > 1 then
pos = pos - 3
elseif dir > 0 and pos + 3 < #channels[sel] then
pos = pos + 3
else
return
end
--delete all mixers for the selected channel
local num_mix = model.getMixesCount(sel-1 +8)
for i = 1, num_mix do
model.deleteMix(sel-1 +8, 0);
end
--create new mixer
local source_max = getFieldInfo("cyc1")
local val = { name = channels[sel][pos+1],
source = source_max.id - 1, -- MAX=100 on TX16S
weight = channels[sel][pos+2],
offset = 0,
switch = 0,
multiplex = 0,
curveType = 0,
curveValue = 0,
flightModes = 0,
carryTrim = false,
mixWarn = 0,
delayUp = 0,
delayDown = 0,
speedUp = 0,
speedDown = 0 }
model.insertMix(sel-1 +8, 0, val)
end
local function LOLI_Menu(event)
if event == EVT_VIRTUAL_NEXT then
if edit == false then
-- not changing a value
if sel < 8 then
sel = sel + 1
end
else
-- need to inc the value
LOLI_Change_Value(1)
end
elseif event == EVT_VIRTUAL_PREV then
if edit == false then
-- not changing a value
if sel > 1 then
sel = sel - 1
end
else
-- need to dec the value
LOLI_Change_Value(-1)
end
elseif event == EVT_VIRTUAL_ENTER then
if edit == false then
edit = true
blink = BLINK_SPEED
else
edit = false
end
end
end
-- Init
local function LOLI_Init()
local module_conf = model.getModule(0)
if module_conf["Type"] ~= 6 or module_conf["protocol"] ~= 82 then
module_conf = model.getModule(1)
if module_conf["Type"] ~= 6 or module_conf["protocol"] ~= 82 then
loli_nok = true
end
end
end
-- Main
local function LOLI_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
return 2
else
LOLI_Menu(event)
LOLI_Draw_LCD(event)
return 0
end
end
return { init=LOLI_Init, run=LOLI_Run }

View file

@ -0,0 +1,499 @@
---- #########################################################################
---- # #
---- # 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. #
---- # #
---- #########################################################################
--###############################################################################
-- Multi buffer for Config description
-- To start operation:
-- Write 0xFF at address 4 will request the buffer to be cleared
-- Write "Conf" at address 0..3
-- Read
-- Read at address 12 gives the current config page
-- Read at address 13..172 gives the current data of the page = 8 lines * 20 caracters
-- Write
-- Write at address 5..11 the command
-- Write 0x01 at address 4 will send the command to the module
-- !! Before exiting the script must write 0 at address 0 for normal operation !!
--###############################################################################
local Version = "v0.1"
local Focus = -1
local Page = 0
local Edit = -1
local Edit_pos = 1
local Menu = { {text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""} }
local Menu_value = {}
local Blink = 0
local Module = {}
local InitialProtocol = 0
function bitand(a, b)
local result = 0
local bitval = 1
while a > 0 and b > 0 do
if a % 2 == 1 and b % 2 == 1 then -- test the rightmost bits
result = result + bitval -- set the current bit
end
bitval = bitval * 2 -- shift left
a = math.floor(a/2) -- shift right
b = math.floor(b/2)
end
return result
end
local function Config_Send(page, line, value)
local i
i = (page*16) + line
multiBuffer( 5, i )
for i = 1 , 6 , 1 do
multiBuffer( 5+i, value[i] )
end
multiBuffer( 4, 1 )
end
local function Config_Release()
Module.protocol = InitialProtocol
model.setModule(1, Module)
local i
for i = 3 , 0 , -1 do
multiBuffer( i, 0 )
end
end
local function Config_Page( )
Config_Send(Page, 0, { 0, 0, 0, 0, 0, 0 })
end
local function Config_Draw_Edit( event )
local i
local text
if Menu[Focus].field_type == 0xD0 then
-- Editable Hex value
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 1
Blink = 0
for i = 1, Menu[Focus].field_len, 1 do
Menu_value[i] = Menu[Focus].field_value[i]
end
end
if Edit == 0 then
-- Not editing value
if event == EVT_VIRTUAL_ENTER then
if Edit_pos > Menu[Focus].field_len then
-- Save or Cancel
Edit = -1
if Edit_pos == Menu[Focus].field_len + 1 then
-- Save
Config_Send(Page, Focus, Menu_value)
end
return
else
-- Switch to edit mode
Edit = 1
end
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Move cursor
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < Menu[Focus].field_len + 2 then
-- Move cursor
Edit_pos = Edit_pos + 1
end
else
-- Editing value
if event == EVT_VIRTUAL_ENTER then
-- End edit
Edit = 0
elseif event == EVT_VIRTUAL_PREV then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] - 1
elseif event == EVT_VIRTUAL_NEXT then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] + 1
end
--Blink
Blink = Blink + 1
if Blink > 30 then
Blink = 0
end
end
--Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
for i = 1, Menu[Focus].field_len, 1 do
if i==Edit_pos and (Edit ~= 1 or Blink > 15) then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170+12*2*(i-1), 110, string.format('%02X', Menu_value[i]), attrib)
else
lcd.drawText(17+6*2*(i-1), 10, string.format('%02X', Menu_value[i]), attrib + SMLSIZE)
end
end
if Edit_pos == Menu[Focus].field_len + 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Save", attrib)
else
lcd.drawText(17, 30, "Save", attrib + SMLSIZE)
end
if Edit_pos == Menu[Focus].field_len + 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "Cancel", attrib)
else
lcd.drawText(77, 30, "Cancel", attrib + SMLSIZE)
end
elseif Menu[Focus].field_type == 0x90 then
-- Action text
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 2
end
if event == EVT_VIRTUAL_ENTER then
-- Exit
Edit = -1
if Edit_pos == 1 then
-- Yes
Config_Send(Page, Focus, { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA } )
end
return
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Switch to Yes
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < 2 then
-- Switch to No
Edit_pos = Edit_pos + 1
end
-- Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
if LCD_W == 480 then
lcd.drawText(170, 110, Menu[Focus].field_text .. "?")
else
lcd.drawText(17, 10, Menu[Focus].field_text .. "?", SMLSIZE)
end
if Edit_pos == 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Yes", attrib)
else
lcd.drawText(17, 30, "Yes", attrib + SMLSIZE)
end
if Edit_pos == 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "No", attrib)
else
lcd.drawText(77, 30, "No", attrib)
end
end
end
local function Config_Next_Prev( event )
-- Next Prev on main menu
local line
if event == EVT_VIRTUAL_PREV then
for line = Focus - 1, 1, -1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
elseif event == EVT_VIRTUAL_NEXT then
for line = Focus + 1, 7, 1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
end
end
local function Config_Draw_Menu()
-- Main menu
local i
local value
local line
local length
local text
lcd.clear()
if LCD_W == 480 then
--Draw title
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, "Multi Config " .. Version, MENU_TITLE_COLOR)
if multiBuffer(13) == 0x00 then
lcd.drawText(10,50,"No Config telemetry...", BLINK)
end
else
--Draw on LCD_W=128
lcd.drawText(1, 0, "Multi Config " .. Version, SMLSIZE)
if multiBuffer(13) == 0x00 then
lcd.drawText(2,17,"No Config telemetry...",SMLSIZE)
end
end
if multiBuffer(13) ~= 0x00 then
if LCD_W == 480 then
--Draw firmware version and channels order
local ch_order = multiBuffer(17)
local channel_names = {}
channel_names[bitand(ch_order,3)+1] = "A"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "E"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "T"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "R"
lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16), MENU_TITLE_COLOR)
--lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16) .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4], MENU_TITLE_COLOR)
else
lcd.drawText(76, 0, "/Fw" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16),SMLSIZE) -- .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4])
end
--Draw Menu
for line = 1, 7, 1 do
--Clear line info
Menu[line].text = ""
Menu[line].field_type = 0
Menu[line].field_len = 0
for i = 1, 7, 1 do
Menu[line].field_value[i] = 0
end
Menu[line].field_text = ""
length = 0
--Read line from buffer
for i = 0, 20-1, 1 do
value=multiBuffer( line*20+13+i )
if value == 0 then
break -- end of line
end
if value > 0x80 and Menu[line].field_type == 0 then
-- Read field type
Menu[line].field_type = bitand(value, 0xF0)
Menu[line].field_len = bitand(value, 0x0F)
length = Menu[line].field_len
if Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 and Focus == -1 then
-- First actionnable field if nothing was selected
Focus = line;
end
else
if Menu[line].field_type == 0 then
-- Text
Menu[line].text = Menu[line].text .. string.char(value)
else
-- Menu specific fields
length = length - 1
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
Menu[line].field_text = Menu[line].field_text .. string.char(value)
else
Menu[line].field_value[Menu[line].field_len-length] = value
end
if length == 0 then
-- End of fields
break
end
end
end
end
-- Display menu text
if Menu[line].text ~= "" then
if Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 or Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
Menu[line].text = Menu[line].text .. ":"
end
if LCD_W == 480 then
lcd.drawText(10,32+20*line,Menu[line].text )
else
lcd.drawText(2,1+8*line,Menu[line].text,SMLSIZE)
end
end
-- Display specific fields
if line == Focus then
attrib = INVERS
else
attrib = 0
end
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
-- Text
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, Menu[line].field_text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, Menu[line].field_text, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 then
-- Decimal value
value = 0
for i = 1, Menu[line].field_len, 1 do
value = value*256 + value
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, value, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, value, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
-- Hex value
text=""
for i = 1, Menu[line].field_len, 1 do
text = text .. string.format('%02X ', Menu[line].field_value[i])
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, text, SMLSIZE + attrib)
end
end
end
end
end
-- Init
local function Config_Init()
--get Module settings and set to config
Module = model.getModule(1)
InitialProtocol = Module.protocol
Module.protocol = 86
model.setModule(1, Module)
for i = 0, 10, 1 do end
--Set protocol to talk to
multiBuffer( 0, string.byte('C') )
--test if value has been written
if multiBuffer( 0 ) ~= string.byte('C') then
error("Not enough memory!")
return 2
end
--Request init of the buffer
multiBuffer( 4, 0xFF )
--Continue buffer init
multiBuffer( 1, string.byte('o') )
multiBuffer( 2, string.byte('n') )
multiBuffer( 3, string.byte('f') )
-- Test set
-- multiBuffer( 12, 0 )
-- multiBuffer( 13, 1 )
-- multiBuffer( 14, 3 )
-- multiBuffer( 15, 2 )
-- multiBuffer( 16, 62 )
-- multiBuffer( 17, 0 + 1*4 + 2*16 + 3*64)
-- multiBuffer( 33, string.byte('G') )
-- multiBuffer( 34, string.byte('l') )
-- multiBuffer( 35, string.byte('o') )
-- multiBuffer( 36, string.byte('b') )
-- multiBuffer( 37, string.byte('a') )
-- multiBuffer( 38, string.byte('l') )
-- multiBuffer( 39, string.byte(' ') )
-- multiBuffer( 40, string.byte('I') )
-- multiBuffer( 41, string.byte('D') )
-- multiBuffer( 42, 0xD0 + 4 )
-- multiBuffer( 43, 0x12 )
-- multiBuffer( 44, 0x34 )
-- multiBuffer( 45, 0x56 )
-- multiBuffer( 46, 0x78 )
-- multiBuffer( 47, 0x9A )
-- multiBuffer( 48, 0xBC )
-- multiBuffer( 53, 0x90 + 9 )
-- multiBuffer( 54, string.byte('R') )
-- multiBuffer( 55, string.byte('e') )
-- multiBuffer( 56, string.byte('s') )
-- multiBuffer( 57, string.byte('e') )
-- multiBuffer( 58, string.byte('t') )
-- multiBuffer( 59, string.byte(' ') )
-- multiBuffer( 60, string.byte('G') )
-- multiBuffer( 61, string.byte('I') )
-- multiBuffer( 62, string.byte('D') )
-- multiBuffer( 63, 0x00 )
end
-- Main
local function Config_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
Config_Release()
return 2
else
Config_Draw_Menu()
if ( event == EVT_VIRTUAL_PREV_PAGE or event == EVT_VIRTUAL_NEXT_PAGE ) and Edit < 1 then
-- Not editing, ok to change page
if event == EVT_VIRTUAL_PREV_PAGE then
killEvents(event)
if Page > 0 then
--Page = Page - 1
--Config_Page()
end
else
--Page = Page + 1
--Config_Page()
end
end
if Focus > 0 then
-- At least one line has an action
if Edit >= 0 then
-- Currently editing
Config_Draw_Edit( event )
elseif event == EVT_VIRTUAL_ENTER then
-- Switch to edit
Config_Draw_Edit( 0 )
elseif event == EVT_VIRTUAL_PREV or event == EVT_VIRTUAL_NEXT then
-- Main menu selection
Config_Next_Prev( event )
end
end
return 0
end
end
return { init=Config_Init, run=Config_Run }

View file

@ -0,0 +1,499 @@
---- #########################################################################
---- # #
---- # 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. #
---- # #
---- #########################################################################
--###############################################################################
-- Multi buffer for Config description
-- To start operation:
-- Write 0xFF at address 4 will request the buffer to be cleared
-- Write "Conf" at address 0..3
-- Read
-- Read at address 12 gives the current config page
-- Read at address 13..172 gives the current data of the page = 8 lines * 20 caracters
-- Write
-- Write at address 5..11 the command
-- Write 0x01 at address 4 will send the command to the module
-- !! Before exiting the script must write 0 at address 0 for normal operation !!
--###############################################################################
local Version = "v0.1"
local Focus = -1
local Page = 0
local Edit = -1
local Edit_pos = 1
local Menu = { {text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""} }
local Menu_value = {}
local Blink = 0
local Module = {}
local InitialProtocol = 0
function bitand(a, b)
local result = 0
local bitval = 1
while a > 0 and b > 0 do
if a % 2 == 1 and b % 2 == 1 then -- test the rightmost bits
result = result + bitval -- set the current bit
end
bitval = bitval * 2 -- shift left
a = math.floor(a/2) -- shift right
b = math.floor(b/2)
end
return result
end
local function Config_Send(page, line, value)
local i
i = (page*16) + line
multiBuffer( 5, i )
for i = 1 , 6 , 1 do
multiBuffer( 5+i, value[i] )
end
multiBuffer( 4, 1 )
end
local function Config_Release()
Module.protocol = InitialProtocol
model.setModule(0, Module)
local i
for i = 3 , 0 , -1 do
multiBuffer( i, 0 )
end
end
local function Config_Page( )
Config_Send(Page, 0, { 0, 0, 0, 0, 0, 0 })
end
local function Config_Draw_Edit( event )
local i
local text
if Menu[Focus].field_type == 0xD0 then
-- Editable Hex value
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 1
Blink = 0
for i = 1, Menu[Focus].field_len, 1 do
Menu_value[i] = Menu[Focus].field_value[i]
end
end
if Edit == 0 then
-- Not editing value
if event == EVT_VIRTUAL_ENTER then
if Edit_pos > Menu[Focus].field_len then
-- Save or Cancel
Edit = -1
if Edit_pos == Menu[Focus].field_len + 1 then
-- Save
Config_Send(Page, Focus, Menu_value)
end
return
else
-- Switch to edit mode
Edit = 1
end
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Move cursor
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < Menu[Focus].field_len + 2 then
-- Move cursor
Edit_pos = Edit_pos + 1
end
else
-- Editing value
if event == EVT_VIRTUAL_ENTER then
-- End edit
Edit = 0
elseif event == EVT_VIRTUAL_PREV then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] - 1
elseif event == EVT_VIRTUAL_NEXT then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] + 1
end
--Blink
Blink = Blink + 1
if Blink > 30 then
Blink = 0
end
end
--Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
for i = 1, Menu[Focus].field_len, 1 do
if i==Edit_pos and (Edit ~= 1 or Blink > 15) then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170+12*2*(i-1), 110, string.format('%02X', Menu_value[i]), attrib)
else
lcd.drawText(17+6*2*(i-1), 10, string.format('%02X', Menu_value[i]), attrib + SMLSIZE)
end
end
if Edit_pos == Menu[Focus].field_len + 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Save", attrib)
else
lcd.drawText(17, 30, "Save", attrib + SMLSIZE)
end
if Edit_pos == Menu[Focus].field_len + 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "Cancel", attrib)
else
lcd.drawText(77, 30, "Cancel", attrib + SMLSIZE)
end
elseif Menu[Focus].field_type == 0x90 then
-- Action text
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 2
end
if event == EVT_VIRTUAL_ENTER then
-- Exit
Edit = -1
if Edit_pos == 1 then
-- Yes
Config_Send(Page, Focus, { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA } )
end
return
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Switch to Yes
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < 2 then
-- Switch to No
Edit_pos = Edit_pos + 1
end
-- Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
if LCD_W == 480 then
lcd.drawText(170, 110, Menu[Focus].field_text .. "?")
else
lcd.drawText(17, 10, Menu[Focus].field_text .. "?", SMLSIZE)
end
if Edit_pos == 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Yes", attrib)
else
lcd.drawText(17, 30, "Yes", attrib + SMLSIZE)
end
if Edit_pos == 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "No", attrib)
else
lcd.drawText(77, 30, "No", attrib)
end
end
end
local function Config_Next_Prev( event )
-- Next Prev on main menu
local line
if event == EVT_VIRTUAL_PREV then
for line = Focus - 1, 1, -1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
elseif event == EVT_VIRTUAL_NEXT then
for line = Focus + 1, 7, 1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
end
end
local function Config_Draw_Menu()
-- Main menu
local i
local value
local line
local length
local text
lcd.clear()
if LCD_W == 480 then
--Draw title
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, "Multi Config " .. Version, MENU_TITLE_COLOR)
if multiBuffer(13) == 0x00 then
lcd.drawText(10,50,"No Config telemetry...", BLINK)
end
else
--Draw on LCD_W=128
lcd.drawText(1, 0, "Multi Config " .. Version, SMLSIZE)
if multiBuffer(13) == 0x00 then
lcd.drawText(2,17,"No Config telemetry...",SMLSIZE)
end
end
if multiBuffer(13) ~= 0x00 then
if LCD_W == 480 then
--Draw firmware version and channels order
local ch_order = multiBuffer(17)
local channel_names = {}
channel_names[bitand(ch_order,3)+1] = "A"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "E"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "T"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "R"
lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16), MENU_TITLE_COLOR)
--lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16) .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4], MENU_TITLE_COLOR)
else
lcd.drawText(76, 0, "/Fw" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16),SMLSIZE) -- .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4])
end
--Draw Menu
for line = 1, 7, 1 do
--Clear line info
Menu[line].text = ""
Menu[line].field_type = 0
Menu[line].field_len = 0
for i = 1, 7, 1 do
Menu[line].field_value[i] = 0
end
Menu[line].field_text = ""
length = 0
--Read line from buffer
for i = 0, 20-1, 1 do
value=multiBuffer( line*20+13+i )
if value == 0 then
break -- end of line
end
if value > 0x80 and Menu[line].field_type == 0 then
-- Read field type
Menu[line].field_type = bitand(value, 0xF0)
Menu[line].field_len = bitand(value, 0x0F)
length = Menu[line].field_len
if Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 and Focus == -1 then
-- First actionnable field if nothing was selected
Focus = line;
end
else
if Menu[line].field_type == 0 then
-- Text
Menu[line].text = Menu[line].text .. string.char(value)
else
-- Menu specific fields
length = length - 1
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
Menu[line].field_text = Menu[line].field_text .. string.char(value)
else
Menu[line].field_value[Menu[line].field_len-length] = value
end
if length == 0 then
-- End of fields
break
end
end
end
end
-- Display menu text
if Menu[line].text ~= "" then
if Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 or Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
Menu[line].text = Menu[line].text .. ":"
end
if LCD_W == 480 then
lcd.drawText(10,32+20*line,Menu[line].text )
else
lcd.drawText(2,1+8*line,Menu[line].text,SMLSIZE)
end
end
-- Display specific fields
if line == Focus then
attrib = INVERS
else
attrib = 0
end
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
-- Text
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, Menu[line].field_text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, Menu[line].field_text, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 then
-- Decimal value
value = 0
for i = 1, Menu[line].field_len, 1 do
value = value*256 + value
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, value, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, value, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
-- Hex value
text=""
for i = 1, Menu[line].field_len, 1 do
text = text .. string.format('%02X ', Menu[line].field_value[i])
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, text, SMLSIZE + attrib)
end
end
end
end
end
-- Init
local function Config_Init()
--get Module settings and set to config
Module = model.getModule(0)
InitialProtocol = Module.protocol
Module.protocol = 86
model.setModule(0, Module)
for i = 0, 10, 1 do end
--Set protocol to talk to
multiBuffer( 0, string.byte('C') )
--test if value has been written
if multiBuffer( 0 ) ~= string.byte('C') then
error("Not enough memory!")
return 2
end
--Request init of the buffer
multiBuffer( 4, 0xFF )
--Continue buffer init
multiBuffer( 1, string.byte('o') )
multiBuffer( 2, string.byte('n') )
multiBuffer( 3, string.byte('f') )
-- Test set
-- multiBuffer( 12, 0 )
-- multiBuffer( 13, 1 )
-- multiBuffer( 14, 3 )
-- multiBuffer( 15, 2 )
-- multiBuffer( 16, 62 )
-- multiBuffer( 17, 0 + 1*4 + 2*16 + 3*64)
-- multiBuffer( 33, string.byte('G') )
-- multiBuffer( 34, string.byte('l') )
-- multiBuffer( 35, string.byte('o') )
-- multiBuffer( 36, string.byte('b') )
-- multiBuffer( 37, string.byte('a') )
-- multiBuffer( 38, string.byte('l') )
-- multiBuffer( 39, string.byte(' ') )
-- multiBuffer( 40, string.byte('I') )
-- multiBuffer( 41, string.byte('D') )
-- multiBuffer( 42, 0xD0 + 4 )
-- multiBuffer( 43, 0x12 )
-- multiBuffer( 44, 0x34 )
-- multiBuffer( 45, 0x56 )
-- multiBuffer( 46, 0x78 )
-- multiBuffer( 47, 0x9A )
-- multiBuffer( 48, 0xBC )
-- multiBuffer( 53, 0x90 + 9 )
-- multiBuffer( 54, string.byte('R') )
-- multiBuffer( 55, string.byte('e') )
-- multiBuffer( 56, string.byte('s') )
-- multiBuffer( 57, string.byte('e') )
-- multiBuffer( 58, string.byte('t') )
-- multiBuffer( 59, string.byte(' ') )
-- multiBuffer( 60, string.byte('G') )
-- multiBuffer( 61, string.byte('I') )
-- multiBuffer( 62, string.byte('D') )
-- multiBuffer( 63, 0x00 )
end
-- Main
local function Config_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
Config_Release()
return 2
else
Config_Draw_Menu()
if ( event == EVT_VIRTUAL_PREV_PAGE or event == EVT_VIRTUAL_NEXT_PAGE ) and Edit < 1 then
-- Not editing, ok to change page
if event == EVT_VIRTUAL_PREV_PAGE then
killEvents(event)
if Page > 0 then
--Page = Page - 1
--Config_Page()
end
else
--Page = Page + 1
--Config_Page()
end
end
if Focus > 0 then
-- At least one line has an action
if Edit >= 0 then
-- Currently editing
Config_Draw_Edit( event )
elseif event == EVT_VIRTUAL_ENTER then
-- Switch to edit
Config_Draw_Edit( 0 )
elseif event == EVT_VIRTUAL_PREV or event == EVT_VIRTUAL_NEXT then
-- Main menu selection
Config_Next_Prev( event )
end
end
return 0
end
end
return { init=Config_Init, run=Config_Run }

View file

@ -6,6 +6,7 @@
14,4,Bayang,DHD_D4,1,Flip,RTH,Pict,Video,HLess,Invert,Rates,TakeOf,EmStop
14,5,Bayang,QX100,1,Flip,RTH,Pict,Video,HLess,Invert,Rates,TakeOf,EmStop
59,0,BayangRX,RX,1,AnAux1,AnAux2,Flip,RTH,Pict,Video
59,1,BayangRX,CPPM,1,AnAux1,AnAux2,Flip,RTH,Pict,Video
41,0,Bugs,3-6-8,0,Arm,Angle,Flip,Pict,Video,LED
42,0,BugsMini,Mini,0,Arm,Angle,Flip,Pict,Video,LED
42,1,BugsMini,3H,0,Arm,Angle,Flip,Pict,Video,LED,AltHol
@ -34,9 +35,9 @@
6,3,DSM,X_11,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,n-a,ThKill
6,4,DSM,AUTO,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,n-a,ThKill
70,0,DSM_RX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
70,1,DSM_RX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
45,0,E01X,E012,1,n-a,Flip,n-a,HLess,RTH
45,1,E01X,E015,1,Arm,Flip,LED,HLess,RTH
45,2,E01X,E016H,1,Stop,Flip,n-a,HLess,RTH
16,0,ESKY,Std,0,Gyro,Pitch
16,1,ESKY,ET4,0,Gyro,Pitch
35,0,ESKY150,4CH,0
@ -54,6 +55,7 @@
28,4,Flysky_AFHDS2A,PWM_IB16,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
28,5,Flysky_AFHDS2A,PPM_IB16,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
56,0,Flysky2A_RX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14
56,1,Flysky2A_RX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14
53,0,Height,5ch,0,Gear
53,1,Height,8ch,0,Gear,Gyro,Flap,Light
25,0,FrSkyV,V8,0,CH5,CH6,CH7,CH8
@ -79,6 +81,8 @@
65,3,FrSkyR9,R9_968_8CH,0,CH5,CH6,CH7,CH8
55,0,FrSkyRX,RX,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
55,1,FrSkyRX,CloneTX,0
55,2,FrSkyRX,EraseTX,0
55,3,FrSkyRX,CPPM,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
58,0,FX816,P38,1
20,0,FY326,FY326,1,Flip,RTH,HLess,Expert,Calib
20,1,FY326,FY319,1,Flip,RTH,HLess,Expert,Calib
@ -99,13 +103,14 @@
26,1,Hontai,JJRCX1,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
26,2,Hontai,X5C1,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
26,3,Hontai,FQ777_951,1,Flip,Arm,Pict,Video,HLess,RTH,Calib
57,0,HoTT,Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
57,1,HoTT,No_Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
57,0,HoTT,Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
57,1,HoTT,No_Sync,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
2,0,Hubsan,H107,1,Flip,Light,Pict,Video,HLess
2,1,Hubsan,H301,0,RTH,Light,Stab,Video
2,2,Hubsan,H501,0,RTH,Light,Pict,Video,HLess,GPS_H,ALT_H,Flip,FModes
22,0,J6Pro,Std,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12
71,0,JJRC345,Std,1,Flip,HLess,RTH
71,0,JJRC345,JJRC345,1,Flip,HLess,RTH,LED,UNK1,UNK2,UNK3
71,1,JJRC345,SkyTmblr,1,Flip,HLess,RTH,LED,UNK1,UNK2,UNK3
49,0,KF606,Std,1,Trim
9,0,KN,WLToys,0,DRate,THold,IdleUp,Gyro,Ttrim,Atrim,Etrim
9,1,KN,Feilun,0,DRate,THold,IdleUp,Gyro,Ttrim,Atrim,Etrim
@ -122,6 +127,8 @@
17,2,MT99XX,YZ,1,Flip,LED,Pict,Video,HLess
17,3,MT99XX,LS,1,Flip,Invert,Pict,Video,HLess
17,4,MT99XX,FY805,1,Flip,n-a,n-a,n-a,HLess
17,5,MT99XX,A180,0,3D_6G
17,6,MT99XX,Dragon,0,Mode,RTH
44,0,NCC1701,Std,1,Warp
77,0,OMP,M2,0,THold,IdleUp,6G_3D
60,0,Pelikan,PRO_V4,0,CH5,CH6,CH7,CH8
@ -138,10 +145,11 @@
72,0,Q90C,Std,0,FMode,VTX+
74,0,RadioLink,Surface,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
74,1,RadioLink,Air,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
74,2,RadioLink,DumboRC,0,CH5,CH6,CH7,CH8,FS_CH1,FS_CH2,FS_CH3,FS_CH4,FS_CH5,FS_CH6,FS_CH7,FS_CH8
76,0,Realacc,R11,1,Flip,Light,Calib,HLess,RTH,UNK
50,0,Redpine,Fast,0,sCH5,sCH6,sCH7,sCH8,sCH9,sCH10,sCH11,sCH12,sCH13,sCH14,sCH15,sCH16
50,1,Redpine,Slow,0,sCH5,sCH6,sCH7,sCH8,sCH9,sCH10,sCH11,sCH12,sCH13,sCH14,sCH15,sCH16
21,0,SFHSS,Std,0,CH5,CH6,CH7,CH8
21,0,Futaba,SFHSS,0,CH5,CH6,CH7,CH8
19,0,Shenqi,Cycle,1
68,0,Skyartec,Std,0,CH5,CH6,CH7
11,0,SLT,V1,0,Gear,Pitch
@ -174,3 +182,11 @@
8,3,YD717,XinXun,1,Flip,Light,Pict,Video,HLess
8,4,YD717,NiHui,1,Flip,Light,Pict,Video,HLess
52,0,ZSX,280,1,Light
78,0,M-Link,Std,0,CH5,CH6,CH7,CH8,CH9,CH10,CH11,CH12,CH13,CH14,CH15,CH16
79,0,WFLY2,RF20x,0,CH5,CH6,CH7,CH8,CH9,CH10
80,0,E016Hv2,E016Hv2,1,TakLan,EmStop,Flip,Calib,HLess,RTH
81,0,E010r5,E010r5,1,Flip,LED,CALIB,HLess,RTH,GLIDE
82,0,LOLI,Std,0,CH5,CH6,CH7,CH8,1SwSePpPw,2SwSePw,3SwSe,4SwSe,5SwSeSb,6SwSe,7SwSePw,8SwSe
83,0,E129,E129,1,TakLan,EmStop,TrimA,TrimE,TrimR
84,0,JOYSWAY,Std,0
85,0,E016H,Std,1,Stop,Flip,n-a,HLess,RTH

View file

@ -0,0 +1,221 @@
local toolName = "TNS|Multi LOLI RX config|TNE"
---- #########################################################################
---- # #
---- # 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 loli_nok = false
local channels={ { 768, "PWM", 100, 102, "PPM", 50, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH1
{ 768, "PWM", 100, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH2
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH3
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH4
{ 102, "SBUS", 50, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH5
{ -768, "Servo", 0, -2048, "Switch", -100 }, -- CH6
{ 768, "PWM", 100, -768, "Servo", 0, -2048, "Switch", -100 }, -- CH7
{ -768, "Servo", 0, -2048, "Switch", -100 } } -- CH8
local sel = 1
local edit = false
local blink = 0
local BLINK_SPEED = 15
local function drawScreenTitle(title)
if LCD_W == 480 then
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, title, MENU_TITLE_COLOR)
else
lcd.drawScreenTitle(title, 0, 0)
end
end
local function LOLI_Draw_LCD(event)
local line = 0
lcd.clear()
--Display settings
local lcd_opt = 0
if LCD_W == 480 then
drawScreenTitle("Multi - LOLI RX configuration tool")
x_pos = 152
x_inc = 90
y_pos = 40
y_inc = 20
else
x_pos = 5
x_inc = 30
y_pos = 1
y_inc = 8
lcd_opt = SMLSIZE
end
--Multi Module detection
if loli_nok then
if LCD_W == 480 then
lcd.drawText(10,50,"The LOLI protocol is not selected...", lcd_opt)
else
--Draw on LCD_W=128
lcd.drawText(2,17,"LOLI protocol not selected...",SMLSIZE)
end
return
end
--Display current config
if LCD_W == 480 then
line = line + 1
lcd.drawText(x_pos, y_pos+y_inc*line -2, "Channel", lcd_opt)
lcd.drawText(x_pos+x_inc, y_pos+y_inc*line -2, "Function", lcd_opt)
lcd.drawRectangle(x_pos-4, y_pos+y_inc*line -4 , 2*x_inc +2, 188)
lcd.drawLine(x_pos-4, y_pos+y_inc*line +18, x_pos-4 +2*x_inc +1, y_pos+y_inc*line +18, SOLID, 0)
lcd.drawLine(x_pos+x_inc -5, y_pos+y_inc*line -4, x_pos+x_inc -5, y_pos+y_inc*line -5 +188, SOLID, 0)
line = line + 1
end
local out
for i = 1, 8 do
out = getValue("ch"..(i+8))
lcd.drawText(x_pos, y_pos+y_inc*line, "CH"..i, lcd_opt)
for j = 1, #channels[i], 3 do
if out > channels[i][j] then
if sel == i then
invert = INVERS
if edit == true then
blink = blink + 1
if blink > BLINK_SPEED then
invert = 0
if blink > BLINK_SPEED * 2 then
blink = 0
end
end
end
else
invert = 0
end
lcd.drawText(x_pos+x_inc, y_pos+y_inc*line, channels[i][j+1], lcd_opt + invert)
break
end
end
line = line + 1
end
end
local function LOLI_Change_Value(dir)
local pos = 0
local out
--look for the current position
out = getValue("ch"..(sel+8))
for j = 1, #channels[sel], 3 do
if out > channels[sel][j] then
pos = j
break
end
end
--decrement or increment
if dir < 0 and pos > 1 then
pos = pos - 3
elseif dir > 0 and pos + 3 < #channels[sel] then
pos = pos + 3
else
return
end
--delete all mixers for the selected channel
local num_mix = model.getMixesCount(sel-1 +8)
for i = 1, num_mix do
model.deleteMix(sel-1 +8, 0);
end
--create new mixer
local source_max = getFieldInfo("cyc1")
local val = { name = channels[sel][pos+1],
source = source_max.id - 1, -- MAX=100 on TX16S
weight = channels[sel][pos+2],
offset = 0,
switch = 0,
multiplex = 0,
curveType = 0,
curveValue = 0,
flightModes = 0,
carryTrim = false,
mixWarn = 0,
delayUp = 0,
delayDown = 0,
speedUp = 0,
speedDown = 0 }
model.insertMix(sel-1 +8, 0, val)
end
local function LOLI_Menu(event)
if event == EVT_VIRTUAL_NEXT then
if edit == false then
-- not changing a value
if sel < 8 then
sel = sel + 1
end
else
-- need to inc the value
LOLI_Change_Value(1)
end
elseif event == EVT_VIRTUAL_PREV then
if edit == false then
-- not changing a value
if sel > 1 then
sel = sel - 1
end
else
-- need to dec the value
LOLI_Change_Value(-1)
end
elseif event == EVT_VIRTUAL_ENTER then
if edit == false then
edit = true
blink = BLINK_SPEED
else
edit = false
end
end
end
-- Init
local function LOLI_Init()
local module_conf = model.getModule(0)
if module_conf["Type"] ~= 6 or module_conf["protocol"] ~= 82 then
module_conf = model.getModule(1)
if module_conf["Type"] ~= 6 or module_conf["protocol"] ~= 82 then
loli_nok = true
end
end
end
-- Main
local function LOLI_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
return 2
else
LOLI_Menu(event)
LOLI_Draw_LCD(event)
return 0
end
end
return { init=LOLI_Init, run=LOLI_Run }

View file

@ -0,0 +1,499 @@
---- #########################################################################
---- # #
---- # 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. #
---- # #
---- #########################################################################
--###############################################################################
-- Multi buffer for Config description
-- To start operation:
-- Write 0xFF at address 4 will request the buffer to be cleared
-- Write "Conf" at address 0..3
-- Read
-- Read at address 12 gives the current config page
-- Read at address 13..172 gives the current data of the page = 8 lines * 20 caracters
-- Write
-- Write at address 5..11 the command
-- Write 0x01 at address 4 will send the command to the module
-- !! Before exiting the script must write 0 at address 0 for normal operation !!
--###############################################################################
local Version = "v0.1"
local Focus = -1
local Page = 0
local Edit = -1
local Edit_pos = 1
local Menu = { {text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""} }
local Menu_value = {}
local Blink = 0
local Module = {}
local InitialProtocol = 0
function bitand(a, b)
local result = 0
local bitval = 1
while a > 0 and b > 0 do
if a % 2 == 1 and b % 2 == 1 then -- test the rightmost bits
result = result + bitval -- set the current bit
end
bitval = bitval * 2 -- shift left
a = math.floor(a/2) -- shift right
b = math.floor(b/2)
end
return result
end
local function Config_Send(page, line, value)
local i
i = (page*16) + line
multiBuffer( 5, i )
for i = 1 , 6 , 1 do
multiBuffer( 5+i, value[i] )
end
multiBuffer( 4, 1 )
end
local function Config_Release()
Module.protocol = InitialProtocol
model.setModule(1, Module)
local i
for i = 3 , 0 , -1 do
multiBuffer( i, 0 )
end
end
local function Config_Page( )
Config_Send(Page, 0, { 0, 0, 0, 0, 0, 0 })
end
local function Config_Draw_Edit( event )
local i
local text
if Menu[Focus].field_type == 0xD0 then
-- Editable Hex value
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 1
Blink = 0
for i = 1, Menu[Focus].field_len, 1 do
Menu_value[i] = Menu[Focus].field_value[i]
end
end
if Edit == 0 then
-- Not editing value
if event == EVT_VIRTUAL_ENTER then
if Edit_pos > Menu[Focus].field_len then
-- Save or Cancel
Edit = -1
if Edit_pos == Menu[Focus].field_len + 1 then
-- Save
Config_Send(Page, Focus, Menu_value)
end
return
else
-- Switch to edit mode
Edit = 1
end
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Move cursor
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < Menu[Focus].field_len + 2 then
-- Move cursor
Edit_pos = Edit_pos + 1
end
else
-- Editing value
if event == EVT_VIRTUAL_ENTER then
-- End edit
Edit = 0
elseif event == EVT_VIRTUAL_PREV then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] - 1
elseif event == EVT_VIRTUAL_NEXT then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] + 1
end
--Blink
Blink = Blink + 1
if Blink > 30 then
Blink = 0
end
end
--Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
for i = 1, Menu[Focus].field_len, 1 do
if i==Edit_pos and (Edit ~= 1 or Blink > 15) then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170+12*2*(i-1), 110, string.format('%02X', Menu_value[i]), attrib)
else
lcd.drawText(17+6*2*(i-1), 10, string.format('%02X', Menu_value[i]), attrib + SMLSIZE)
end
end
if Edit_pos == Menu[Focus].field_len + 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Save", attrib)
else
lcd.drawText(17, 30, "Save", attrib + SMLSIZE)
end
if Edit_pos == Menu[Focus].field_len + 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "Cancel", attrib)
else
lcd.drawText(77, 30, "Cancel", attrib + SMLSIZE)
end
elseif Menu[Focus].field_type == 0x90 then
-- Action text
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 2
end
if event == EVT_VIRTUAL_ENTER then
-- Exit
Edit = -1
if Edit_pos == 1 then
-- Yes
Config_Send(Page, Focus, { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA } )
end
return
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Switch to Yes
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < 2 then
-- Switch to No
Edit_pos = Edit_pos + 1
end
-- Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
if LCD_W == 480 then
lcd.drawText(170, 110, Menu[Focus].field_text .. "?")
else
lcd.drawText(17, 10, Menu[Focus].field_text .. "?", SMLSIZE)
end
if Edit_pos == 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Yes", attrib)
else
lcd.drawText(17, 30, "Yes", attrib + SMLSIZE)
end
if Edit_pos == 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "No", attrib)
else
lcd.drawText(77, 30, "No", attrib)
end
end
end
local function Config_Next_Prev( event )
-- Next Prev on main menu
local line
if event == EVT_VIRTUAL_PREV then
for line = Focus - 1, 1, -1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
elseif event == EVT_VIRTUAL_NEXT then
for line = Focus + 1, 7, 1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
end
end
local function Config_Draw_Menu()
-- Main menu
local i
local value
local line
local length
local text
lcd.clear()
if LCD_W == 480 then
--Draw title
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, "Multi Config " .. Version, MENU_TITLE_COLOR)
if multiBuffer(13) == 0x00 then
lcd.drawText(10,50,"No Config telemetry...", BLINK)
end
else
--Draw on LCD_W=128
lcd.drawText(1, 0, "Multi Config " .. Version, SMLSIZE)
if multiBuffer(13) == 0x00 then
lcd.drawText(2,17,"No Config telemetry...",SMLSIZE)
end
end
if multiBuffer(13) ~= 0x00 then
if LCD_W == 480 then
--Draw firmware version and channels order
local ch_order = multiBuffer(17)
local channel_names = {}
channel_names[bitand(ch_order,3)+1] = "A"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "E"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "T"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "R"
lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16), MENU_TITLE_COLOR)
--lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16) .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4], MENU_TITLE_COLOR)
else
lcd.drawText(76, 0, "/Fw" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16),SMLSIZE) -- .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4])
end
--Draw Menu
for line = 1, 7, 1 do
--Clear line info
Menu[line].text = ""
Menu[line].field_type = 0
Menu[line].field_len = 0
for i = 1, 7, 1 do
Menu[line].field_value[i] = 0
end
Menu[line].field_text = ""
length = 0
--Read line from buffer
for i = 0, 20-1, 1 do
value=multiBuffer( line*20+13+i )
if value == 0 then
break -- end of line
end
if value > 0x80 and Menu[line].field_type == 0 then
-- Read field type
Menu[line].field_type = bitand(value, 0xF0)
Menu[line].field_len = bitand(value, 0x0F)
length = Menu[line].field_len
if Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 and Focus == -1 then
-- First actionnable field if nothing was selected
Focus = line;
end
else
if Menu[line].field_type == 0 then
-- Text
Menu[line].text = Menu[line].text .. string.char(value)
else
-- Menu specific fields
length = length - 1
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
Menu[line].field_text = Menu[line].field_text .. string.char(value)
else
Menu[line].field_value[Menu[line].field_len-length] = value
end
if length == 0 then
-- End of fields
break
end
end
end
end
-- Display menu text
if Menu[line].text ~= "" then
if Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 or Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
Menu[line].text = Menu[line].text .. ":"
end
if LCD_W == 480 then
lcd.drawText(10,32+20*line,Menu[line].text )
else
lcd.drawText(2,1+8*line,Menu[line].text,SMLSIZE)
end
end
-- Display specific fields
if line == Focus then
attrib = INVERS
else
attrib = 0
end
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
-- Text
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, Menu[line].field_text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, Menu[line].field_text, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 then
-- Decimal value
value = 0
for i = 1, Menu[line].field_len, 1 do
value = value*256 + value
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, value, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, value, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
-- Hex value
text=""
for i = 1, Menu[line].field_len, 1 do
text = text .. string.format('%02X ', Menu[line].field_value[i])
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, text, SMLSIZE + attrib)
end
end
end
end
end
-- Init
local function Config_Init()
--get Module settings and set to config
Module = model.getModule(1)
InitialProtocol = Module.protocol
Module.protocol = 86
model.setModule(1, Module)
for i = 0, 10, 1 do end
--Set protocol to talk to
multiBuffer( 0, string.byte('C') )
--test if value has been written
if multiBuffer( 0 ) ~= string.byte('C') then
error("Not enough memory!")
return 2
end
--Request init of the buffer
multiBuffer( 4, 0xFF )
--Continue buffer init
multiBuffer( 1, string.byte('o') )
multiBuffer( 2, string.byte('n') )
multiBuffer( 3, string.byte('f') )
-- Test set
-- multiBuffer( 12, 0 )
-- multiBuffer( 13, 1 )
-- multiBuffer( 14, 3 )
-- multiBuffer( 15, 2 )
-- multiBuffer( 16, 62 )
-- multiBuffer( 17, 0 + 1*4 + 2*16 + 3*64)
-- multiBuffer( 33, string.byte('G') )
-- multiBuffer( 34, string.byte('l') )
-- multiBuffer( 35, string.byte('o') )
-- multiBuffer( 36, string.byte('b') )
-- multiBuffer( 37, string.byte('a') )
-- multiBuffer( 38, string.byte('l') )
-- multiBuffer( 39, string.byte(' ') )
-- multiBuffer( 40, string.byte('I') )
-- multiBuffer( 41, string.byte('D') )
-- multiBuffer( 42, 0xD0 + 4 )
-- multiBuffer( 43, 0x12 )
-- multiBuffer( 44, 0x34 )
-- multiBuffer( 45, 0x56 )
-- multiBuffer( 46, 0x78 )
-- multiBuffer( 47, 0x9A )
-- multiBuffer( 48, 0xBC )
-- multiBuffer( 53, 0x90 + 9 )
-- multiBuffer( 54, string.byte('R') )
-- multiBuffer( 55, string.byte('e') )
-- multiBuffer( 56, string.byte('s') )
-- multiBuffer( 57, string.byte('e') )
-- multiBuffer( 58, string.byte('t') )
-- multiBuffer( 59, string.byte(' ') )
-- multiBuffer( 60, string.byte('G') )
-- multiBuffer( 61, string.byte('I') )
-- multiBuffer( 62, string.byte('D') )
-- multiBuffer( 63, 0x00 )
end
-- Main
local function Config_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
Config_Release()
return 2
else
Config_Draw_Menu()
if ( event == EVT_VIRTUAL_PREV_PAGE or event == EVT_VIRTUAL_NEXT_PAGE ) and Edit < 1 then
-- Not editing, ok to change page
if event == EVT_VIRTUAL_PREV_PAGE then
killEvents(event)
if Page > 0 then
--Page = Page - 1
--Config_Page()
end
else
--Page = Page + 1
--Config_Page()
end
end
if Focus > 0 then
-- At least one line has an action
if Edit >= 0 then
-- Currently editing
Config_Draw_Edit( event )
elseif event == EVT_VIRTUAL_ENTER then
-- Switch to edit
Config_Draw_Edit( 0 )
elseif event == EVT_VIRTUAL_PREV or event == EVT_VIRTUAL_NEXT then
-- Main menu selection
Config_Next_Prev( event )
end
end
return 0
end
end
return { init=Config_Init, run=Config_Run }

View file

@ -0,0 +1,499 @@
---- #########################################################################
---- # #
---- # 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. #
---- # #
---- #########################################################################
--###############################################################################
-- Multi buffer for Config description
-- To start operation:
-- Write 0xFF at address 4 will request the buffer to be cleared
-- Write "Conf" at address 0..3
-- Read
-- Read at address 12 gives the current config page
-- Read at address 13..172 gives the current data of the page = 8 lines * 20 caracters
-- Write
-- Write at address 5..11 the command
-- Write 0x01 at address 4 will send the command to the module
-- !! Before exiting the script must write 0 at address 0 for normal operation !!
--###############################################################################
local Version = "v0.1"
local Focus = -1
local Page = 0
local Edit = -1
local Edit_pos = 1
local Menu = { {text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""},
{text = "", field_type = 0, field_len = 0, field_value = {}, field_text = ""} }
local Menu_value = {}
local Blink = 0
local Module = {}
local InitialProtocol = 0
function bitand(a, b)
local result = 0
local bitval = 1
while a > 0 and b > 0 do
if a % 2 == 1 and b % 2 == 1 then -- test the rightmost bits
result = result + bitval -- set the current bit
end
bitval = bitval * 2 -- shift left
a = math.floor(a/2) -- shift right
b = math.floor(b/2)
end
return result
end
local function Config_Send(page, line, value)
local i
i = (page*16) + line
multiBuffer( 5, i )
for i = 1 , 6 , 1 do
multiBuffer( 5+i, value[i] )
end
multiBuffer( 4, 1 )
end
local function Config_Release()
Module.protocol = InitialProtocol
model.setModule(0, Module)
local i
for i = 3 , 0 , -1 do
multiBuffer( i, 0 )
end
end
local function Config_Page( )
Config_Send(Page, 0, { 0, 0, 0, 0, 0, 0 })
end
local function Config_Draw_Edit( event )
local i
local text
if Menu[Focus].field_type == 0xD0 then
-- Editable Hex value
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 1
Blink = 0
for i = 1, Menu[Focus].field_len, 1 do
Menu_value[i] = Menu[Focus].field_value[i]
end
end
if Edit == 0 then
-- Not editing value
if event == EVT_VIRTUAL_ENTER then
if Edit_pos > Menu[Focus].field_len then
-- Save or Cancel
Edit = -1
if Edit_pos == Menu[Focus].field_len + 1 then
-- Save
Config_Send(Page, Focus, Menu_value)
end
return
else
-- Switch to edit mode
Edit = 1
end
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Move cursor
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < Menu[Focus].field_len + 2 then
-- Move cursor
Edit_pos = Edit_pos + 1
end
else
-- Editing value
if event == EVT_VIRTUAL_ENTER then
-- End edit
Edit = 0
elseif event == EVT_VIRTUAL_PREV then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] - 1
elseif event == EVT_VIRTUAL_NEXT then
-- Change value
Menu_value[Edit_pos] = Menu_value[Edit_pos] + 1
end
--Blink
Blink = Blink + 1
if Blink > 30 then
Blink = 0
end
end
--Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
for i = 1, Menu[Focus].field_len, 1 do
if i==Edit_pos and (Edit ~= 1 or Blink > 15) then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170+12*2*(i-1), 110, string.format('%02X', Menu_value[i]), attrib)
else
lcd.drawText(17+6*2*(i-1), 10, string.format('%02X', Menu_value[i]), attrib + SMLSIZE)
end
end
if Edit_pos == Menu[Focus].field_len + 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Save", attrib)
else
lcd.drawText(17, 30, "Save", attrib + SMLSIZE)
end
if Edit_pos == Menu[Focus].field_len + 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "Cancel", attrib)
else
lcd.drawText(77, 30, "Cancel", attrib + SMLSIZE)
end
elseif Menu[Focus].field_type == 0x90 then
-- Action text
if Edit == -1 then
-- Init
Edit = 0
Edit_pos = 2
end
if event == EVT_VIRTUAL_ENTER then
-- Exit
Edit = -1
if Edit_pos == 1 then
-- Yes
Config_Send(Page, Focus, { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA } )
end
return
elseif event == EVT_VIRTUAL_PREV and Edit_pos > 1 then
-- Switch to Yes
Edit_pos = Edit_pos - 1
elseif event == EVT_VIRTUAL_NEXT and Edit_pos < 2 then
-- Switch to No
Edit_pos = Edit_pos + 1
end
-- Display
if LCD_W == 480 then
lcd.drawRectangle(160-1, 100-1, 160+2, 55+2, TEXT_COLOR)
lcd.drawFilledRectangle(160, 100, 160, 55, TEXT_BGCOLOR)
else
lcd.clear()
end
if LCD_W == 480 then
lcd.drawText(170, 110, Menu[Focus].field_text .. "?")
else
lcd.drawText(17, 10, Menu[Focus].field_text .. "?", SMLSIZE)
end
if Edit_pos == 1 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(170, 130, "Yes", attrib)
else
lcd.drawText(17, 30, "Yes", attrib + SMLSIZE)
end
if Edit_pos == 2 then
attrib = INVERS
else
attrib = 0
end
if LCD_W == 480 then
lcd.drawText(260, 130, "No", attrib)
else
lcd.drawText(77, 30, "No", attrib)
end
end
end
local function Config_Next_Prev( event )
-- Next Prev on main menu
local line
if event == EVT_VIRTUAL_PREV then
for line = Focus - 1, 1, -1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
elseif event == EVT_VIRTUAL_NEXT then
for line = Focus + 1, 7, 1 do
if Menu[line].field_type >= 0x80 and Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 then
Focus = line
break
end
end
end
end
local function Config_Draw_Menu()
-- Main menu
local i
local value
local line
local length
local text
lcd.clear()
if LCD_W == 480 then
--Draw title
lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR)
lcd.drawText(1, 5, "Multi Config " .. Version, MENU_TITLE_COLOR)
if multiBuffer(13) == 0x00 then
lcd.drawText(10,50,"No Config telemetry...", BLINK)
end
else
--Draw on LCD_W=128
lcd.drawText(1, 0, "Multi Config " .. Version, SMLSIZE)
if multiBuffer(13) == 0x00 then
lcd.drawText(2,17,"No Config telemetry...",SMLSIZE)
end
end
if multiBuffer(13) ~= 0x00 then
if LCD_W == 480 then
--Draw firmware version and channels order
local ch_order = multiBuffer(17)
local channel_names = {}
channel_names[bitand(ch_order,3)+1] = "A"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "E"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "T"
ch_order = math.floor(ch_order/4)
channel_names[bitand(ch_order,3)+1] = "R"
lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16), MENU_TITLE_COLOR)
--lcd.drawText(150, 5, "Firmware v" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16) .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4], MENU_TITLE_COLOR)
else
lcd.drawText(76, 0, "/Fw" .. multiBuffer(13) .. "." .. multiBuffer(14) .. "." .. multiBuffer(15) .. "." .. multiBuffer(16),SMLSIZE) -- .. " " .. channel_names[1] .. channel_names[2] .. channel_names[3] .. channel_names[4])
end
--Draw Menu
for line = 1, 7, 1 do
--Clear line info
Menu[line].text = ""
Menu[line].field_type = 0
Menu[line].field_len = 0
for i = 1, 7, 1 do
Menu[line].field_value[i] = 0
end
Menu[line].field_text = ""
length = 0
--Read line from buffer
for i = 0, 20-1, 1 do
value=multiBuffer( line*20+13+i )
if value == 0 then
break -- end of line
end
if value > 0x80 and Menu[line].field_type == 0 then
-- Read field type
Menu[line].field_type = bitand(value, 0xF0)
Menu[line].field_len = bitand(value, 0x0F)
length = Menu[line].field_len
if Menu[line].field_type ~= 0xA0 and Menu[line].field_type ~= 0xC0 and Focus == -1 then
-- First actionnable field if nothing was selected
Focus = line;
end
else
if Menu[line].field_type == 0 then
-- Text
Menu[line].text = Menu[line].text .. string.char(value)
else
-- Menu specific fields
length = length - 1
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
Menu[line].field_text = Menu[line].field_text .. string.char(value)
else
Menu[line].field_value[Menu[line].field_len-length] = value
end
if length == 0 then
-- End of fields
break
end
end
end
end
-- Display menu text
if Menu[line].text ~= "" then
if Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 or Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
Menu[line].text = Menu[line].text .. ":"
end
if LCD_W == 480 then
lcd.drawText(10,32+20*line,Menu[line].text )
else
lcd.drawText(2,1+8*line,Menu[line].text,SMLSIZE)
end
end
-- Display specific fields
if line == Focus then
attrib = INVERS
else
attrib = 0
end
if Menu[line].field_type == 0x80 or Menu[line].field_type == 0x90 then
-- Text
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, Menu[line].field_text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, Menu[line].field_text, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xA0 or Menu[line].field_type == 0xB0 then
-- Decimal value
value = 0
for i = 1, Menu[line].field_len, 1 do
value = value*256 + value
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, value, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, value, SMLSIZE + attrib)
end
elseif Menu[line].field_type == 0xC0 or Menu[line].field_type == 0xD0 then
-- Hex value
text=""
for i = 1, Menu[line].field_len, 1 do
text = text .. string.format('%02X ', Menu[line].field_value[i])
end
if LCD_W == 480 then
lcd.drawText(10+9*#Menu[line].text, 32+20*line, text, attrib)
else
lcd.drawText(2+5*#Menu[line].text, 1+8*line, text, SMLSIZE + attrib)
end
end
end
end
end
-- Init
local function Config_Init()
--get Module settings and set to config
Module = model.getModule(0)
InitialProtocol = Module.protocol
Module.protocol = 86
model.setModule(0, Module)
for i = 0, 10, 1 do end
--Set protocol to talk to
multiBuffer( 0, string.byte('C') )
--test if value has been written
if multiBuffer( 0 ) ~= string.byte('C') then
error("Not enough memory!")
return 2
end
--Request init of the buffer
multiBuffer( 4, 0xFF )
--Continue buffer init
multiBuffer( 1, string.byte('o') )
multiBuffer( 2, string.byte('n') )
multiBuffer( 3, string.byte('f') )
-- Test set
-- multiBuffer( 12, 0 )
-- multiBuffer( 13, 1 )
-- multiBuffer( 14, 3 )
-- multiBuffer( 15, 2 )
-- multiBuffer( 16, 62 )
-- multiBuffer( 17, 0 + 1*4 + 2*16 + 3*64)
-- multiBuffer( 33, string.byte('G') )
-- multiBuffer( 34, string.byte('l') )
-- multiBuffer( 35, string.byte('o') )
-- multiBuffer( 36, string.byte('b') )
-- multiBuffer( 37, string.byte('a') )
-- multiBuffer( 38, string.byte('l') )
-- multiBuffer( 39, string.byte(' ') )
-- multiBuffer( 40, string.byte('I') )
-- multiBuffer( 41, string.byte('D') )
-- multiBuffer( 42, 0xD0 + 4 )
-- multiBuffer( 43, 0x12 )
-- multiBuffer( 44, 0x34 )
-- multiBuffer( 45, 0x56 )
-- multiBuffer( 46, 0x78 )
-- multiBuffer( 47, 0x9A )
-- multiBuffer( 48, 0xBC )
-- multiBuffer( 53, 0x90 + 9 )
-- multiBuffer( 54, string.byte('R') )
-- multiBuffer( 55, string.byte('e') )
-- multiBuffer( 56, string.byte('s') )
-- multiBuffer( 57, string.byte('e') )
-- multiBuffer( 58, string.byte('t') )
-- multiBuffer( 59, string.byte(' ') )
-- multiBuffer( 60, string.byte('G') )
-- multiBuffer( 61, string.byte('I') )
-- multiBuffer( 62, string.byte('D') )
-- multiBuffer( 63, 0x00 )
end
-- Main
local function Config_Run(event)
if event == nil then
error("Cannot be run as a model script!")
return 2
elseif event == EVT_VIRTUAL_EXIT then
Config_Release()
return 2
else
Config_Draw_Menu()
if ( event == EVT_VIRTUAL_PREV_PAGE or event == EVT_VIRTUAL_NEXT_PAGE ) and Edit < 1 then
-- Not editing, ok to change page
if event == EVT_VIRTUAL_PREV_PAGE then
killEvents(event)
if Page > 0 then
--Page = Page - 1
--Config_Page()
end
else
--Page = Page + 1
--Config_Page()
end
end
if Focus > 0 then
-- At least one line has an action
if Edit >= 0 then
-- Currently editing
Config_Draw_Edit( event )
elseif event == EVT_VIRTUAL_ENTER then
-- Switch to edit
Config_Draw_Edit( 0 )
elseif event == EVT_VIRTUAL_PREV or event == EVT_VIRTUAL_NEXT then
-- Main menu selection
Config_Next_Prev( event )
end
end
return 0
end
end
return { init=Config_Init, run=Config_Run }

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

@ -123,7 +123,7 @@ bool menuRadioTools(event_t event)
#elif defined(INTERNAL_MODULE_MULTI)
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
#endif
#if defined(PXX2)|| defined(MULTIMODULE)
#if defined(PXX2) || defined(MULTIMODULE)
if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER) || isModuleMultimodule(EXTERNAL_MODULE))
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_EXT, menuRadioSpectrumAnalyser, EXTERNAL_MODULE);
#endif

View file

@ -120,11 +120,11 @@ Get RF module parameters
* `channelsCount` (number) number of channels sent to module
* `Type` (number) module type
* if the module type is Multi additional information are available
* `protocol` (number) protocol number
* `subProtocol` (number) sub-protocol number
* `channelsOrder` (number) first 4 channels expected order
* `protocol` (number) protocol number (Multi only)
* `subProtocol` (number) sub-protocol number (Multi only)
* `channelsOrder` (number) first 4 channels expected order (Multi only)
@status current Introduced in TODO
@status current Introduced in 2.2.0
*/
static int luaModelGetModule(lua_State *L)
{
@ -174,13 +174,16 @@ Set RF module parameters
@notice If a parameter is missing from the value, then
that parameter remains unchanged.
@status current Introduced in TODO
@status current Introduced in 2.2.0, modified in 2.3.12 (proto/subproto)
*/
static int luaModelSetModule(lua_State *L)
{
unsigned int idx = luaL_checkunsigned(L, 1);
if (idx < NUM_MODULES) {
int protocol = -1;
int subprotocol = -1;
ModuleData & module = g_model.moduleData[idx];
luaL_checktype(L, -1, LUA_TTABLE);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
@ -201,7 +204,22 @@ static int luaModelSetModule(lua_State *L)
else if (!strcmp(key, "channelsCount")) {
module.channelsCount = luaL_checkinteger(L, -1) - 8;
}
#if defined(MULTIMODULE)
if (!strcmp(key, "protocol")) {
protocol = luaL_checkinteger(L, -1);
}
if (!strcmp(key, "subProtocol")) {
subprotocol = luaL_checkinteger(L, -1);
}
#endif
}
#if defined(MULTIMODULE)
if (protocol > 0 && subprotocol >= 0) { // Both are needed to compute otx protocol
convertMultiProtocolToOtx(&protocol, &subprotocol);
g_model.moduleData[idx].setMultiProtocol(protocol - 1);
g_model.moduleData[idx].subType = subprotocol;
}
#endif
storageDirty(EE_MODEL);
}
return 0;

View file

@ -177,12 +177,17 @@ enum ModuleSubtypeMulti {
MODULE_SUBTYPE_MULTI_ELRS,
MODULE_SUBTYPE_MULTI_REALACC,
MODULE_SUBTYPE_MULTI_OMP,
MODULE_SUBTYPE_MULTI_MLINK, //75
MODULE_SUBTYPE_MULTI_MLINK, //75
MODULE_SUBTYPE_MULTI_WFLY2,
MODULE_SUBTYPE_MULTI_E016HV2,
MODULE_SUBTYPE_MULTI_LAST = MODULE_SUBTYPE_MULTI_E016HV2
MODULE_SUBTYPE_MULTI_E010R5,
MODULE_SUBTYPE_MULTI_LOLI,
MODULE_SUBTYPE_MULTI_E129, //80
MODULE_SUBTYPE_MULTI_JOYSWAY,
MODULE_SUBTYPE_MULTI_E016H,
MODULE_SUBTYPE_MULTI_CONFIG,
MODULE_SUBTYPE_MULTI_LAST = MODULE_SUBTYPE_MULTI_CONFIG
};
#define MODULE_SUBTYPE_MULTI_XN297DP 63-3
enum MMDSM2Subtypes {
MM_RF_DSM2_SUBTYPE_DSM2_22,

View file

@ -669,7 +669,7 @@ inline void getMultiOptionValues(int8_t multi_proto, int8_t & min, int8_t & max)
min = 0;
max = 70;
break;
case MODULE_SUBTYPE_MULTI_XN297DP:
case MODULE_SUBTYPE_MULTI_XN297DUMP:
min = -1;
max = 84;
break;

View file

@ -42,6 +42,7 @@ static void sendD16BindOption(uint8_t moduleIdx);
#if defined(LUA)
static void sendSport(uint8_t moduleIdx);
static void sendHott(uint8_t moduleIdx);
static void sendConfig(uint8_t moduleIdx);
static void sendDSM(uint8_t moduleIdx);
#endif
@ -190,11 +191,14 @@ void setupPulsesMulti(uint8_t moduleIdx)
#if defined(LUA)
// SPort send
if (IS_D16_MULTI(moduleIdx) && outputTelemetryBuffer.destination == TELEMETRY_ENDPOINT_SPORT && outputTelemetryBuffer.size) {
sendSport(moduleIdx); //8 bytes of additional data
sendSport(moduleIdx); //8 bytes of additional data
}
else if (IS_HOTT_MULTI(moduleIdx)) {
sendHott(moduleIdx); //1 byte of additional data
}
else if (IS_CONFIG_MULTI(moduleIdx)) {
sendConfig(moduleIdx); //7 bytes of additional data
}
else if (IS_DSM_MULTI(moduleIdx)) {
sendDSM(moduleIdx); //7 bytes of additional data
}
@ -251,10 +255,54 @@ void sendChannels(uint8_t moduleIdx)
}
}
void convertMultiProtocolToOtx(int *protocol, int *subprotocol)
{
if (*protocol == 3 and *subprotocol == 0) {
*protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1;
*subprotocol = MM_RF_FRSKY_SUBTYPE_D8;
return;
}
if (*protocol == 3 and *subprotocol == 1) {
*protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1;
*subprotocol = MM_RF_FRSKY_SUBTYPE_D8_CLONED;
return;
}
if (*protocol == 25) {
*protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1;
*subprotocol = MM_RF_FRSKY_SUBTYPE_V8;
return;
}
if (*protocol == 15) {
*protocol = MODULE_SUBTYPE_MULTI_FRSKY + 1;
if (*subprotocol == 0)
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16;
else if (*subprotocol == 1)
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16_8CH;
else if (*subprotocol == 2)
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16_LBT;
else if (*subprotocol == 3)
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16_LBT_8CH;
else if (*subprotocol == 4)
*subprotocol = MM_RF_FRSKY_SUBTYPE_D16_CLONED;
return;
}
if (*protocol >= 25)
*protocol -= 1;
if (*protocol >= 16)
*protocol -= 1;
}
void convertOtxProtocolToMulti(int *protocol, int *subprotocol)
{
// Special treatment for the FrSky entry...
if (*protocol == MODULE_SUBTYPE_MULTI_FRSKY +1) {
if (*protocol == MODULE_SUBTYPE_MULTI_FRSKY + 1) {
if (*subprotocol == MM_RF_FRSKY_SUBTYPE_D8) {
//D8
*protocol = 3;
@ -288,10 +336,10 @@ void convertOtxProtocolToMulti(int *protocol, int *subprotocol)
// 15 for Multimodule is FrskyX or D16 which we map as a protocol of 3 (FrSky)
// all protos > frskyx are therefore also off by one
if (*protocol >= 15)
*protocol = *protocol + 1;
*protocol += 1;
// 25 is again a FrSky *protocol (FrskyV) so shift again
if (*protocol >= 25)
*protocol = *protocol + 1;
*protocol += 1;
}
}
@ -404,6 +452,23 @@ void sendHott(uint8_t moduleIdx)
}
}
void sendConfig(uint8_t moduleIdx)
{
// Multi_Buffer[0..3]=="Conf" -> Lua script is running
// Multi_Buffer[4]==0x01 -> TX to Module data ready to be sent
// Multi_Buffer[4]==0xFF -> Clear buffer data
// Multi_Buffer[5..11]=7 bytes of TX to Module data
// Multi_Buffer[12] -> Current page
// Multi_Buffer[13..172]=8*20=160 bytes of Module to TX data
if (Multi_Buffer && memcmp(Multi_Buffer, "Conf", 4) == 0 && Multi_Buffer[4] == 0x01) {
// Config Lua script is running and sending
for (uint8_t i = 0; i < 7; i++) {
sendMulti(moduleIdx, Multi_Buffer[5 + i]);
}
Multi_Buffer[4] = 0x00; // Send data only once
}
}
void sendDSM(uint8_t moduleIdx)
{
// Multi_Buffer[0..2]=="DSM" -> Lua script is running

View file

@ -25,6 +25,7 @@
void multiPatchCustom(uint8_t moduleIdx);
void convertOtxProtocolToMulti(int *protocol, int *subprotocol);
void convertMultiProtocolToOtx(int *protocol, int *subprotocol);
class UartMultiPulses: public DataBuffer<uint8_t, 64>
{

View file

@ -42,7 +42,8 @@ enum MultiPacketTypes : uint8_t
FlyskyIBusTelemetryAC,
MultiRxChannels,
HottTelemetry,
MLinkTelemetry
MLinkTelemetry,
ConfigTelemetry
};
enum MultiBufferState : uint8_t
@ -291,6 +292,31 @@ static void processMultiRxChannels(const uint8_t * data, uint8_t len)
}
#endif
#if defined(LUA)
static void processConfigPacket(const uint8_t * packet, uint8_t len)
{
// Multi_Buffer[0..3]=="Conf" -> Lua script is running
// Multi_Buffer[4]==0x01 -> TX to Module data ready to be sent
// Multi_Buffer[4]==0xFF -> Clear buffer data
// Multi_Buffer[5..11]=7 bytes of TX to Module data
// Multi_Buffer[12] -> Current page
// Multi_Buffer[13..172]=8*20=160 bytes of Module to TX data
if (Multi_Buffer && memcmp(Multi_Buffer, "Conf", 4) == 0) {
// HoTT Lua script is running
if (Multi_Buffer[4] == 0xFF) {
// Init
memset(&Multi_Buffer[4], 0x00, 1 + 7 + 1 + 160); // Clear the buffer
}
if ((packet[0] >> 4) != Multi_Buffer[12]) {// page change
memset(&Multi_Buffer[13], 0x00, 160); // Clear the buffer
Multi_Buffer[12] = (packet[0] >> 4); //Save the page number
}
memcpy(&Multi_Buffer[13 + (packet[0] & 0x0F) * 20], &packet[1], 20); // Store the received page in the buffer
}
}
#endif
static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
{
uint8_t type = packet[0];
@ -363,9 +389,18 @@ static void processMultiTelemetryPaket(const uint8_t * packet, uint8_t module)
if (len > 6)
processMLinkPacket(data);
else
TRACE("[MP] Received M-Link telemetry len %d < 6", len);
TRACE("[MP] Received M-Link telemetry len %d <= 6", len);
break;
#if defined(LUA)
case ConfigTelemetry:
if (len >= 21)
processConfigPacket(data, len);
else
TRACE("[MP] Received Config telemetry len %d < 20", len);
break;
#endif
case FrSkyHubTelemetry:
if (len >= 4)
frskyDProcessPacket(data);

View file

@ -118,6 +118,7 @@ extern uint8_t telemetryProtocol;
|| (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_FRSKYX2))
#define IS_R9_MULTI(module) (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_FRSKY_R9)
#define IS_HOTT_MULTI(module) (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_HOTT)
#define IS_CONFIG_MULTI(module) (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_CONFIG)
#define IS_DSM_MULTI(module) (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_DSM2)
#define IS_RX_MULTI(module) ((g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_AFHDS2A_RX) || (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_FRSKYX_RX) \
|| (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_BAYANG_RX) || (g_model.moduleData[module].getMultiProtocol() == MODULE_SUBTYPE_MULTI_DSM_RX))
@ -130,6 +131,7 @@ extern uint8_t telemetryProtocol;
#define IS_D16_MULTI(module) false
#define IS_R9_MULTI(module) false
#define IS_HOTT_MULTI(module) false
#define IS_CONFIG_MULTI(module) false
#define IS_DSM_MULTI(module) false
#define IS_FRSKY_SPORT_PROTOCOL() (telemetryProtocol == PROTOCOL_TELEMETRY_FRSKY_SPORT)
#define IS_RX_MULTI(module) false

View file

@ -131,7 +131,7 @@
#define TR_DSM_PROTOCOLS "LP45""DSM2""DSMX"
#define LEN_MULTI_PROTOCOLS "\007"
#define TR_MULTI_PROTOCOLS "FlySky\0""Hubsan\0""FrSky\0 ""Hisky\0 ""V2x2\0 ""DSM\0 ""Devo\0 ""YD717\0 ""KN\0 ""SymaX\0 ""SLT\0 ""CX10\0 ""CG023\0 ""Bayang\0""ESky\0 ""MT99XX\0""MJXq\0 ""Shenqi\0""FY326\0 ""Futaba\0""J6 Pro\0""FQ777\0 ""Assan\0 ""Hontai\0""OpenLrs""FlSky2A""Q2x2\0 ""Walkera""Q303\0 ""GW008\0 ""DM002\0 ""Cabell\0""Esky150""H8 3D\0 ""Corona\0""CFlie\0 ""Hitec\0 ""WFly\0 ""Bugs\0 ""BugMini""Traxxas""NCC1701""E01X\0 ""V911S\0 ""GD00X\0 ""V761\0 ""KF606\0 ""Redpine""Potensi""ZSX\0 ""Height\0""Scanner""FrSkyRX""FS2A_RX""HoTT\0 ""FX816\0 ""BayanRX""Pelikan""Tiger\0 ""XK\0 ""XN297DU""FrSkyX2""FrSkyR9""Propel\0""FrSkyL\0""Skyartc""ESky-v2""DSM RX\0""JJRC345""Q90C\0 ""Kyosho\0""RadLink""ExpLRS\0""Realacc""OMP\0 ""M-Link\0""Wfly 2\0""E016Hv2"
#define TR_MULTI_PROTOCOLS "FlySky\0""Hubsan\0""FrSky\0 ""Hisky\0 ""V2x2\0 ""DSM\0 ""Devo\0 ""YD717\0 ""KN\0 ""SymaX\0 ""SLT\0 ""CX10\0 ""CG023\0 ""Bayang\0""ESky\0 ""MT99XX\0""MJXq\0 ""Shenqi\0""FY326\0 ""Futaba\0""J6 Pro\0""FQ777\0 ""Assan\0 ""Hontai\0""OpenLrs""FlSky2A""Q2x2\0 ""Walkera""Q303\0 ""GW008\0 ""DM002\0 ""Cabell\0""Esky150""H8 3D\0 ""Corona\0""CFlie\0 ""Hitec\0 ""WFly\0 ""Bugs\0 ""BugMini""Traxxas""NCC1701""E01X\0 ""V911S\0 ""GD00X\0 ""V761\0 ""KF606\0 ""Redpine""Potensi""ZSX\0 ""Height\0""Scanner""FrSkyRX""FS2A_RX""HoTT\0 ""FX816\0 ""BayanRX""Pelikan""Tiger\0 ""XK\0 ""XN297DU""FrSkyX2""FrSkyR9""Propel\0""FrSkyL\0""Skyartc""ESky-v2""DSM RX\0""JJRC345""Q90C\0 ""Kyosho\0""RadLink""ExpLRS\0""Realacc""OMP\0 ""M-Link\0""Wfly 2\0""E016Hv2""E010r5 ""LOLI\0 ""E129\0 ""JOYSWAY""E016H\0 ""Config\0"
#define LEN_MULTI_POWER "\005"
#define TR_MULTI_POWER "1.6mW""2.0mW""2.5mW""3.2mW""4.0mW""5.0mW""6.3mW""7.9mW""10mW\0""13mW\0""16mW\0""20mW\0""25mW\0""32mW\0""40mW\0""50mW\0"