Skip to content

Commit

Permalink
Merge pull request #37 from codecae/revert-36-vtx_presave_fix
Browse files Browse the repository at this point in the history
Revert "Vtx presave fix"
  • Loading branch information
codecae authored Oct 30, 2017
2 parents 00b1ce3 + b51c1a8 commit 8b01d94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sdcard/SCRIPTS/BF/X9/vtx.lua
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return{read=88,write=89,eepromWrite=false,reboot=false,saveMaxRetries=2,saveTimeout=300,title="VTX",minBytes=5,text={},fields={{t="Band",x=25,y=14,sp=50,min=1,max=5,vals={2},to=SMLSIZE,table={"A","B","E","F","R"},upd=function(self)self.updateVTXFreq(self)end},{t="Channel",x=25,y=24,sp=50,min=1,max=8,vals={3},to=SMLSIZE,upd=function(self)self.updateVTXFreq(self)end},{t="Power",x=25,y=34,sp=50,min=1,vals={4},to=SMLSIZE,upd=function(self)self.updatePowerTable(self)end},{t="Pit",x=25,y=44,sp=50,min=0,max=1,vals={5},to=SMLSIZE,table={[0]="OFF","ON"}},{t="Dev",x=100,y=14,sp=32,write=false,ro=true,vals={1},to=SMLSIZE,table={[3]="SmartAudio",[4]="Tramp",[255]="None"}},{t="Freq",x=100,y=24,sp=32,min=5000,max=6000,to=SMLSIZE,ro=true}},freqLookup={{5865,5845,5825,5805,5785,5765,5745,5725},{5733,5752,5771,5790,5809,5828,5847,5866},{5705,5685,5665,5645,5885,5905,5925,5945},{5740,5760,5780,5800,5820,5840,5860,5880},{5658,5695,5732,5769,5806,5843,5880,5917}},postLoad=function(self)if self.values[2]==0 or self.values[3]==0 or self.values[4]==0 then self.values={}end end,preSave=function(self)local a={}local b=(self.values[2]-1)*8+self.values[3]-1;a[1]=bit32.band(b,0xFF)a[2]=bit32.rshift(b,8)a[3]=self.values[4]a[4]=self.values[5]self.values=a end,updatePowerTable=function(self)if self.values and not self.fields[3].table then if self.values[1]==3 then self.fields[3].table={25,200,500,800}self.fields[3].max=4 elseif self.values[1]==4 then self.fields[3].table={25,100,200,400,600}self.fields[3].max=5 end end end,updateVTXFreq=function(self)if(#self.values or 0)>=self.minBytes then if(self.fields[2].value or 0)>0 and(self.fields[3].value or 0)>0 then self.fields[6].value=self.freqLookup[self.values[2]][self.values[3]]end end end}
return{read=88,write=89,eepromWrite=false,reboot=false,saveMaxRetries=2,saveTimeout=300,title="VTX",minBytes=5,text={},fields={{t="Band",x=25,y=14,sp=50,min=1,max=5,vals={2},to=SMLSIZE,table={"A","B","E","F","R"},upd=function(self)self.updateVTXFreq(self)end},{t="Channel",x=25,y=24,sp=50,min=1,max=8,vals={3},to=SMLSIZE,upd=function(self)self.updateVTXFreq(self)end},{t="Power",x=25,y=34,sp=50,min=1,vals={4},to=SMLSIZE,upd=function(self)self.updatePowerTable(self)end},{t="Pit",x=25,y=44,sp=50,min=0,max=1,vals={5},to=SMLSIZE,table={[0]="OFF","ON"}},{t="Dev",x=100,y=14,sp=32,write=false,ro=true,vals={1},to=SMLSIZE,table={[3]="SmartAudio",[4]="Tramp",[255]="None"}},{t="Freq",x=100,y=24,sp=32,min=5000,max=6000,to=SMLSIZE,ro=true}},freqLookup={{5865,5845,5825,5805,5785,5765,5745,5725},{5733,5752,5771,5790,5809,5828,5847,5866},{5705,5685,5665,5645,5885,5905,5925,5945},{5740,5760,5780,5800,5820,5840,5860,5880},{5658,5695,5732,5769,5806,5843,5880,5917}},postLoad=function(self)if self.values[2]==0 or self.values[3]==0 or self.values[4]==0 then self.values={}end end,preSave=function(self)local a={}local b=(self.values[2]-1)*8+self.values[3]-1;self.values[2]=bit32.band(b,0xFF)self.values[3]=bit32.rshift(b,8)for c=2,self.minBytes do a[c-1]=self.values[c]end;self.values=a end,updatePowerTable=function(self)if self.values and not self.fields[3].table then if self.values[1]==3 then self.fields[3].table={25,200,500,800}self.fields[3].max=4 elseif self.values[1]==4 then self.fields[3].table={25,100,200,400,600}self.fields[3].max=5 end end end,updateVTXFreq=function(self)if(#self.values or 0)>=self.minBytes then if(self.fields[2].value or 0)>0 and(self.fields[3].value or 0)>0 then self.fields[6].value=self.freqLookup[self.values[2]][self.values[3]]end end end}
13 changes: 7 additions & 6 deletions src/SCRIPTS/BF/X9/vtx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ return {
reboot = false,
saveMaxRetries = 2,
saveTimeout = 300, -- 3s
title = "VTX",
title = "VTX",
minBytes = 5,
text = {},
fields = {
Expand All @@ -29,13 +29,14 @@ return {
self.values = {}
end
end,
preSave = function(self)
preSave = function(self)
local valsTemp = {}
local channel = (self.values[2]-1)*8 + self.values[3]-1
valsTemp[1] = bit32.band(channel,0xFF)
valsTemp[2] = bit32.rshift(channel,8)
valsTemp[3] = self.values[4]
valsTemp[4] = self.values[5]
self.values[2] = bit32.band(channel,0xFF)
self.values[3] = bit32.rshift(channel,8)
for i=2,self.minBytes do
valsTemp[i-1] = self.values[i]
end
self.values = valsTemp
end,
updatePowerTable = function(self)
Expand Down

0 comments on commit 8b01d94

Please sign in to comment.