diff --git a/src/SCRIPTS/BF/PAGES/accelerometer.lua b/src/SCRIPTS/BF/PAGES/accelerometer.lua new file mode 100644 index 0000000..f6c934b --- /dev/null +++ b/src/SCRIPTS/BF/PAGES/accelerometer.lua @@ -0,0 +1,36 @@ +local template = loadScript(radio.templateHome.."accelerometer.lua") +if template then + template = template() +else + template = assert(loadScript(radio.templateHome.."default_template.lua"))() +end +local margin = template.margin +local indent = template.indent +local lineSpacing = template.lineSpacing +local tableSpacing = template.tableSpacing +local sp = template.listSpacing.field +local yMinLim = radio.yMinLimit +local x = margin +local y = yMinLim - lineSpacing +local inc = { x = function(val) x = x + val return x end, y = function(val) y = y + val return y end } +local labels = {} +local fields = {} + +labels[#labels + 1] = { t = "Make sure the craft is level", x = x, y = inc.y(lineSpacing) } +labels[#labels + 1] = { t = "and stable, then press", x = x, y = inc.y(lineSpacing) } +labels[#labels + 1] = { t = "[ENTER] to calibrate, or", x = x, y = inc.y(lineSpacing) } +labels[#labels + 1] = { t = "[EXIT] to cancel.", x = x, y = inc.y(lineSpacing) } +fields[#fields + 1] = { x = x, y = inc.y(lineSpacing), value = "", ro = true, onClick = function(self) self.accCal(self) end } + +return { + write = 205, -- MSP_ACC_CALIBRATION + title = "Accelerometer", + reboot = false, + eepromWrite = false, + minBytes = 0, + labels = labels, + fields = fields, + accCal = function(self) + protocol.mspRead(self.write) + end, +} diff --git a/src/SCRIPTS/BF/ui.lua b/src/SCRIPTS/BF/ui.lua index 630c3d8..552c822 100644 --- a/src/SCRIPTS/BF/ui.lua +++ b/src/SCRIPTS/BF/ui.lua @@ -16,7 +16,7 @@ local pageStatus = local uiMsp = { reboot = 68, - eepromWrite = 250 + eepromWrite = 250, } local uiState = uiStatus.init @@ -72,6 +72,13 @@ local function eepromWrite() protocol.mspRead(uiMsp.eepromWrite) end +local function accCal() + invalidatePages() + currentField = 1 + Page = assert(loadScript("Pages/accelerometer.lua"))() + collectgarbage() +end + local function getVtxTables() uiState = uiStatus.init PageFiles = nil @@ -85,6 +92,7 @@ local function createPopupMenu() { t = "save page", f = saveSettings }, { t = "reload", f = invalidatePages }, { t = "reboot", f = rebootFc }, + { t = "acc cal", f = accCal }, } if apiVersion >= 1.042 then popupMenuList[#popupMenuList + 1] = { t = "vtx tables", f = getVtxTables } @@ -342,6 +350,9 @@ local function run_ui(event) elseif event == EVT_VIRTUAL_ENTER then if Page then local f = Page.fields[currentField] + if f.onClick then + f.onClick(Page) + end if Page.values and f.vals and Page.values[f.vals[#f.vals]] and not f.ro then pageState = pageStatus.editing end