diff --git a/src/Horus/KISS/alarms.lua b/src/Horus/KISS/alarms.lua index 68a894a..8a8a0f9 100644 --- a/src/Horus/KISS/alarms.lua +++ b/src/Horus/KISS/alarms.lua @@ -25,5 +25,9 @@ return { -- Alarms { t = "VBat", x = 100, y = 96, sp = 60, i=1, min=0, max=26000, prec=1 }, { t = "mAH", x = 250, y = 96, sp = 60, i=2, min=0, max=26000, inc=10 } - } + }, + wrName = {}, + dL = 10, + data = {}, + defValues = "Default___14400 1000" } diff --git a/src/Horus/KISS/filters.lua b/src/Horus/KISS/filters.lua index 2287bce..c46b85f 100644 --- a/src/Horus/KISS/filters.lua +++ b/src/Horus/KISS/filters.lua @@ -52,5 +52,9 @@ return { { x = 289, y = 124, i=6, min=0, max=490 }, { x = 129, y = 158, i=7, min=1, max=7, table = { "Off", "High", "Med. High", "Medium", "Med. Low", "Low", "Very Low" } }, { x = 129, y = 186, i=8, min=0, max=97}, - } + }, + wrName = {}, + dL = 40, + data = {}, + defValues = "Default___ 1 200 100 1 200 100 1 35" } diff --git a/src/Horus/KISS/memory.lua b/src/Horus/KISS/memory.lua new file mode 100644 index 0000000..24f7b92 --- /dev/null +++ b/src/Horus/KISS/memory.lua @@ -0,0 +1,20 @@ +return { + title = " Names", + text = { + { t = "1:", x = 40, y = 43 }, + { t = "2:", x = 40, y = 63 }, + { t = "3:", x = 40, y = 83 }, + { t = "4:", x = 40, y = 103 }, + { t = "5:", x = 40, y = 123 } + }, + fields = { + -- model data + {t="1", d="", x = 60, y = 43, sp = 12, i=1, min=1, max=500 }, + {t="2", d="", x = 60, y = 63, sp = 12, i=2, min=1, max=500 }, + {t="3", d="", x = 60, y = 83, sp = 12, i=3, min=0, max=600 }, + {t="4", d="", x = 60, y = 103, sp = 12, i=4, min=0, max=600 }, + {t="5", d="", x = 60, y = 123, sp = 12, i=5, min=0, max=600 } + }, + read = select_model_load, + write = select_model_save +} diff --git a/src/Horus/KISS/pids.lua b/src/Horus/KISS/pids.lua index 5f9f745..81d6870 100644 --- a/src/Horus/KISS/pids.lua +++ b/src/Horus/KISS/pids.lua @@ -47,5 +47,9 @@ return { { x = 289, y = 96, i=3, max=65000, prec=2 }, { x = 289, y = 124, i=6, max=65000, prec=2 }, { x = 289, y = 152, i=9, max=65000, prec=2 } - } + }, + wrName = {}, + dL = 45, + data = {}, + defValues = "Default___ 3000 3510000 3000 3510000 8000 50 0" } diff --git a/src/Horus/KISS/rates.lua b/src/Horus/KISS/rates.lua index 67ad172..d34b32f 100644 --- a/src/Horus/KISS/rates.lua +++ b/src/Horus/KISS/rates.lua @@ -40,5 +40,9 @@ return { { x = 129, y = 152, i=7, max=65000, prec=2 }, { x = 209, y = 152, i=8, max=65000, prec=2 }, { x = 289, y = 152, i=9, max=65000, prec=2 } - } + }, + wrName = {}, + dL = 45, + data = {}, + defValues= "Default___ 70 70 40 70 70 40 70 70 40" } diff --git a/src/Horus/KISS/tpa.lua b/src/Horus/KISS/tpa.lua index abe61af..26b5e11 100644 --- a/src/Horus/KISS/tpa.lua +++ b/src/Horus/KISS/tpa.lua @@ -51,5 +51,9 @@ return { { x = 190, y = 190, i=8, max=100}, { x = 240, y = 190, i=9, max=100}, { x = 289, y = 190, i=10,max=100}, - } + }, + wrName = {}, + dL = 50, + data = {}, + defValues = "Default___ 40 20 40 1 30 50 30 0 0 100" } diff --git a/src/Horus/Kiss.lua b/src/Horus/Kiss.lua index 0ff3bc3..6802dcb 100644 --- a/src/Horus/Kiss.lua +++ b/src/Horus/Kiss.lua @@ -7,6 +7,19 @@ local drawScreenTitle = function(title, currentPage, totalPages) lcd.drawText(1, 5, title, MENU_TITLE_COLOR) end +local drawScreenTitle = function(title, cPage, tPages) + local str + if cPage == #(AllPages) then + str = "Mem: "..CP.title + cPage = 0 + tPages = 0 + else + str = "Kiss Setup: " + end + lcd.drawFilledRectangle(0, 0, LCD_W, 30, TITLE_BGCOLOR) + lcd.drawText(1,5,str..title,MENU_TITLE_COLOR) +end + local drawTelemetry = function() lcd.drawText(192,LCD_H - 28,"No telemetry",TEXT_COLOR + INVERS + BLINK) end @@ -18,20 +31,29 @@ local drawSaving = function() end local function drawMenu(menuList, menuActive) + local vTx +if ActivePage.title== "VTX" then vTx = 2 else vTx = #(menuList) end + local x = 120 local y = 100 - local w = 200 + local w = 240 local x_offset = 68 local h_line = 20 local h_offset = 6 - local h = #(menuList) * h_line + h_offset*2 + local h = vTx * h_line + h_offset*2 +lcd.drawFilledRectangle(x-2,y-2,w+4,h+4,ERASE) +lcd.drawRectangle(x-2,y-2,w+3,h+3,SOLID) +lcd.drawRectangle(x,y,w-1,h-1,SOLID) +lcd.drawText(x+4,y+3,"Menu: ", INVERS) + lcd.drawFilledRectangle(x,y,w,h,TEXT_BGCOLOR) lcd.drawRectangle(x,y,w-1,h-1,LINE_COLOR) lcd.drawText(x+h_line/2,y+h_offset,"Menu:", TEXT_COLOR) for i,e in ipairs(menuList) do local text_options = TEXT_COLOR + if vTx == 2 and i == 3 then break end if menuActive == i then text_options = text_options + INVERS end @@ -39,6 +61,39 @@ local function drawMenu(menuList, menuActive) end end +local function getFieldFlags(p) +local flg = 0 +if activeField==p then + flg=INVERS + if editMode then + flg=INVERS+BLINK + end +end +return flg +end + +local function drawEditMenu() +currentLine = 1 +local x = 30 +local y = 60 +local w = 240 +local h = 120 + +lcd.drawFilledRectangle(x,y,w,h,TEXT_BGCOLOR) +lcd.drawRectangle(x,y,w,h,LINE_COLOR) +lcd.drawRectangle(x+1,y+1,w-2,h-3,LINE_COLOR) + +lcd.drawText(x+5,y+3,CP.title.." Set: ",TEXT_COLOR) +lcd.drawText(x + w - 30, y+3, currentLine, TEXT_COLOR) +lcd.drawText(x+4,y+32,"Name: ") +for i = 0,9 do + lcd.drawText ( x+80+i*15,y+32,CPvN[i+1],getFieldFlags(i)) +end +lcd.drawText(x+6, y+80, "[SAVE NAME]", getFieldFlags(10)) +lcd.drawText(x+w-90, y+80, "[..LOAD..]", getFieldFlags(11)) + +end + local function getDefaultTextOptions() return TEXT_COLOR end diff --git a/src/X7/KISS/alarms.lua b/src/X7/KISS/alarms.lua index 0e26463..9c7cf26 100644 --- a/src/X7/KISS/alarms.lua +++ b/src/X7/KISS/alarms.lua @@ -24,5 +24,9 @@ return { fields = { { t = "VBat", x = 15, y = 27, sp = 70, i=1, min=0, max=26000, prec=1 }, { t = "mAH", x = 15, y = 40, sp = 70, i=2, min=0, max=26000, inc=10 } - } + }, + wrName = {}, + dL = 10, + data = {}, + defValues = "Default___14400 1000" } diff --git a/src/X7/KISS/filters.lua b/src/X7/KISS/filters.lua index 4cd6f9f..e7ad739 100644 --- a/src/X7/KISS/filters.lua +++ b/src/X7/KISS/filters.lua @@ -54,5 +54,9 @@ return { { x = 80, y = 38, i=6, min=0, max=490 }, { x = 15, y = 52, i=7, min=1, max=7, table = { "Off", "High", "MedHi", "Med", "MedLo", "Low", "VerLo" } }, { x = 80, y = 52, i=8, min=0, max=97}, - } + }, + wrName = {}, + dL = 40, + data = {}, + defValues = "Default___ 1 200 100 1 200 100 1 35" } diff --git a/src/X7/KISS/memory.lua b/src/X7/KISS/memory.lua new file mode 100644 index 0000000..8e139fb --- /dev/null +++ b/src/X7/KISS/memory.lua @@ -0,0 +1,20 @@ +return { + title = " Names", + text = { + { t = "1:", x = 10, y = 13 }, + { t = "2", x = 10, y = 23 }, + { t = "3:", x = 10, y = 33 }, + { t = "4:", x = 10, y = 43 }, + { t = "5:", x = 10, y = 53 } + }, + fields = { + -- model data + {t="1", d="", x = 20, y = 13, sp = 12, i=1, min=1, max=500 }, + {t="2", d="", x = 20, y = 23, sp = 12, i=2, min=1, max=500 }, + {t="3", d="", x = 20, y = 33, sp = 12, i=3, min=0, max=600 }, + {t="4", d="", x = 20, y = 43, sp = 12, i=4, min=0, max=600 }, + {t="5", d="", x = 20, y = 53, sp = 12, i=5, min=0, max=600 } + }, + read = select_model_load, + write = select_model_save +} diff --git a/src/X7/KISS/pids.lua b/src/X7/KISS/pids.lua index 6a017c8..e4bcddd 100644 --- a/src/X7/KISS/pids.lua +++ b/src/X7/KISS/pids.lua @@ -45,4 +45,8 @@ return { { x = 48, y = 50, i=8, max=65000, prec=3 }, { x = 80, y = 50, i=9, max=65000, prec=2 } }, + wrName = {}, + dL = 45, + data = {}, + defValues = "Default___ 3000 3510000 3000 3510000 8000 50 0" } diff --git a/src/X7/KISS/rates.lua b/src/X7/KISS/rates.lua index 3f9b2db..d13bba7 100644 --- a/src/X7/KISS/rates.lua +++ b/src/X7/KISS/rates.lua @@ -39,5 +39,9 @@ return { { x = 16, y = 50, i=7, max=65000, prec=2 }, { x = 48, y = 50, i=8, max=65000, prec=2 }, { x = 80, y = 50, i=9, max=65000, prec=2 } - } + }, + wrName = {}, + dL = 45, + data = {}, + defValues= "Default___ 70 70 40 70 70 40 70 70 40" } diff --git a/src/X7/KISS/tpa.lua b/src/X7/KISS/tpa.lua index 2bb5921..7a13b9a 100644 --- a/src/X7/KISS/tpa.lua +++ b/src/X7/KISS/tpa.lua @@ -51,5 +51,9 @@ return { { x = 38, y = 53, i=8, max=100}, { x = 61, y = 53, i=9, max=100}, { x = 85, y = 53, i=10,max=100}, - } + }, + wrName = {}, + dL = 50, + data = {}, + defValues = "Default___ 40 20 40 1 30 50 30 0 0 100" } diff --git a/src/X7/Kiss.lua b/src/X7/Kiss.lua index c68337f..5f28aff 100644 --- a/src/X7/Kiss.lua +++ b/src/X7/Kiss.lua @@ -2,8 +2,16 @@ local RADIO = "X7" -local drawScreenTitle = function(title, currentPage, totalPages) - lcd.drawScreenTitle('Kiss Setup: '..title, currentPage, totalPages) +local drawScreenTitle = function(title, cPage, tPages) + local str + if cPage == #(AllPages) then + str = "Mem: "..CP.title + cPage = 0 + tPages = 0 + else + str = "Kiss Setup: " + end + lcd.drawScreenTitle(str..title, cPage, tPages) end local drawTelemetry = function() @@ -17,23 +25,61 @@ local drawSaving = function() end local function drawMenu(menuList, menuActive) - local x = 6 +local vTx +if ActivePage.title== "VTX" then vTx = 2 else vTx = #(menuList) end + + local x = 4 local y = 12 local w = 120 - local h = #(menuList) * 8 + 6 - lcd.drawFilledRectangle(x,y,w,h,ERASE) + local h = vTx * 8 + 6 + lcd.drawFilledRectangle(x-2,y-2,w+4,h+4,ERASE) + lcd.drawRectangle(x-2,y-2,w+3,h+3,SOLID) lcd.drawRectangle(x,y,w-1,h-1,SOLID) - lcd.drawText(x+4,y+3,"Menu:") + lcd.drawText(x+2,y+3,"Menu:") for i,e in ipairs(menuList) do + if vTx == 2 and i == 3 then break end if menuActive == i then - lcd.drawText(x+36,y+(i-1)*8+3,e.t,INVERS) + if vTx == 2 and i == 3 then break end + lcd.drawText(x+33,y+(i-1)*8+3,e.t,INVERS) else - lcd.drawText(x+36,y+(i-1)*8+3,e.t) + lcd.drawText(x+33,y+(i-1)*8+3,e.t) end end end +local function getFieldFlags(p) +local flg = 0 +if activeField==p then + flg=INVERS + if editMode then + flg=INVERS+BLINK + end +end +return flg +end + +local function drawEditMenu() +currentLine = 1 +local x = 6 +local y = 12 +local w = 120 +local h = 38 +lcd.drawFilledRectangle(x-2,y-2,w+4,h+4,ERASE) +lcd.drawRectangle(x-2,y-2,w+3,h+3,SOLID) +lcd.drawRectangle(x,y,w-1,h-1,SOLID) +lcd.drawFilledRectangle(x+2,y+2,w-5,10, SOLID) +lcd.drawText(x+5,y+3,CP.title.." Set: ",INVERS) +lcd.drawText(lcd.getLastPos() + 20, y+3, currentLine, INVERS) +lcd.drawText(x+4,y+16,"Name: ") +for i = 0,9 do + lcd.drawText ( x+36+i*6,y+16,CPvN[i+1],getFieldFlags(i)) +end +lcd.drawText(x+5, y+26, "[SAVE NAME]", getFieldFlags(10)) +lcd.drawText(x+75, y+26, "[..LOAD..]", getFieldFlags(11)) + +end + local function getDefaultTextOptions() return 0 end diff --git a/src/X9/KISS/alarms.lua b/src/X9/KISS/alarms.lua index 844172d..3384b08 100644 --- a/src/X9/KISS/alarms.lua +++ b/src/X9/KISS/alarms.lua @@ -24,5 +24,9 @@ return { fields = { { t = "VBat", x = 15, y = 25, sp = 30, i=1, min=0, max=26000, prec=1 }, { t = "mAH", x = 120, y = 25, sp = 30, i=2, min=0, max=26000, inc=10 } - } + }, + wrName = {}, + dL = 10, + data = {}, + defValues = "Default___14400 1000" } diff --git a/src/X9/KISS/filters.lua b/src/X9/KISS/filters.lua index c7335f3..9c29d2d 100644 --- a/src/X9/KISS/filters.lua +++ b/src/X9/KISS/filters.lua @@ -51,5 +51,9 @@ return { { x = 145, y = 38, i=6, min=0, max=490 }, { x = 35, y = 52, i=7, min=1, max=7, table = { "Off", "High", "Med. High", "Medium", "Med. Low", "Low", "Very Low" } }, { x = 145, y = 52, i=8, min=0, max=97}, - } + }, + wrName = {}, + dL = 40, + data = {}, + defValues = "Default___ 1 200 100 1 200 100 1 35" } diff --git a/src/X9/KISS/memory.lua b/src/X9/KISS/memory.lua new file mode 100644 index 0000000..933b11e --- /dev/null +++ b/src/X9/KISS/memory.lua @@ -0,0 +1,20 @@ +return { + title = " Names", + text = { + { t = "1:", x = 10, y = 13 }, + { t = "2:", x = 10, y = 23 }, + { t = "3:", x = 10, y = 33 }, + { t = "4:", x = 10, y = 43 }, + { t = "5:", x = 10, y = 53 } + }, + fields = { + -- model data + {t="1", d="", x = 20, y = 13, sp = 12, i=1, min=1, max=500 }, + {t="2", d="", x = 20, y = 23, sp = 12, i=2, min=1, max=500 }, + {t="3", d="", x = 20, y = 33, sp = 12, i=3, min=0, max=600 }, + {t="4", d="", x = 20, y = 43, sp = 12, i=4, min=0, max=600 }, + {t="5", d="", x = 20, y = 53, sp = 12, i=5, min=0, max=600 } + }, + read = select_model_load, + write = select_model_save +} diff --git a/src/X9/KISS/pids.lua b/src/X9/KISS/pids.lua index ed2d4b8..ce681b1 100644 --- a/src/X9/KISS/pids.lua +++ b/src/X9/KISS/pids.lua @@ -44,5 +44,9 @@ return { { x = 35, y = 50, i=7, max=65000, prec=2 }, { x = 90, y = 50, i=8, max=65000, prec=3 }, { x = 145, y = 50, i=9, max=65000, prec=2 } - } + }, + wrName = {}, + dL = 45, + data = {}, + defValues = "Default___ 3000 3510000 3000 3510000 8000 50 0" } diff --git a/src/X9/KISS/rates.lua b/src/X9/KISS/rates.lua index 8ddf7cf..78049e1 100644 --- a/src/X9/KISS/rates.lua +++ b/src/X9/KISS/rates.lua @@ -9,7 +9,6 @@ return { end return ret end, - preWrite = function(values) local ret = {} for i=1,9 do @@ -41,5 +40,9 @@ return { { x = 35, y = 50, i=7, max=65000, prec=2 }, { x = 90, y = 50, i=8, max=65000, prec=2 }, { x = 145, y = 50, i=9, max=65000, prec=2 } - } + }, + wrName = {}, + dL = 45, + data = {}, + defValues= "Default___ 70 70 40 70 70 40 70 70 40" } diff --git a/src/X9/KISS/tpa.lua b/src/X9/KISS/tpa.lua index 26c071c..f1932fd 100644 --- a/src/X9/KISS/tpa.lua +++ b/src/X9/KISS/tpa.lua @@ -51,5 +51,9 @@ return { { x = 90, y = 53, i=8, max=100}, { x = 120, y = 53, i=9, max=100}, { x = 150, y = 53, i=10,max=100}, - } + }, + wrName = {}, + dL = 50, + data = {}, + defValues = "Default___ 40 20 40 1 30 50 30 0 0 100" } diff --git a/src/X9/KISS/vtx.lua b/src/X9/KISS/vtx.lua index 6f9b81a..bcb8adb 100644 --- a/src/X9/KISS/vtx.lua +++ b/src/X9/KISS/vtx.lua @@ -26,9 +26,9 @@ return { title = "VTX", text = {}, fields = { - { t = "Band", x = 15, y = 25, sp = 60, i=2, min=1, max=5, table = { "A", "B", "E", "FS", "RB" } }, - { t = "Channel", x = 110, y = 25, sp = 70, i=3, min=1, max=8 }, - { t = "Low Power", x = 15, y = 38, sp = 60, i=4, min=0, max=800 }, - { t = "High Power", x = 110, y = 38, sp = 70, i=5, min=0, max=800 } + { t = "Band", x = 15, y = 25, sp = 60, i=2, min=1, max=5, table = { "A", "B", "E", "FS", "RB" } }, + { t = "Channel", x = 110, y = 25, sp = 70, i=3, min=1, max=8 }, + { t = "Low Power", x = 15, y = 38, sp = 60, i=4, min=0, max=800 }, + { t = "High Power", x = 110, y = 38, sp = 70, i=5, min=0, max=800 } } } diff --git a/src/X9/Kiss.lua b/src/X9/Kiss.lua index 3bd2aeb..c364a3a 100644 --- a/src/X9/Kiss.lua +++ b/src/X9/Kiss.lua @@ -1,10 +1,19 @@ - -- BEGIN X9 + + RADIO = "X9" -local drawScreenTitle = function(title, currentPage, totalPages) - lcd.drawScreenTitle('Kiss Setup: '..title, currentPage, totalPages) +local drawScreenTitle = function(title, cPage, tPages) + local str + if cPage == #(AllPages) then + str = "Mem: "..CP.title + cPage = 0 + tPages = 0 + else + str = "Kiss Setup: " + end + lcd.drawScreenTitle(str..title, cPage, tPages) end local drawTelemetry = function() @@ -18,21 +27,58 @@ local drawSaving = function() end local function drawMenu(menuList, menuActive) - local x = 40 - local y = 12 - local w = 120 - local h = #(menuList) * 8 + 6 - lcd.drawFilledRectangle(x,y,w,h,ERASE) - lcd.drawRectangle(x,y,w-1,h-1,SOLID) - lcd.drawText(x+4,y+3,"Menu:") - - for i,e in ipairs(menuList) do - if menuActive == i then - lcd.drawText(x+36,y+(i-1)*8+3,e.t,INVERS) - else - lcd.drawText(x+36,y+(i-1)*8+3,e.t) - end - end + local vTx +if ActivePage.title== "VTX" then vTx = 2 else vTx = #(menuList) end + +local x = 30 +local y = 11 +local w = 150 +local h = vTx * 8 + 10 +lcd.drawFilledRectangle(x-2,y-2,w+4,h+4,ERASE) +lcd.drawRectangle(x-2,y-2,w+3,h+3,SOLID) +lcd.drawRectangle(x,y,w-1,h-1,SOLID) +lcd.drawText(x+4,y+3,"Menu: ", INVERS) + +for i,e in ipairs(menuList) do + if vTx == 2 and i == 3 then break end + if menuActive == i then + lcd.drawText(x+50,y+(i-1)*9+3,e.t,INVERS) + else + lcd.drawText(x+50,y+(i-1)*9+3,e.t) + end +end +end + +local function getFieldFlags(p) +local flg = 0 +if activeField==p then + flg=INVERS + if editMode then + flg=INVERS+BLINK + end +end +return flg +end + +local function drawEditMenu() +currentLine = 1 +local x = 25 +local y = 14 +local w = 170 +local h = 38 +lcd.drawFilledRectangle(x-2,y-2,w+4,h+4,ERASE) +lcd.drawRectangle(x-2,y-2,w+3,h+3,SOLID) +lcd.drawRectangle(x,y,w-1,h-1,SOLID) +lcd.drawFilledRectangle(x+2,y+2,w-5,10, SOLID) +lcd.drawText(x+5,y+3,CP.title.." Set: ",INVERS) +lcd.drawText(lcd.getLastPos() + 20, y+3, currentLine, INVERS) +lcd.drawText(x+4,y+16,"Name: ") +for i = 0,9 do + lcd.drawText ( x+36+i*6,30,CPvN[i+1],getFieldFlags(i)) +end +lcd.drawText(x+105, y+16, "[SAVE NAME]", getFieldFlags(10)) +lcd.drawText(x+114, y+26, "[..LOAD..]", getFieldFlags(11)) + end local function getDefaultTextOptions() diff --git a/src/common/KissProtocolCF.lua b/src/common/KissProtocolCF.lua index 945d01f..93e7a45 100644 --- a/src/common/KissProtocolCF.lua +++ b/src/common/KissProtocolCF.lua @@ -11,6 +11,15 @@ FC_RESPONSE_COMMAND = 0x79 local kissLastReq = 0 local kissTxBuf = {} ++local CP = {} ++local AP = {} ++local CPvN = {} ++local sVal ++local APValues = {} ++local nL = 10 --DataSet Name Length ++local payload ++local activeField = 0 + local function isTelemetryPresent() return true end diff --git a/src/common/KissProtocolSPort.lua b/src/common/KissProtocolSPort.lua index c321cce..f6a6b89 100644 --- a/src/common/KissProtocolSPort.lua +++ b/src/common/KissProtocolSPort.lua @@ -29,6 +29,15 @@ local kissTxIdx = 1 local kissTxCRC = 0 local kissTxPk = 0 +local CP = {} +local AP = {} +local CPvN = {} +local sVal +local APValues = {} +local nL = 10 --DataSet Name Length +local payload +local activeField = 0 + local function isTelemetryPresent() return getValue("RSSI")>0 end @@ -230,4 +239,4 @@ local function kissPollReply() return nil end --- SPORT END +-- SPORT END \ No newline at end of file diff --git a/src/common/KissUI.lua b/src/common/KissUI.lua index d65cc19..b009fdc 100644 --- a/src/common/KissUI.lua +++ b/src/common/KissUI.lua @@ -1,4 +1,3 @@ - -- BEGIN UI local currentPage = 1 @@ -15,6 +14,10 @@ local PAGE_DISPLAY = 2 local EDITING = 3 local PAGE_SAVING = 4 local MENU_DISP = 5 +local MODEL_WRITE = 6 +local MODEL_LOAD = 7 +local MODEL_EDIT = 8 +local MENU_NAME = 9 local telemetryScreenActive = false local menuActive = false @@ -23,7 +26,7 @@ local lastRunTS = 0 local gState = PAGE_DISPLAY ActivePage = nil -AllPages = { "pids", "rates", "tpa", "filters", "alarms", "vtx" } +AllPages = { "pids", "rates", "tpa", "filters", "alarms", "vtx", "memory" } local function formatKissFloat(v, d) local s = string.format("%0.4d", v); @@ -76,15 +79,161 @@ end local function loadPage(pageId) local file = "/SCRIPTS/TELEMETRY/KISS/"..AllPages[pageId]..".lua" + AP = ActivePage clearTable(ActivePage) local tmp = assert(loadScript(file)) ActivePage = tmp() end +--set state and open DataType select Page to save +local function openSaveMenu() +gState = MODEL_WRITE + local page = ActivePage --AllPages[currentPage] + if page.values then + --if page.getWriteValues then + payload = page.Values + currentPage = #(AllPages) + currentLine = 1 + loadPage(currentPage) + --end + end +end + +local function readModel(modelNum) +loadPage(PREV_PAGE) +local val = CP.data[modelNum] +ActivePage.values = val +end + +--set state and open DataType select Page to load +local function openLoadMenu() +gState = MODEL_LOAD +currentPage = #(AllPages) -- goto LoadList +currentLine = 1 -- set Line 1 +loadPage(currentPage) +end + +local function openEditMenu() +gState = MODEL_EDIT +currentPage = #(AllPages) -- goto LoadList +currentLine = 1 -- set Line 1 +loadPage(currentPage) +end + +local function tableToString(v) +local vStr +vStr = v[1] +for i = 2,#(v) do + vStr = vStr..v[i] +end +return vStr +end + +local function getMemData(fileNum) + +local file = "/SCRIPTS/TELEMETRY/KISS/"..AllPages[fileNum]..".lua" + clearTable(CP) + local tmp = assert(loadScript(file)) + CP = tmp() + +local dLen = CP.dL +local f = io.open("/SCRIPTS/TELEMETRY/KISS/"..CP.title, "r") +io.seek(f,0) + +for i = 1,5 do +io.seek(f,(i-1)*(nL+dLen)) +CP.wrName[i] = io.read(f,nL) +var = {} + for j = 1,dLen/5 do + io.seek(f,nL+(i-1)*(nL+dLen)+(j-1)*5) + var[j] = tonumber(io.read(f,5)) + end + CP.data[i] = var +end +io.close(f) +end + local menuList = { - { t = "save page", f = saveSettings }, { t = "reload", f = invalidatePage } +{ t = "Send to FC", f = saveSettings }, { t = "Restore from FC", f = invalidatePage }, { t = "Edit Files", f = openEditMenu }, { t = "Save to File", f = openSaveMenu }, { t = "Load from File", f = openLoadMenu } } +local function writeToFile(values, fName) +if values then +local f = io.open("/SCRIPTS/TELEMETRY/KISS/"..fName, "w") +if type(values) == "table" then + v = string.format("%5d",values[1]) + for i = 2,#(values) do + v = v..string.format("%5d",values[i]) + end +else + v = values +end +io.write(f,v) +io.close(f) +end +end + +local function savePageValues(values) +if values then +if type(values) == "table" then + v = string.format("%5d",values[1]) + for i = 2,#(values) do + v = v..string.format("%5d",values[i]) + end +else + v = values +end + +return v +end +end + +local function saveValues( mN, newName) + local file = "/SCRIPTS/TELEMETRY/KISS/"..AllPages[PREV_PAGE]..".lua" + clearTable(SP) + local tmp = assert(loadScript(file)) + SP = tmp() + + local dLen = SP.dL + local f = io.open("/SCRIPTS/TELEMETRY/KISS/"..SP.title, "r") + if newName == nil then + n = CP.wrName[mN] + else + n = newName + end + if mN == 1 then + s = n + else + s = io.read(f,(dLen+nL)*(mN-1))..n + end + s = s..sVal + io.seek(f,mN*(dLen+nL)) + s = s..io.read(f,(dLen+nL)*(5-mN)) + io.close(f) + f = io.open("/SCRIPTS/TELEMETRY/KISS/"..SP.title, "w") + io.write(f,s) + io.close(f) +end + +local function init() +local str +local ret = {} +for i = 1,#(AllPages)-2 do + loadPage(i) + local f = io.open("/SCRIPTS/TELEMETRY/KISS/"..ActivePage.title, "r") + if not f then + f = io.open("/SCRIPTS/TELEMETRY/KISS/"..ActivePage.title, "a") + for j = 1,5 do --number of available saved values sets + io.write(f,ActivePage.defValues) + end + io.close(f) + else + io.close(f) + end +end +loadPage(1) +end + local function processKissReply(cmd, rx_buf) if cmd == nil or rx_buf == nil then @@ -130,7 +279,7 @@ local function changeWithLimit(value, direction, min, max) end local function incPage(inc) - currentPage = changeWithLimit(currentPage, inc, 1, #(AllPages)) + currentPage = changeWithLimit(currentPage, inc, 1, #(AllPages)-1) loadPage(currentPage) end @@ -142,6 +291,37 @@ local function incMenu(inc) menuActive = changeWithLimit(menuActive, inc, 1, #(menuList)) end +local function valueIncDec(event,value,min,max,step) + if editMode then + if event == EVT_PLUS_FIRST or event == EVT_ROT_RIGHT or event==EVT_PLUS_REPT then + if value<=max-step then + value=value+step + else + value = min + end + elseif event == EVT_MINUS_FIRST or event == EVT_ROT_LEFT or event==EVT_MINUS_REPT then + if value>=min+step then + value=value-step + else + value = max + end + end +end +return value +end + +local function fieldIncDec(event,value,max,force) + if editMode or force==true then + if event==EVT_PLUS_FIRST or event == EVT_ROT_RIGHT then + value=value+max + elseif event==EVT_MINUS_FIRST or event == EVT_ROT_LEFT then + value=value+max+2 + end + value=value%(max+1) + end +return value +end + local function requestPage() if ActivePage.read and ((ActivePage.reqTS == nil) or (ActivePage.reqTS + REQ_TIMEOUT <= getTime())) then ActivePage.reqTS = getTime() @@ -151,7 +331,7 @@ end local function drawScreen(page_locked) - drawScreenTitle(ActivePage.title, currentPage, #(AllPages)) + drawScreenTitle(ActivePage.title, currentPage, #(AllPages)-1) for i=1,#(ActivePage.text) do local f = ActivePage.text[i] @@ -183,7 +363,12 @@ local function drawScreen(page_locked) local spacing = 20 if f.t ~= nil then - lcd.drawText(f.x, f.y, f.t .. ":", getDefaultTextOptions()) + if currentPage == #(AllPages) and gState >= 6 then + lcd.drawText(f.x, f.y, CP.wrName[i] , text_options) + else + lcd.drawText(f.x, f.y, f.t .. ":", getDefaultTextOptions()) + end + end -- draw some value @@ -204,7 +389,9 @@ local function drawScreen(page_locked) lcd.drawText(f.x + spacing, f.y, val, text_options) else - lcd.drawText(f.x + spacing, f.y, "---", text_options) + if currentPage ~= #(AllPages) then + lcd.drawText(f.x + spacing, f.y, "---", text_options) + end end end @@ -240,6 +427,7 @@ local function incValue(inc) end ActivePage.values[idx] = clipValue(ActivePage.values[idx] + tmpInc, field.min or 0, field.max or 255) + end local function run(event) @@ -249,7 +437,9 @@ local function run(event) end local now = getTime() - + if currentPage < #AllPages then + PREV_PAGE = currentPage + end -- if lastRunTS old than 500ms if lastRunTS + 50 < now then invalidatePage() @@ -271,14 +461,18 @@ local function run(event) end -- navigation + if event == EVT_MENU_LONG then menuActive = 1 + sVal = savePageValues(ActivePage.values) + tmpModelNum = modelNum gState = MENU_DISP elseif EVT_PAGEUP_FIRST and (event == EVT_ENTER_LONG) then menuActive = 1 killEnterBreak = 1 gState = MENU_DISP + PREV_PAGE = currentPage -- menu is currently displayed elseif gState == MENU_DISP then @@ -289,18 +483,61 @@ local function run(event) elseif event == EVT_MINUS_BREAK or event == EVT_ROT_RIGHT then incMenu(1) elseif event == EVT_ENTER_BREAK then - if RADIO == "HORUS" then - if killEnterBreak == 1 then - killEnterBreak = 0 - else - gState = PAGE_DISPLAY - menuList[menuActive].f() - end + if menuActive ==3 then + gState = MENU_NAME + + if RADIO == "HORUS" then + if killEnterBreak == 1 then + killEnterBreak = 0 + end + end else gState = PAGE_DISPLAY - menuList[menuActive].f() + end + + if menuActive >= 3 then getMemData(PREV_PAGE) end + menuList[menuActive].f() + end + + --menu2 - pid model name change screen is displayed + elseif gState == MENU_NAME then + + if event == EVT_ENTER_BREAK then + editMode = not editMode + elseif event == EVT_EXIT_BREAK then + currentPage = PREV_PAGE + loadPage(PREV_PAGE) + --readModel ( tmpModelNum ) + gState = MODEL_EDIT + end + if editMode then + if activeField <= 9 then + CPvN[activeField+1] = string.char(valueIncDec(event, string.byte(CPvN[activeField+1]), 34, 127, 1)) + elseif activeField == 10 then + activeField = 0 + sVal = savePageValues(CP.data[modelNum]) + saveValues(modelNum, tableToString(CPvN)) + currentPage = PREV_PAGE + loadPage(PREV_PAGE) + gState = PAGE_DISPLAY + --readModel ( tmpModelNum ) + currentLine=1 + editMode = not editMode + + elseif activeField == 11 then + activeField = 0 + modelNum = currentLine + editMode = not editMode + currentPage = PREV_PAGE + gState = PAGE_DISPLAY + readModel ( modelNum ) + currentLine=1 + end + else + activeField = fieldIncDec(event, activeField, 11, true) + end -- normal page viewing elseif gState <= PAGE_DISPLAY then if event == EVT_PAGEUP_FIRST then @@ -331,6 +568,41 @@ local function run(event) elseif event == EVT_MINUS_REPT then incValue(-10) end +--READ/WRITE values to assigned Page and Line(Model)Number (ie: PIDS, Rates etc) +elseif gState >= 6 and gState < 9 then + if event == EVT_ENTER_BREAK then + modelNum = currentLine + --CP = SetupPages[PREV_PAGE] + for i = 1,#(CP.wrName[currentLine]) do + CPvN[i] = string.sub(CP.wrName[currentLine],i,i) + end + if gState == MODEL_WRITE then + currentPage = PREV_PAGE + saveValues(modelNum) + gState = PAGE_DISPLAY + currentLine=1 + getMemData(PREV_PAGE) + readModel(modelNum) + + elseif gState == MODEL_LOAD then + currentPage = PREV_PAGE + readModel(modelNum) + gState = PAGE_DISPLAY + currentLine=1 + elseif gState == MODEL_EDIT then + gState = MENU_NAME + end + elseif event == EVT_PLUS_FIRST or event == EVT_PLUS_REPT or event == EVT_ROT_RIGHT then + incLine(1) + elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_REPT or event == EVT_ROT_LEFT then + incLine(-1) + elseif event == EVT_EXIT_BREAK then + currentPage = PREV_PAGE + loadPage(PREV_PAGE) + gState = PAGE_DISPLAY + + + end end local page_locked = false @@ -350,6 +622,8 @@ local function run(event) if gState == MENU_DISP then drawMenu(menuList, menuActive) + elseif gState == MENU_NAME then + drawEditMenu() elseif gState == PAGE_SAVING then drawSaving() end @@ -358,6 +632,6 @@ local function run(event) return 0 end -return {run=run} +return {init=init, run=run} --- END UI +-- END UI \ No newline at end of file