Skip to content

Commit

Permalink
Accelerometer calibration
Browse files Browse the repository at this point in the history
Adds a function to the menu that sends MSP_ACC_CALIBRATION to the FC.
  • Loading branch information
klutvott123 committed Dec 19, 2020
1 parent f9dec71 commit 2c570a9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/SCRIPTS/BF/PAGES/accelerometer.lua
Original file line number Diff line number Diff line change
@@ -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,
}
13 changes: 12 additions & 1 deletion src/SCRIPTS/BF/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ local pageStatus =
local uiMsp =
{
reboot = 68,
eepromWrite = 250
eepromWrite = 250,
}

local uiState = uiStatus.init
Expand Down Expand Up @@ -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
Expand All @@ -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 }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2c570a9

Please sign in to comment.