Skip to content

Add Profiles page. #432

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
Feb 4, 2022
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
46 changes: 46 additions & 0 deletions src/SCRIPTS/BF/PAGES/profiles.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
local template = assert(loadScript(radio.template))()
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 = {}

local RATEPROFILE_MASK = bit32.lshift(1, 7)
local profileNumbers = { [0] = "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }

fields[#fields + 1] = { t = "PID Profile", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 1, vals = { 11 }, table = profileNumbers }
fields[#fields + 1] = { t = "Rate Profile", x = x, y = inc.y(lineSpacing), sp = x + sp, min = 0, max = 5, vals = { 15 }, table = profileNumbers }

return {
read = 150, -- MSP_STATUS_EX
write = 210, -- MSP_SELECT_SETTING
title = "Profiles",
reboot = false,
eepromWrite = true,
minBytes = 11,
labels = labels,
fields = fields,
pidProfile = 0,
postLoad = function(self)
local pidProfileCount = self.values[14]
self.fields[1].max = pidProfileCount - 1
self.pidProfile = self.fields[1].value
end,
preSave = function(self)
local value = 0
if self.fields[1].value ~= self.pidProfile then
value = self.fields[1].value
else
value = bit32.bor(self.fields[2].value, RATEPROFILE_MASK)
end
self.values = {}
self.values[1] = value
return self.values
end,
}
4 changes: 4 additions & 0 deletions src/SCRIPTS/BF/pages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ if apiVersion >= 1.036 then
PageFiles[#PageFiles + 1] = { title = "VTX Settings", script = "vtx.lua" }
end

if apiVersion >= 1.016 then
PageFiles[#PageFiles + 1] = { title = "Profiles", script = "profiles.lua" }
Copy link
Member

Choose a reason for hiding this comment

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

Move to line 12?

Copy link
Member Author

Choose a reason for hiding this comment

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

By having it like this the pages can be shuffled around as we please. and if a page is to be removed we have to break it out anyway. I also like the readability of the current approach of having a if for each page.

end

if apiVersion >= 1.016 then
PageFiles[#PageFiles + 1] = { title = "PIDs 1", script = "pids1.lua" }
end
Expand Down