Skip to content

Accelerometer calibration #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to make this a bit more verbose, like pop up a dialog saying something like 'Make sure the craft is level and stable, then press [Enter] to continue, or [Cancel]'?
Otherwise I suspect unsuspecting newbie pilots will 'test' this function and then end up un-calibrating their craft when they 'try' this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I'll see what I can do. I think the best approach would be to just make it a special page that can only be entered from the popup menu. I looked into the built in popup dialogue in opentx but it's very limited and behaves differently on different radios

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeller It's done. I updated the first post with a description of how this works with pictures

}
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