diff --git a/sdcard/SCRIPTS/BF/protocols.lua b/sdcard/SCRIPTS/BF/protocols.lua index 47a5179c..6bf76f07 100644 --- a/sdcard/SCRIPTS/BF/protocols.lua +++ b/sdcard/SCRIPTS/BF/protocols.lua @@ -1 +1 @@ -supportedProtocols={smartPort={transport=SCRIPT_HOME.."/MSP/sp.lua",rssi=function()return getValue("RSSI")end,exitFunc=function()return 0 end,push=sportTelemetryPush,maxTxBufferSize=6,maxRxBufferSize=6,saveMaxRetries=2,saveTimeout=150},crsf={transport=SCRIPT_HOME.."/MSP/crsf.lua",rssi=function()return getValue("TQly")end,exitFunc=function()return"/CROSSFIRE/crossfire.lua"end,push=crossfireTelemetryPush,maxTxBufferSize=8,maxRxBufferSize=58,saveMaxRetries=2,saveTimeout=150}}function getProtocol()if supportedProtocols.smartPort.push()then return supportedProtocols.smartPort elseif supportedProtocols.crsf.push()then return supportedProtocols.crsf end end;local a=getProtocol()if not a then error("Telemetry protocol not supported!")end;return a +supportedProtocols={smartPort={transport=SCRIPT_HOME.."/MSP/sp.lua",rssi=function()return getValue("RSSI")end,exitFunc=function()return 0 end,push=sportTelemetryPush,maxTxBufferSize=6,maxRxBufferSize=6,saveMaxRetries=2,saveTimeout=300},crsf={transport=SCRIPT_HOME.."/MSP/crsf.lua",rssi=function()return getValue("TQly")end,exitFunc=function()return"/CROSSFIRE/crossfire.lua"end,push=crossfireTelemetryPush,maxTxBufferSize=8,maxRxBufferSize=58,saveMaxRetries=2,saveTimeout=150}}function getProtocol()if supportedProtocols.smartPort.push()then return supportedProtocols.smartPort elseif supportedProtocols.crsf.push()then return supportedProtocols.crsf end end;local a=getProtocol()if not a then error("Telemetry protocol not supported!")end;return a diff --git a/sdcard/SCRIPTS/BF/ui.lua b/sdcard/SCRIPTS/BF/ui.lua index 16daa0af..6c205182 100644 --- a/sdcard/SCRIPTS/BF/ui.lua +++ b/sdcard/SCRIPTS/BF/ui.lua @@ -1 +1 @@ -local a=assert(loadScript(SCRIPT_HOME.."/events.lua"))()local b={display=2,editing=3,saving=4,displayMenu=5}local c={reboot=68,eepromWrite=250}local d=b.display;local e=80;local f=1;local g=1;local h=0;local i=0;local j=0;local k=0;local l=false;local m=false;local n=false;local o=0;local p=0;Page=nil;backgroundFill=backgroundFill or ERASE;foregroundColor=foregroundColor or SOLID;globalTextOptions=globalTextOptions or 0;local function q(r)if Page.values then if Page.preSave then Page.preSave(Page)end;protocol.mspWrite(Page.write,Page.values)h=getTime()if d==b.saving then j=j+1 else d=b.saving;j=0;k=protocol.saveMaxRetries or 2;i=protocol.saveTimeout or 150 end end end;local function s()Page=nil;d=b.display;h=0 end;local function t()protocol.mspRead(c.reboot)s()end;local function u()protocol.mspRead(c.eepromWrite)end;local v={{t="save page",f=q},{t="reload",f=s},{t="reboot",f=t}}local function w(x,y)if x==nil or y==nil then return end;if x==Page.write then if Page.eepromWrite then u()end;l=false;return end;if x==c.eepromWrite then if Page.reboot then t()end;s()d=b.display;h=0;return end;if x~=Page.read then return end;if#y>0 then Page.values={}for z=1,#y do Page.values[z]=y[z]end;if Page.postLoad then Page.postLoad(Page)end end end;local function A()return#Page.fields end;local function B(C)f=f+C;if f>#PageFiles then f=1 elseif f<1 then f=#PageFiles end;g=1 end;local function D(C)g=g+C;if g>A()then g=1 elseif g<1 then g=A()end end;local function E(C)n=n+C;if n>#v then n=1 elseif n<1 then n=#v end end;local function F()if Page.read and(Page.reqTS==nil or Page.reqTS+e<=getTime())then Page.reqTS=getTime()protocol.mspRead(Page.read)end end;function drawScreenTitle(G)lcd.drawFilledRectangle(0,0,LCD_W,10)lcd.drawText(1,1,G,INVERS)end;local function H()local G=Page.title;drawScreenTitle("Betaflight / "..G)for z=1,#Page.text do local I=Page.text[z]if I.to==nil then lcd.drawText(I.x,I.y,I.t,globalTextOptions)else lcd.drawText(I.x,I.y,I.t,I.to)end end;local J="---"for z=1,#Page.fields do local I=Page.fields[z]local K=I.to or globalTextOptions;local L=K;local M=K;if z==g then M=K+INVERS;if d==b.editing then M=M+BLINK end end;local N=20;if I.t~=nil then lcd.drawText(I.x,I.y,I.t,L)if I.sp~=nil then N=I.sp end else N=0 end;if Page.values then if(#Page.values or 0)>=Page.minBytes then if not I.value and I.vals then for O=1,#I.vals do I.value=bit32.bor(I.value or 0,bit32.lshift(Page.values[I.vals[O]],(O-1)*8))end;I.value=I.value/(I.scale or 1)end end end;if I.value then if I.upd and Page.values then I.upd(Page)end;J=I.value;if I.table and I.table[I.value]then J=I.table[I.value]end end;lcd.drawText(I.x+N,I.y,J,M)end end;local function P(J,Q,R)if JR then J=R end;return J end;local function S()return Page.fields[g]end;local function T(C)local I=Page.fields[g]local O=I.i or g;local U=I.scale or 1;I.value=P(I.value+C*(I.mult or 1)/U,I.min/U or 0,I.max/U or 255)for O=1,#I.vals do Page.values[I.vals[O]]=bit32.rshift(I.value*U,(O-1)*8)end;if I.upd and Page.values then I.upd(Page)end end;local function V()local W=MenuBox.x;local X=MenuBox.y;local Y=MenuBox.w;local Z=MenuBox.h_line;local _=MenuBox.h_offset;local a0=#v*Z+_*2;lcd.drawFilledRectangle(W,X,Y,a0,backgroundFill)lcd.drawRectangle(W,X,Y-1,a0-1,foregroundColor)lcd.drawText(W+Z/2,X+_,"Menu:",globalTextOptions)for z,a1 in ipairs(v)do local K=globalTextOptions;if n==z then K=K+INVERS end;lcd.drawText(W+MenuBox.x_offset,X+(z-1)*Z+_,a1.t,K)end end;function run_ui(a2)local a3=getTime()if o+500 then Page.values={}for z=1,#y do Page.values[z]=y[z]end;if Page.postLoad then Page.postLoad(Page)end end end;local function A()return#Page.fields end;local function B(C)f=f+C;if f>#PageFiles then f=1 elseif f<1 then f=#PageFiles end;g=1 end;local function D(C)g=g+C;if g>A()then g=1 elseif g<1 then g=A()end end;local function E(C)n=n+C;if n>#v then n=1 elseif n<1 then n=#v end end;local function F()if Page.read and(Page.reqTS==nil or Page.reqTS+e<=getTime())then Page.reqTS=getTime()protocol.mspRead(Page.read)end end;function drawScreenTitle(G)lcd.drawFilledRectangle(0,0,LCD_W,10)lcd.drawText(1,1,G,INVERS)end;local function H()local G=Page.title;drawScreenTitle("Betaflight / "..G)for z=1,#Page.text do local I=Page.text[z]if I.to==nil then lcd.drawText(I.x,I.y,I.t,globalTextOptions)else lcd.drawText(I.x,I.y,I.t,I.to)end end;local J="---"for z=1,#Page.fields do local I=Page.fields[z]local K=I.to or globalTextOptions;local L=K;local M=K;if z==g then M=K+INVERS;if d==b.editing then M=M+BLINK end end;local N=20;if I.t~=nil then lcd.drawText(I.x,I.y,I.t,L)if I.sp~=nil then N=I.sp end else N=0 end;if Page.values then if(#Page.values or 0)>=Page.minBytes then if not I.value and I.vals then for O=1,#I.vals do I.value=bit32.bor(I.value or 0,bit32.lshift(Page.values[I.vals[O]],(O-1)*8))end;I.value=I.value/(I.scale or 1)end end end;if I.value then if I.upd and Page.values then I.upd(Page)end;J=I.value;if I.table and I.table[I.value]then J=I.table[I.value]end end;lcd.drawText(I.x+N,I.y,J,M)end end;local function P(J,Q,R)if JR then J=R end;return J end;local function S()return Page.fields[g]end;local function T(C)local I=Page.fields[g]local O=I.i or g;local U=I.scale or 1;I.value=P(I.value+C*(I.mult or 1)/U,I.min/U or 0,I.max/U or 255)for O=1,#I.vals do Page.values[I.vals[O]]=bit32.rshift(I.value*U,(O-1)*8)end;if I.upd and Page.values then I.upd(Page)end end;local function V()local W=MenuBox.x;local X=MenuBox.y;local Y=MenuBox.w;local Z=MenuBox.h_line;local _=MenuBox.h_offset;local a0=#v*Z+_*2;lcd.drawFilledRectangle(W,X,Y,a0,backgroundFill)lcd.drawRectangle(W,X,Y-1,a0-1,foregroundColor)lcd.drawText(W+Z/2,X+_,"Menu:",globalTextOptions)for z,a1 in ipairs(v)do local K=globalTextOptions;if n==z then K=K+INVERS end;lcd.drawText(W+MenuBox.x_offset,X+(z-1)*Z+_,a1.t,K)end end;function run_ui(a2)local a3=getTime()if o+50