|
| 1 | +local template = assert(loadScript(radio.template))() |
| 2 | +local margin = template.margin |
| 3 | +local indent = template.indent |
| 4 | +local lineSpacing = template.lineSpacing |
| 5 | +local tableSpacing = template.tableSpacing |
| 6 | +local sp = template.listSpacing.field |
| 7 | +local yMinLim = radio.yMinLimit |
| 8 | +local x = margin |
| 9 | +local y = yMinLim - lineSpacing |
| 10 | +local inc = { x = function(val) x = x + val return x end, y = function(val) y = y + val return y end } |
| 11 | +local labels = {} |
| 12 | +local fields = {} |
| 13 | + |
| 14 | +local RATEPROFILE_MASK = bit32.lshift(1, 7) |
| 15 | +local profileNumbers = { [0] = "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" } |
| 16 | + |
| 17 | +fields[#fields + 1] = { t = "PID Profile", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 1, vals = { 11 }, table = profileNumbers } |
| 18 | +fields[#fields + 1] = { t = "Rate Profile", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 5, vals = { 15 }, table = profileNumbers } |
| 19 | + |
| 20 | +return { |
| 21 | + read = 150, -- MSP_STATUS_EX |
| 22 | + write = 210, -- MSP_SELECT_SETTING |
| 23 | + title = "Profiles", |
| 24 | + reboot = false, |
| 25 | + eepromWrite = true, |
| 26 | + minBytes = 11, |
| 27 | + labels = labels, |
| 28 | + fields = fields, |
| 29 | + pidProfile = 0, |
| 30 | + postLoad = function(self) |
| 31 | + local pidProfileCount = self.values[14] |
| 32 | + self.fields[1].max = pidProfileCount - 1 |
| 33 | + self.pidProfile = self.fields[1].value |
| 34 | + end, |
| 35 | + preSave = function(self) |
| 36 | + local value = 0 |
| 37 | + if self.fields[1].value ~= self.pidProfile then |
| 38 | + value = self.fields[1].value |
| 39 | + else |
| 40 | + value = bit32.bor(self.fields[2].value, RATEPROFILE_MASK) |
| 41 | + end |
| 42 | + self.values = {} |
| 43 | + self.values[1] = value |
| 44 | + return self.values |
| 45 | + end, |
| 46 | +} |
0 commit comments