Skip to content

Commit 9e2d4b8

Browse files
authored
Merge pull request #365 from klutvott123/rates-type-support
2 parents 8c345ce + 4974c94 commit 9e2d4b8

File tree

7 files changed

+127
-0
lines changed

7 files changed

+127
-0
lines changed

src/SCRIPTS/BF/PAGES/rates.lua

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ if apiVersion >= 1.016 then
6666
inc.y(lineSpacing*0.4)
6767
end
6868

69+
if apiVersion >= 1.043 then
70+
fields[#fields + 1] = { t = "Rates Type", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 4, vals = { 23 }, table = { [0] = "BF", "RF", "KISS", "ACTUAL", "QUICK"}, postEdit = function(self) self.updateRatesType(self, true) end }
71+
end
72+
6973
if apiVersion >= 1.016 then
7074
labels[#labels + 1] = { t = "Throttle", x = x, y = inc.y(lineSpacing) }
7175
fields[#fields + 1] = { t = "Mid", x = x + indent, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 100, vals = { 7 }, scale = 100 }
@@ -91,4 +95,49 @@ return {
9195
minBytes = 12,
9296
labels = labels,
9397
fields = fields,
98+
ratesType,
99+
getRatesType = function(self)
100+
for i = 1, #self.fields do
101+
if self.fields[i].vals and self.fields[i].vals[1] == 23 then
102+
return self.fields[i].table[self.fields[i].value]
103+
end
104+
end
105+
end,
106+
updateRatesType = function(self, applyDefaults)
107+
local ratesTable = assert(loadScript("RATETABLES/"..self.getRatesType(self)..".lua"))()
108+
for i = 1, #ratesTable.labels do
109+
self.labels[i].t = ratesTable.labels[i]
110+
end
111+
for i = 1, #ratesTable.fields do
112+
for k, v in pairs(ratesTable.fields[i]) do
113+
self.fields[i][k] = v
114+
end
115+
end
116+
if applyDefaults and self.ratesType ~= self.getRatesType(self) then
117+
for i = 1, #ratesTable.defaults do
118+
local f = self.fields[i]
119+
f.value = ratesTable.defaults[i]
120+
for idx=1, #f.vals do
121+
self.values[f.vals[idx]] = bit32.rshift(math.floor(f.value*(f.scale or 1) + 0.5), (idx-1)*8)
122+
end
123+
end
124+
else
125+
for i = 1, 9 do
126+
local f = self.fields[i]
127+
f.value = 0
128+
for idx=1, #f.vals do
129+
local raw_val = self.values[f.vals[idx]] or 0
130+
raw_val = bit32.lshift(raw_val, (idx-1)*8)
131+
f.value = bit32.bor(f.value, raw_val)
132+
end
133+
f.value = f.value/(f.scale or 1)
134+
end
135+
end
136+
self.ratesType = self.getRatesType(self)
137+
end,
138+
postLoad = function(self)
139+
if apiVersion >= 1.043 then
140+
self.updateRatesType(self)
141+
end
142+
end,
94143
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
return {
2+
labels = { "", "", "ROLL", "PITCH", "YAW", "Cntr", "Sens", "Max", "Rate", "", "Expo" },
3+
fields = {
4+
{ min = 1, max = 200, scale = 0.1 },
5+
{ min = 1, max = 200, scale = 0.1 },
6+
{ min = 1, max = 200, scale = 0.1 },
7+
{ min = 0, max = 200, scale = 0.1 },
8+
{ min = 0, max = 200, scale = 0.1 },
9+
{ min = 0, max = 200, scale = 0.1 },
10+
{ min = 0, max = 100, scale = 100 },
11+
{ min = 0, max = 100, scale = 100 },
12+
{ min = 0, max = 100, scale = 100 }
13+
},
14+
defaults = { 200, 200, 200, 670, 670, 670, 0.54, 0.54, 0.54 }
15+
}

src/SCRIPTS/BF/RATETABLES/BF.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
return {
2+
labels = { "", "", "ROLL", "PITCH", "YAW", "RC", "Rate", "Super", "Rate", "RC", "Expo" },
3+
fields = {
4+
{ min = 0, max = 255, scale = 100 },
5+
{ min = 0, max = 255, scale = 100 },
6+
{ min = 0, max = 255, scale = 100 },
7+
{ min = 0, max = 100, scale = 100 },
8+
{ min = 0, max = 100, scale = 100 },
9+
{ min = 0, max = 255, scale = 100 },
10+
{ min = 0, max = 100, scale = 100 },
11+
{ min = 0, max = 100, scale = 100 },
12+
{ min = 0, max = 100, scale = 100 }
13+
},
14+
defaults = { 1.0, 1.0, 1.0, 0.7, 0.7, 0.7, 0.0, 0.0, 0.0 }
15+
}

src/SCRIPTS/BF/RATETABLES/KISS.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
return {
2+
labels = { "", "", "ROLL", "PITCH", "YAW", "RC", "Rate", "", "Rate", "RC", "Curve" },
3+
fields = {
4+
{ min = 1, max = 255, scale = 100 },
5+
{ min = 1, max = 255, scale = 100 },
6+
{ min = 1, max = 255, scale = 100 },
7+
{ min = 0, max = 99, scale = 100 },
8+
{ min = 0, max = 99, scale = 100 },
9+
{ min = 0, max = 99, scale = 100 },
10+
{ min = 0, max = 100, scale = 100 },
11+
{ min = 0, max = 100, scale = 100 },
12+
{ min = 0, max = 100, scale = 100 }
13+
},
14+
defaults = { 1.0, 1.0, 1.0, 0.7, 0.7, 0.7, 0.0, 0.0, 0.0 }
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
return {
2+
labels = { "", "", "ROLL", "PITCH", "YAW", "RC", "Rate", "Max", "Rate", "", "Expo" },
3+
fields = {
4+
{ min = 1, max = 255, scale = 100 },
5+
{ min = 1, max = 255, scale = 100 },
6+
{ min = 1, max = 255, scale = 100 },
7+
{ min = 0, max = 200, scale = 0.1 },
8+
{ min = 0, max = 200, scale = 0.1 },
9+
{ min = 0, max = 200, scale = 0.1 },
10+
{ min = 0, max = 100, scale = 100 },
11+
{ min = 0, max = 100, scale = 100 },
12+
{ min = 0, max = 100, scale = 100 }
13+
},
14+
defaults = { 1.0, 1.0, 1.0, 670, 670, 670, 0.0, 0.0, 0.0 }
15+
}

src/SCRIPTS/BF/RATETABLES/RF.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
return {
2+
labels = { "", "", "ROLL", "PITCH", "YAW", "", "Rate", "", "Acro+", "", "Expo" },
3+
fields = {
4+
{ min = 1, max = 200, scale = 0.1 },
5+
{ min = 1, max = 200, scale = 0.1 },
6+
{ min = 1, max = 200, scale = 0.1 },
7+
{ min = 0, max = 100, scale = 1 },
8+
{ min = 0, max = 100, scale = 1 },
9+
{ min = 0, max = 100, scale = 1 },
10+
{ min = 0, max = 100, scale = 1 },
11+
{ min = 0, max = 100, scale = 1 },
12+
{ min = 0, max = 100, scale = 1 }
13+
},
14+
defaults = { 370, 370, 370, 80, 80, 80, 50, 50, 50 }
15+
}

src/SCRIPTS/BF/ui.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ local function run_ui(event)
358358
end
359359
elseif pageState == pageStatus.editing then
360360
if event == EVT_VIRTUAL_EXIT or event == EVT_VIRTUAL_ENTER then
361+
if Page.fields[currentField].postEdit then
362+
Page.fields[currentField].postEdit(Page)
363+
end
361364
pageState = pageStatus.display
362365
elseif event == EVT_VIRTUAL_INC or event == EVT_VIRTUAL_INC_REPT then
363366
incValue(1)

0 commit comments

Comments
 (0)