Skip to content

Commit 8600937

Browse files
committed
Make PWM page functions more efficient
1 parent 5cc9a56 commit 8600937

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/SCRIPTS/BF/PAGES/pwm.lua

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ end
2323

2424
if apiVersion >= 1.016 then
2525
labels[#labels + 1] = { t = "Gyro Update", x = x, y = inc.y(lineSpacing)}
26-
fields[#fields + 1] = { x = x + sp, y = y, min = 1, max = 32, vals = { 1 }, upd = function(self) self.updatePidRateTable(self) end }
26+
fields[#fields + 1] = { x = x + sp, y = y, min = 1, max = 32, vals = { 1 }, table = {}, upd = function(self) self.updatePidRateTable(self) end }
2727
labels[#labels + 1] = { t = "PID Loop", x = x, y = inc.y(lineSpacing)}
28-
fields[#fields + 1] = { x = x + sp, y = y, min = 1, max = 16, vals = { 2 }, }
28+
fields[#fields + 1] = { x = x + sp, y = y, min = 1, max = 16, vals = { 2 }, table = {} }
2929
labels[#labels + 1] = { t = "Protocol", x = x, y = inc.y(lineSpacing) }
3030
fields[#fields + 1] = { x = x + sp, y = y, min = 0, max = 9, vals = { 4 }, table = { [0] = "OFF", "OS125", "OS42", "MSHOT","BRSH", "DS150", "DS300", "DS600","DS1200", "PS1000" } }
3131
labels[#labels + 1] = { t = "Unsynced PWM", x = x, y = inc.y(lineSpacing) }
@@ -48,6 +48,7 @@ return {
4848
minBytes = 6,
4949
labels = labels,
5050
fields = fields,
51+
gyroRates = {},
5152
getGyroDenomFieldIndex = function(self)
5253
for i=1,#self.fields do
5354
if self.fields[i].vals[1] == 1 then
@@ -63,18 +64,14 @@ return {
6364
end
6465
end,
6566
calculateGyroRates = function(self, baseRate)
66-
self.gyroRates = {}
6767
local idx = self.getGyroDenomFieldIndex(self)
68-
self.fields[idx].table = {}
6968
for i=1, 32 do
7069
self.gyroRates[i] = baseRate/i
71-
local fmt = nil
7270
self.fields[idx].table[i] = string.format("%.2f",baseRate/i)
7371
end
7472
end,
7573
calculatePidRates = function(self, baseRate)
7674
local idx = self.getPidDenomFieldIndex(self)
77-
self.fields[idx].table = {}
7875
for i=1, 16 do
7976
self.fields[idx].table[i] = string.format("%.2f",baseRate/i)
8077
end

0 commit comments

Comments
 (0)