Skip to content

Commit 2c570a9

Browse files
committed
Accelerometer calibration
Adds a function to the menu that sends MSP_ACC_CALIBRATION to the FC.
1 parent f9dec71 commit 2c570a9

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
local template = loadScript(radio.templateHome.."accelerometer.lua")
2+
if template then
3+
template = template()
4+
else
5+
template = assert(loadScript(radio.templateHome.."default_template.lua"))()
6+
end
7+
local margin = template.margin
8+
local indent = template.indent
9+
local lineSpacing = template.lineSpacing
10+
local tableSpacing = template.tableSpacing
11+
local sp = template.listSpacing.field
12+
local yMinLim = radio.yMinLimit
13+
local x = margin
14+
local y = yMinLim - lineSpacing
15+
local inc = { x = function(val) x = x + val return x end, y = function(val) y = y + val return y end }
16+
local labels = {}
17+
local fields = {}
18+
19+
labels[#labels + 1] = { t = "Make sure the craft is level", x = x, y = inc.y(lineSpacing) }
20+
labels[#labels + 1] = { t = "and stable, then press", x = x, y = inc.y(lineSpacing) }
21+
labels[#labels + 1] = { t = "[ENTER] to calibrate, or", x = x, y = inc.y(lineSpacing) }
22+
labels[#labels + 1] = { t = "[EXIT] to cancel.", x = x, y = inc.y(lineSpacing) }
23+
fields[#fields + 1] = { x = x, y = inc.y(lineSpacing), value = "", ro = true, onClick = function(self) self.accCal(self) end }
24+
25+
return {
26+
write = 205, -- MSP_ACC_CALIBRATION
27+
title = "Accelerometer",
28+
reboot = false,
29+
eepromWrite = false,
30+
minBytes = 0,
31+
labels = labels,
32+
fields = fields,
33+
accCal = function(self)
34+
protocol.mspRead(self.write)
35+
end,
36+
}

src/SCRIPTS/BF/ui.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ local pageStatus =
1616
local uiMsp =
1717
{
1818
reboot = 68,
19-
eepromWrite = 250
19+
eepromWrite = 250,
2020
}
2121

2222
local uiState = uiStatus.init
@@ -72,6 +72,13 @@ local function eepromWrite()
7272
protocol.mspRead(uiMsp.eepromWrite)
7373
end
7474

75+
local function accCal()
76+
invalidatePages()
77+
currentField = 1
78+
Page = assert(loadScript("Pages/accelerometer.lua"))()
79+
collectgarbage()
80+
end
81+
7582
local function getVtxTables()
7683
uiState = uiStatus.init
7784
PageFiles = nil
@@ -85,6 +92,7 @@ local function createPopupMenu()
8592
{ t = "save page", f = saveSettings },
8693
{ t = "reload", f = invalidatePages },
8794
{ t = "reboot", f = rebootFc },
95+
{ t = "acc cal", f = accCal },
8896
}
8997
if apiVersion >= 1.042 then
9098
popupMenuList[#popupMenuList + 1] = { t = "vtx tables", f = getVtxTables }
@@ -342,6 +350,9 @@ local function run_ui(event)
342350
elseif event == EVT_VIRTUAL_ENTER then
343351
if Page then
344352
local f = Page.fields[currentField]
353+
if f.onClick then
354+
f.onClick(Page)
355+
end
345356
if Page.values and f.vals and Page.values[f.vals[#f.vals]] and not f.ro then
346357
pageState = pageStatus.editing
347358
end

0 commit comments

Comments
 (0)