Skip to content

Commit

Permalink
New version
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Mar 7, 2022
1 parent d04fe3e commit ccf2182
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 1 deletion.
Binary file added flvss/battery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added flvss/lowbat.wav
Binary file not shown.
2 changes: 1 addition & 1 deletion flvss/main.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
local a={en="Lua FLVSS",fr="FLVSS Lua"}local b=0;local c="1.0.0.1"local function d(e,f)e=tonumber(e)b=b*0.9+e*0.1;local g={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,8,8,9,9,10,12,13,14,17,19,20,22,23,26,28,30,33,36,39,42,45,48,51,54,57,58,60,62,64,66,67,69,70,72,74,75,77,78,80,81,82,84,85,86,86,87,88,89,91,92,94,95,96,97,97,99,100}f=tonumber(f)if f>0 then local h=3;local i=0;local j=1;e=e*100;h=e/f;j=math.floor(h-298)if j>120 then j=120 end;if j<1 then j=1 end;return g[j]end end;local function k(l)if l<=100 and l>=75 then lcd.color(lcd.RGB(128,192,16))elseif l<=75 and l>=50 then lcd.color(lcd.RGB(250,152,5))elseif l<=50 and l>=25 then lcd.color(lcd.RGB(250,225,5))else lcd.color(lcd.RGB(255,0,0))end end;local function m(n,o,p,q,r,l,s,t)lcd.color(lcd.RGB(40,40,40))lcd.drawCircle(n,o,p)k(l)local u=p+5;lcd.drawAnnulusSector(n,o,0,u,q,r)lcd.color(lcd.RGB(255,255,255))lcd.drawCircle(n,o,p-5)lcd.color(lcd.RGB(40,40,40))lcd.drawFilledCircle(n,o,p-6)lcd.font(FONT_S)lcd.color(lcd.RGB(255,255,255))if s then lcd.drawText(n+3,o-7,l.."%",CENTERED)else lcd.drawText(n+3,o-7,t,CENTERED)end end;local function v(w)local y=system.getLocale()return a[y]or a["en"]end;local function z()local A=system.getSource("LiPo")return{sensor=A,value=nil}end;local function B(w)return{{"FLVSS v"..c,function()end}}end;local function C(w)if w.sensor~=nil then local D=40;local E=32;local F,G=lcd.getWindowSize()local l=d(w.sensor:value(),w.sensor:stringValue(OPTION_CELL_COUNT))local H=l/100*360;local I=10;local J=(E+I)*w.sensor:value(OPTION_CELL_COUNT)local K=0;m(60,J*0.1+25+K,35,0,H,l,true,w.sensor:stringValue())lcd.font(FONT_S)lcd.drawText(110,J*0.1+10,w.sensor:stringValue(OPTION_CELL_COUNT).." cells")lcd.font(FONT_L_BOLD)k(l)lcd.drawText(110,J*0.1+30,w.sensor:stringValue())x=60;D=J*0.1+130+K;for j=1,w.sensor:value(OPTION_CELL_COUNT)do local L=d(w.sensor:value(OPTION_CELL_INDEX(j)),1)local M=L/100*360;lcd.font(FONT_XS)if x>=F then x=60;D=D+70 end;m(x,D,30,0,H,l,false,w.sensor:stringValue(OPTION_CELL_INDEX(j)))x=x+87 end end end;local function N(w)local O=nil;if w.sensor==nil then w.sensor=system.getSource("LiPo")end;if w.sensor~=nil then O=w.sensor:stringValue()end;if w.value~=O then w.value=O;lcd.invalidate()end end;local function P()system.registerWidget({key="flvss",name=v,create=z,paint=C,wakeup=N,menu=B})end;return{init=P}
local a={en="iOs style FLVSS"}local b=0;local c=0;local d;local e={{"-",0},{"--",1},{"---",2},{"------",3},{".",4},{"..",5},{"...",6},{".....",7},{".-",8},{"..-",9},{".-.",10},{"-.-",11}}local function f(h)for i,j in ipairs(e)do if j[2]==h then system.playHaptic(j[1])break end end end;local function k(l,m)l=tonumber(l)b=b*0.9+l*0.1;local n={0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,8,8,9,9,10,12,13,14,17,19,20,22,23,26,28,30,33,36,39,42,45,48,51,54,57,58,60,62,64,66,67,69,70,72,74,75,77,78,80,81,82,84,85,86,86,87,88,89,91,92,94,95,96,97,97,99,100}m=tonumber(m)if m>0 then local o=3;local p=0;local i=1;l=l*100;o=l/m;i=math.floor(o-298)if i>120 then i=120 end;if i<1 then i=1 end;return n[i]end end;local function q(s)g=math.floor(0xDF*s/100)r=0xDF-g;lcd.color(lcd.RGB(r,g,0))end;local function t(u,v,w,y,z,A,B,C)lcd.color(lcd.RGB(40,40,40))lcd.drawCircle(u,v,w)local D=w+5;q(A)lcd.drawAnnulusSector(u,v,0,D,y,z)lcd.color(lcd.RGB(255,255,255))lcd.drawCircle(u,v,w-5)lcd.color(lcd.RGB(40,40,40))lcd.drawFilledCircle(u,v,w-6)lcd.font(FONT_XS_BOLD)lcd.color(lcd.RGB(255,255,255))if B then lcd.drawText(u+3,v-7,A.."%",CENTERED)else lcd.drawText(u+3,v-7,C,CENTERED)end end;local function E(Me,F)count=count+1;local G=40;local H=32;local I,J=lcd.getWindowSize()local A=k(F.LipoSensor:value(),F.LipoSensor:stringValue(OPTION_CELL_COUNT))local K=A/100*360;local L=10;local M=(H+L)*F.LipoSensor:value(OPTION_CELL_COUNT)local N=0;x=I/2;G=J/2;local m=tonumber(F.LipoSensor:stringValue(OPTION_CELL_COUNT))t(60,M*0.1+25+N,35,0,K,A,true,F.LipoSensor:stringValue())lcd.font(FONT_S)lcd.drawText(110,M*0.1+10,F.LipoSensor:stringValue(OPTION_CELL_COUNT).." cells")lcd.font(FONT_L_BOLD)q(A)lcd.drawText(110,M*0.1+30,F.LipoSensor:stringValue())x=60;G=M*0.1+110+N;for i=1,F.LipoSensor:value(OPTION_CELL_COUNT)do local O=k(F.LipoSensor:value(OPTION_CELL_INDEX(i)),1)local P=O/100*360;lcd.font(FONT_XS)if x>=I then x=60;G=G+80 end;t(x,G,30,0,K,A,false,F.LipoSensor:stringValue(OPTION_CELL_INDEX(i)))x=x+87 end;if count>lowBattCycleTime*3.3 then if battAlertOnOff==true and lipoPackVoltage<lowBattAlert/10 then print("Battery drained")system.playFile("/scripts/flvss/lowbat.wav")if F.enableHaptic==true then f(F.fieldPattern)end end;count=0 end end;local function Q(Me)lcd.color(WHITE)local R,S=lcd.getWindowSize()lcd.drawText(R*0.35,S*0.30,"Please")lcd.drawText(R*0.35,S*0.45,"Setup")lcd.drawText(R*0.35,S*0.60,"LiPo sensor.")end;local function T()local U={{label="Close",action=function()end}}form.openDialog("About flvss","Version "..d.."\n".."iOS style flvss".."\n".."(c) 2022 William Mayvis\n".."For more information\n".."https://github.com/wmayvis/FrSky-Lua",U)end;local function V(F)local W=system.getLocale()return a[W]or a["en"]end;local function X()return{r=255,g=255,b=255,OnOff=false,source=nil,min=-1024,max=1024,value=0,LowBattCycleTime=5,BattAlertOnOff=true,LowBattAlert=30,LipoSensor=nil,enableHaptic=false}end;local function Y(F)return{{"FLVSS V"..d,function()end},{"About",function()T()end}}end;local function Z(F)if Init==false then Init=true end;battAlertOnOff=F.enableBattAlert;lowBattAlert=F.LowBattAlert;lowBattCycleTime=F.LowBattCycleTime;if F.LipoSensor~=nil then if F.LipoSensor:name()~="---"then numberOffCells=F.LipoSensor:stringValue(OPTION_CELL_COUNT)lipoPackVoltage=F.LipoSensor:value()E(Me,F)else Q(Me)end else Q(Me)end end;local function _(F)newValue=os.clock()if newValue>c then c=newValue;lcd.invalidate()end end;local function a0(F)line=form.addLine("Low battery parameters:")line=form.addLine("Low battery warning")local a1=form.getFieldSlots(line,{0})F.battAlertField=form.addBooleanField(line,form.getFieldSlots(line)[0],function()return F.enableBattAlert end,function(h)F.enableBattAlert=h;F.field_alertVolt:enable(h)F.field_AlertRate:enable(h)F.field_haptic:enable(h)end)line=form.addLine("Batt Alert (x0.1V)")local a2=form.getFieldSlots(line,{0})F.field_alertVolt=form.addNumberField(line,a2[1],1,252,function()return F.LowBattAlert end,function(h)F.LowBattAlert=h end)F.field_alertVolt:enable(F.enableBattAlert)line=form.addLine("Low battery cycle time (s)")a2=form.getFieldSlots(line,{0})F.field_AlertRate=form.addNumberField(line,a2[1],1,10,function()return F.LowBattCycleTime end,function(h)F.LowBattCycleTime=h end)F.field_AlertRate:enable(F.enableBattAlert)line=form.addLine("Haptic Selection:")line=form.addLine("Enable")local a3=form.getFieldSlots(line,{0})F.field_haptic=form.addBooleanField(line,form.getFieldSlots(line)[0],function()return F.enableHaptic end,function(h)F.enableHaptic=h;F.fieldPattern:enable(F.enableHaptic)end)F.field_haptic:enable(F.enableBattAlert)line=form.addLine("Pattern")local a4=form.getFieldSlots(line,{0})F.fieldPattern=form.addChoiceField(line,form.getFieldSlots(line)[0],e,function()return F.fieldPattern end,function(h)f(h)F.fieldPattern=h end)F.fieldPattern:enable(F.enableHaptic)line=form.addLine("Sensor Selection:")line=form.addLine("Lipo Sensor")form.addSourceField(line,nil,function()return F.LipoSensor end,function(h)F.LipoSensor=h end)line=form.addLine("iOs style flvss")line=form.addLine("Version : V"..d)end;local function a5(F)F.enableBattAlert=storage.read("BattAlertOnOff")F.LowBattAlert=storage.read("LowBattAlert")F.LowBattCycleTime=storage.read("LowBattCycleTime")F.LipoSensor=storage.read("LipoSensor")F.enableHaptic=storage.read("enableHaptic")F.fieldPattern=storage.read("fieldPattern")end;local function a6(F)storage.write("BattAlertOnOff",F.enableBattAlert)storage.write("LowBattAlert",F.LowBattAlert)storage.write("LowBattCycleTime",F.LowBattCycleTime)storage.write("LipoSensor",F.LipoSensor)storage.write("enableHaptic",F.enableHaptic)storage.write("fieldPattern",F.fieldPattern)end;local function a7()cellsLowbatterySound="/scripts/flvss/lowbat.wav"count=0;d="1.0.2"system.registerWidget({key="flvss",name=V,create=X,paint=Z,wakeup=_,menu=Y,configure=a0,read=a5,write=a6})Init=false end;return{init=a7}

0 comments on commit ccf2182

Please sign in to comment.