From e247b8b9c105dd4463345fa4049f0f72967725f4 Mon Sep 17 00:00:00 2001 From: Pascal Langer Date: Wed, 20 Oct 2021 15:13:56 +0200 Subject: [PATCH] DSM Fwd Pgm updated --- Lua_scripts/DSM FwdPrg.lua | 245 +++++++++++++++++++++++++++---------- Lua_scripts/README.md | 2 + 2 files changed, 179 insertions(+), 68 deletions(-) diff --git a/Lua_scripts/DSM FwdPrg.lua b/Lua_scripts/DSM FwdPrg.lua index ce659e0..8bb570c 100644 --- a/Lua_scripts/DSM FwdPrg.lua +++ b/Lua_scripts/DSM FwdPrg.lua @@ -1,4 +1,4 @@ -local toolName = "TNS|DSM Forward Programming|TNE" +local toolName = "TNS|DSM Forward Programming v0.2|TNE" ---- ######################################################################### ---- # # @@ -31,8 +31,8 @@ local toolName = "TNS|DSM Forward Programming|TNE" -- Write "DSM" at address 0..2 --############################################################################### -local RX_VERSION, WAIT_CMD, MENU_TITLE, MENU_LINES, MENU_VALUES, VALUE_CHANGING, VALUE_CHANGING_WAIT, VALUE_CHANGED = 0, 1, 2, 3, 4, 5, 6, 7 -local MENU, LIST_MENU_NOCHANGING, LIST_MENU2, PERCENTAGE_VALUE = 0x1C, 0x6C, 0x4C, 0xC0 +local RX_VERSION, WAIT_CMD, MENU_TITLE, MENU_LINES, MENU_VALUES, VALUE_CHANGING, VALUE_CHANGING_WAIT, VALUE_CHANGED, EXIT, EXIT_DONE = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 +local MENU, LIST_MENU_NOCHANGING, LIST_MENU1, LIST_MENU2, VALUE_NOCHANGING = 0x1C, 0x6C, 0x0C, 0x4C, 0x60 local Phase = RX_VERSION local Waiting_RX = 0 local Text = {} @@ -44,13 +44,30 @@ local Menu = { Cur=nil, Id=nil, Title="", Prev=nil, PrevId=nil, Next=nil, NextId local Line = {} local RX = { Name="", Version="" } +-- used for debug +local rxAnswer = "" +local debugLine = 0 + +------------------------------------------------------------------------------------------------------------ +local function GetDebugInfo(lineNr) -- used for debug + local i + + debugLine = lineNr + rxAnswer = "RX:" + for i=10, 25 do + rxAnswer = rxAnswer.." "..string.format("%02X", multiBuffer(i)) + end + +end + +------------------------------------------------------------------------------------------------------------ local function conv_int16(number) if number >= 0x8000 then return number - 0x10000 end return number end - +------------------------------------------------------------------------------------------------------------ local function Get_Text(index) out = Text[index] if out == nil then -- unknown... @@ -58,11 +75,12 @@ local function Get_Text(index) end return out end - +------------------------------------------------------------------------------------------------------------ local function DSM_Release() multiBuffer( 0, 0 ) + Phase = EXIT_DONE end - +------------------------------------------------------------------------------------------------------------ local function DSM_Send(...) local arg = {...} for i = 1 , #arg do @@ -70,7 +88,7 @@ local function DSM_Send(...) end multiBuffer( 3, 0x70+#arg) end - +------------------------------------------------------------------------------------------------------------ local function Value_Add(dir) local line=Line[Menu.SelLine] Speed = getRotEncSpeed() @@ -91,17 +109,25 @@ local function Value_Add(dir) Waiting_RX = 0 end end - +------------------------------------------------------------------------------------------------------------ local function DSM_Menu(event) local Speed = 0 - if event == EVT_VIRTUAL_NEXT then + + if event == EVT_VIRTUAL_EXIT then + if Phase == RX_VERSION then + DSM_Release() + else + Phase = EXIT + Waiting_RX = 0 + end + elseif event == EVT_VIRTUAL_NEXT then if Menu.EditLine == nil then -- not changing a value if Menu.SelLine ~= nil then if Menu.SelLine < 7 then local num = Menu.SelLine for i = Menu.SelLine + 1, 6, 1 do - if Line[i].Type ~= nil and Line[i].Next ~= nil then + if Line[i].Type ~= nil and Line[i].Next ~= nil and Line[i].Type ~= VALUE_NOCHANGING then Menu.SelLine=i break end @@ -131,7 +157,7 @@ local function DSM_Menu(event) end local num = Menu.SelLine for i = Menu.SelLine-1, 0, -1 do - if Line[i].Type ~= nil and Line[i].Next ~= nil then + if Line[i].Type ~= nil and Line[i].Next ~= nil and Line[i].Type ~= VALUE_NOCHANGING then Menu.SelLine=i break end @@ -146,6 +172,15 @@ local function DSM_Menu(event) else -- need to dec the value Value_Add(-1) end + elseif event == EVT_VIRTUAL_ENTER_LONG then + if Menu.EditLine ~= nil then + -- reset the value to default + if Line[Menu.SelLine].Type ~= LIST_MENU_NOCHANGING then + Line[Menu.SelLine].Val = Line[Menu.SelLine].Def + Phase = VALUE_CHANGING + Waiting_RX = 0 + end + end elseif event == EVT_VIRTUAL_ENTER then if Menu.SelLine == -1 then -- Back Menu.Cur = Menu.Back @@ -185,23 +220,27 @@ local function DSM_Menu(event) end end end - +------------------------------------------------------------------------------------------------------------ local function DSM_Send_Receive() if Waiting_RX == 0 then Waiting_RX = 1 - -- Need to send a request + + -- Need to send a request if Phase == RX_VERSION then -- request RX version DSM_Send(0x11,0x06,0x00,0x14,0x00,0x00) - elseif Phase == WAIT_CMD then -- keep connection open + + elseif Phase == WAIT_CMD then -- keep connection open DSM_Send(0x00,0x04,0x00,0x00) - elseif Phase == MENU_TITLE then -- request menu title + + elseif Phase == MENU_TITLE then -- request menu title if Menu.Cur == nil then DSM_Send(0x12,0x06,0x00,0x14,0x00,0x00) -- first menu only Menu.Cur = 0 else DSM_Send(0x16,0x06,Menu.Id,Menu.Cur,0x00,Menu.SelLine) end - elseif Phase == MENU_LINES then -- request menu lines + + elseif Phase == MENU_LINES then -- request menu lines if Menu.CurLine == nil then DSM_Send(0x13,0x04,Menu.Id,Menu.Cur) -- line 0 elseif Menu.CurLine >= 0x80 then @@ -210,46 +249,59 @@ local function DSM_Send_Receive() else DSM_Send(0x14,0x06,Menu.Id,Menu.Cur,0x00,Menu.CurLine) -- line X end - elseif Phase == MENU_VALUES then -- request menu values - DSM_Send(0x15,0x06,Menu.Id,Menu.Cur,Line[Menu.CurLine].ValId,Menu.CurLine) -- line X - elseif Phase == VALUE_CHANGING then -- send value - local value=Line[Menu.SelLine].Val + + elseif Phase == MENU_VALUES then -- request menu values + DSM_Send(0x15,0x06,Menu.Id,Menu.Cur,Line[Menu.CurLine].ValId,Line[Menu.CurLine].Next) -- line X + + elseif Phase == VALUE_CHANGING then -- send value + local value=Line[Menu.SelLine].Val if value < 0 then value = 0x10000 + value end - DSM_Send(0x18,0x06,Line[Menu.SelLine].ValId,Menu.SelLine,bit32.rshift(value,8),bit32.band(value,0xFF)) -- send current value + DSM_Send(0x18,0x06,Line[Menu.SelLine].ValId,Line[Menu.SelLine].Next,bit32.rshift(value,8),bit32.band(value,0xFF)) -- send current value Phase = VALUE_CHANGING_WAIT - elseif Phase == VALUE_CHANGED then -- send value + + elseif Phase == VALUE_CHANGED then -- send value if Value_Changed == 0 then local value=Line[Menu.SelLine].Val if value < 0 then value = 0x10000 + value end - DSM_Send(0x18,0x06,Line[Menu.SelLine].ValId,Menu.SelLine,bit32.rshift(value,8),bit32.band(value,0xFF)) -- send current value + DSM_Send(0x18,0x06,Line[Menu.SelLine].ValId,Line[Menu.SelLine].Next,bit32.rshift(value,8),bit32.band(value,0xFF)) -- send current value Value_Changed = Value_Changed + 1 Waiting_RX = 0 elseif Value_Changed == 1 then - DSM_Send(0x19,0x06,Line[Menu.SelLine].ValId,Menu.SelLine) -- validate + DSM_Send(0x19,0x06,Line[Menu.SelLine].ValId,Line[Menu.SelLine].Next) -- validate -- Value_Changed = Value_Changed + 1 -- Waiting_RX = 0 --elseif Value_Changed == 2 then -- DSM_Send(0x1B,0x06,0x10,Menu.SelLine) -- validate again? -- Value_Changed = Value_Changed + 1 end - elseif Phase == VALUE_CHANGING_WAIT then - DSM_Send(0x1A,0x06,Line[Menu.SelLine].ValId,Menu.SelLine) - end + + elseif Phase == VALUE_CHANGING_WAIT then + DSM_Send(0x1A,0x06,Line[Menu.SelLine].ValId,Line[Menu.SelLine].Next) + + elseif Phase == EXIT then + DSM_Send(0x1F,0x02,0xAA) + + end multiBuffer(10,0x00); Retry = 50 + -- -- -- -- -- -- -- -- -- -- -- -- receive part -- -- -- -- -- -- -- -- -- -- -- -- -- elseif multiBuffer(10) == 0x09 then -- Answer received - --if multiBuffer(11) == 0x00 then -- waiting for commands? - if multiBuffer(11) == 0x01 then -- read version - --ex: 0x09 0x01 0x00 0x15 0x02 0x22 0x01 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + -- GetDebugInfo(292) -- used for debug + + --if multiBuffer(11) == 0x00 then -- waiting for commands? + + if multiBuffer(11) == 0x01 then -- read version + --ex: 0x09 0x01 0x00 0x15 0x02 0x22 0x01 0x00 0x14 0x00 0x00 0x00 0x00 0x00 0x00 0x00 RX.Name = Get_Text(multiBuffer(13)) RX.Version = multiBuffer(14).."."..multiBuffer(15).."."..multiBuffer(16) Phase = MENU_TITLE - elseif multiBuffer(11) == 0x02 then -- read menu title + + elseif multiBuffer(11) == 0x02 then -- read menu title --ex: 0x09 0x02 0x4F 0x10 0xA5 0x00 0x00 0x00 0x50 0x10 0x10 0x10 0x00 0x00 0x00 0x00 Menu.Cur = multiBuffer(12) Menu.Id = multiBuffer(13) @@ -271,7 +323,8 @@ local function DSM_Send_Receive() end Blink = 0 Phase = MENU_LINES - elseif multiBuffer(11) == 0x03 then -- read menu lines + + elseif multiBuffer(11) == 0x03 then -- read menu lines --ex: 0x09 0x03 0x00 0x10 0x00 0x1C 0xF9 0x00 0x10 0x10 0x00 0x00 0x00 0x00 0x03 0x00 -- Menu Id line Type Text_idx Next V_Id Val_Min Val_Max Val_Def --ex: 0x09 0x03 0x61 0x10 0x00 0x6C 0x50 0x00 0x00 0x10 0x36 0x00 0x49 0x00 0x36 0x00 @@ -279,13 +332,13 @@ local function DSM_Send_Receive() local line = Line[Menu.CurLine] line.Menu = multiBuffer(12) line.Id = multiBuffer(13) -- not quite sure yet - line.Type = multiBuffer(15) -- not quite sure yet: 1C is text menu only, 4C/6C is text followed by text list, C0 is text followed by percentage value + line.Type = multiBuffer(15) -- not quite sure yet: 1C is text menu only, 4C/6C is text followed by text list, C0 is text followed by percentage value, 0C new list type line.Text = Get_Text(multiBuffer(16)+multiBuffer(17)*256) - if multiBuffer(18) == Menu.Cur then - line.Next = nil - else - line.Next = multiBuffer(18) -- not quite sure yet: 1C=text menu=>next menu, others=>line number of the value - end + --if multiBuffer(18) == Menu.Cur then + -- line.Next = nil + --else + line.Next = multiBuffer(18) -- not quite sure yet: 1C=text menu=>next menu, others=>identifier of line number of the value + --end if Menu.SelLine == -1 and line.Next ~= nil then -- Auto select first line of the menu Menu.SelLine = Menu.CurLine end @@ -297,7 +350,7 @@ local function DSM_Send_Receive() line.Def = conv_int16(multiBuffer(24)+multiBuffer(25)*256) if line.Type == MENU then -- nothing to do on menu entries - elseif line.Type == LIST_MENU_NOCHANGING or line.Type == LIST_MENU2 then + elseif line.Type == LIST_MENU_NOCHANGING or line.Type == LIST_MENU1 or line.Type == LIST_MENU2 then line.Val = nil --line.Def - line.Min -- use default value not sure if needed line.Def = line.Min -- pointer to the start of the list in Text line.Max = line.Max - line.Min -- max index @@ -305,43 +358,66 @@ local function DSM_Send_Receive() else -- default to numerical value line.Val = nil --line.Def -- use default value not sure if needed end - if line.Type ~= 0x1C then -- value to follow + if line.Type ~= MENU and line.Type ~= VALUE_NOCHANGING then -- updatable value to follow line.Text = line.Text..":" end Phase = MENU_LINES - elseif multiBuffer(11) == 0x04 then -- read menu values + + elseif multiBuffer(11) == 0x04 then -- read menu values --ex: 0x09 0x04 0x53 0x10 0x00 0x10 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 -- Menu MeId line VaId Value --ex: 0x09 0x04 0x61 0x10 0x02 0x10 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 - Menu.CurLine = multiBuffer(14) - Line[Menu.CurLine].Val = conv_int16(multiBuffer(16)+multiBuffer(17)*256) + -- Identify the line and update the value + for i = 0, 6 do + if Line[i] ~= nil and Line[i].Type ~= nil then + if Line[i].Type ~= MENU and Line[i].Next == multiBuffer(14) then -- identifier of line number stored in .Next + Line[i].Val = conv_int16(multiBuffer(16)+multiBuffer(17)*256) + Menu.CurLine = i + break + end + end + end Phase = MENU_VALUES - elseif multiBuffer(11) == 0x05 then -- unknown... need to get through the lines... + + elseif multiBuffer(11) == 0x05 then -- unknown... need to get through the lines... Menu.CurLine = 0x80 + multiBuffer(12) Phase = MENU_LINES - elseif multiBuffer(11) == 0x00 and Phase == VALUE_CHANGING then + + elseif multiBuffer(11) == 0xA7 then -- answer to EXIT command + DSM_Release() + + elseif multiBuffer(11) == 0x00 and Phase == VALUE_CHANGING then Phase = VALUE_CHANGING_WAIT - end - -- Data processed + + end + + -- Data processed Waiting_RX = 0 multiBuffer(10,0x00) Retry = 50 + else Retry = Retry - 1 if Retry <= 0 then -- Retry the RX request Retry = 50 Waiting_RX = 0 + if Phase == EXIT then + DSM_Release() + end if Phase ~= RX_VERSION and Phase ~= VALUE_CHANGING_WAIT then Phase = WAIT_CMD end end end + end - +------------------------------------------------------------------------------------------------------------ local function DSM_Display() lcd.clear() + if LCD_W == 480 then + --lcd.drawText(10,55,debugLine.." "..rxAnswer) -- draw debug info --Draw title lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR) lcd.drawText(1, 5, "DSM Forward Programming", MENU_TITLE_COLOR) @@ -362,12 +438,13 @@ local function DSM_Display() if Line[i].Type ~= MENU then -- list/value if Line[i].Val ~= nil then local text="" - if Line[i].Type == LIST_MENU_NOCHANGING or Line[i].Type == LIST_MENU2 then + if Line[i].Type == LIST_MENU_NOCHANGING or Line[i].Type == LIST_MENU1 or Line[i].Type == LIST_MENU2 then text = Get_Text(Line[i].Val+Line[i].Def) - elseif Line[i].Type == PERCENTAGE_VALUE then + elseif ( Line[i].Min == 0 and Line[i].Max == 100) or ( Line[i].Min == -100 and Line[i].Max == 100) or ( Line[i].Min == 0 and Line[i].Max == 150) or ( Line[i].Min == -150 and Line[i].Max == 150) then text = Line[i].Val.." %" else - text = Line[i].Val + --text = Line[i].Val .." T="..Line[i].Type -- used for debug + text = Line[i].Val end if Menu.EditLine == Menu.SelLine then -- blink edited entry Blink = Blink + 1 @@ -437,7 +514,7 @@ local function DSM_Display() -- end end end - +------------------------------------------------------------------------------------------------------------ -- Init local function DSM_Init() --Set protocol to talk to @@ -457,10 +534,16 @@ local function DSM_Init() multiBuffer( 2, string.byte('M') ) --Text to be displayed -> need to use a file instead? + Text[0x0002]="Off" + Text[0x000C]="Inhibit?" --? + Text[0x000D]="Gear" + --RX names-- Text[0x0014]="SPM4651T" Text[0x0015]="AR637T" + Text[0x0018]="FC6250HX" --Lists-- + Text[0x0035]="Inhibit?" --? Text[0x0036]="Throttle" Text[0x0037]="Aileron" Text[0x0038]="Elevator" @@ -479,9 +562,12 @@ local function DSM_Init() Text[0x0040]="Roll" Text[0x0041]="Pitch" Text[0x0042]="Yaw" + Text[0x0043]="Gain" -- FC6250HX + Text[0x0045]="Differential" Text[0x0046]="Priority" + Text[0x0049]="Output Setup" -- FC6250HX --****** - + Text[0x004A]="Failsafe" Text[0x004B]="Main Menu" Text[0x004E]="Position" @@ -497,20 +583,28 @@ local function DSM_Init() Text[0x0060]="Preset" --Text[0x0061]="Custom" --Messages-- + Text[0x0071]="Proportional" + Text[0x0072]="Integral" + Text[0x0073]="Derivate" Text[0x0078]="FM Channel" Text[0x0080]="Orientation" Text[0x0085]="Frame Rate" Text[0x0086]="System Setup" Text[0x0087]="F-Mode Setup" Text[0x0088]="Enabled F-Modes" + Text[0x0089]="Gain Channel" Text[0x008A]="Gain Sensitivity" + Text[0x008B]="Panic" Text[0x0090]="Apply" + Text[0x0092]="Start" Text[0x0093]="Complete" Text[0x0094]="Done" Text[0x0097]="Factory Reset" + Text[0x0099]="Advanced Setup" Text[0x009A]="Capture Failsafe Positions" Text[0x009C]="Custom Failsafe" Text[0x00A5]="First Time Setup" + Text[0x00AA]="Capture Gyro Gains" Text[0x00AD]="Gain Channel Select" Text[0x00B6]="FM1" Text[0x00B7]="FM2" @@ -522,33 +616,47 @@ local function DSM_Init() Text[0x00BD]="FM8" Text[0x00BE]="FM9" Text[0x00BF]="FM10" + Text[0x00C7]="Calibrate Sensor" + Text[0x00D3]="Swashplate" + Text[0x00D5]="Agility" + Text[0x00D8]="Stop" + Text[0x00DA]="SAFE" + Text[0x00DB]="Stability" + Text[0x00DC]="@ per sec" + Text[0x00DD]="Tail rotor" + Text[0x00DE]="Setup" + Text[0x00DF]="AFR" + Text[0x00E0]="Collective" + Text[0x00E1]="Subtrim" + Text[0x00E2]="Phasing" + Text[0x00E4]="E-Ring" + Text[0x00E7]="Left" + Text[0x00E8]="Right" + Text[0x00F3]="Adjustable" Text[0x00F9]="Gyro settings" Text[0x00FE]="Stick Priority" Text[0x0100]="Make sure the model has been" Text[0x0101]="configured, including wing type," Text[0x0102]="reversing, travel, trimmed, etc." Text[0x0103]="before continuing setup." - Text[0x0104]="0104" - Text[0x0105]="0105" Text[0x0106]="Any wing type, channel assignment," Text[0x0107]="subtrim, or servo reversing changes" Text[0x0108]="require running through initial" Text[0x0109]="setup again." - Text[0x010A]="010A" - Text[0x010B]="010B" Text[0x0190]="Relearn Servo Settings" Text[0x019C]="Enter Receiver Bind Mode" Text[0x01DC]="AS3X" Text[0x01DD]="AS3X Settings" Text[0x01DE]="AS3X Gains" Text[0x01E0]="Rate Gains" - Text[0x020A]="Restore from Backup" + Text[0x01E6]="Attitude Trim" + Text[0x01E7]="Envelope" + Text[0x0208]="Decay" Text[0x0209]="Save to Backup" + Text[0x020A]="Restore from Backup" Text[0x020D]="First Time SAFE Setup" Text[0x021A]="Set the model level," Text[0x021B]="and press Continue." - Text[0x021C]="021C" - Text[0x021D]="021D" Text[0x021F]="Set the model on its nose," Text[0x0220]="and press Continue. If the" @@ -564,36 +672,37 @@ local function DSM_Init() Text[0x022D]="configuration to factory" Text[0x022E]="defaults. This does not" Text[0x022F]="affect the backup config." - Text[0x0230]="0230" Text[0x0231]="This will overwrite the" Text[0x0232]="backup memory with your" Text[0x0233]="current configuartion." - Text[0x0234]="0234" - Text[0x0235]="0235" Text[0x0236]="This will overwrite the" Text[0x0237]="current config with" Text[0x0238]="that which is in" Text[0x0239]="the backup memory." - Text[0x023A]="023A" Text[0x023D]="Copy Flight Mode Settings" Text[0x0240]="Utilities" + Text[0x0263]="Fixed/Adjustable Gains" + Text[0x0266]="Heading Gain" + Text[0x026A]="Use CAUTION for Yaw gain!" + Text[0x8000]="FLIGHT MODE" Text[0x8001]="Flight Mode 1" Text[0x8002]="Flight Mode 2" Text[0x8003]="Flight Mode 3" end - +------------------------------------------------------------------------------------------------------------ -- Main local function DSM_Run(event) if event == nil then error("Cannot be run as a model script!") return 2 - elseif event == EVT_VIRTUAL_EXIT then - DSM_Release() - return 2 else DSM_Menu(event) DSM_Send_Receive() DSM_Display() + end + if Phase == EXIT_DONE then + return 2 + else return 0 end end diff --git a/Lua_scripts/README.md b/Lua_scripts/README.md index 2bef9cb..9cd562a 100644 --- a/Lua_scripts/README.md +++ b/Lua_scripts/README.md @@ -54,6 +54,8 @@ Notes: ## DSM Forward Programming +Navigation is mainly done using the scroll wheel and ENT. Short press on ENT will edit a value. When editing a value a long ENT press will restore the value to its default. To exit the script and terminate all current operations correctly short press RTN (if you don't do this the RX might not store the changes). + This is a work in progress. It's only available for color screens (Horus, TX16S, T16, T18...). If some text appears as Unknown_xxx, please report xxx and what the exact text display should be.