Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/SCRIPTS/RF2/COMPILE/scripts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ local scripts = {
"/SCRIPTS/RF2/PAGES/esc_xdfly.lua",
"/SCRIPTS/RF2/PAGES/esc_yge.lua",
"/SCRIPTS/RF2/PAGES/experimental.lua",
"/SCRIPTS/RF2/PAGES/battery.lua",
"/SCRIPTS/RF2/PAGES/filters.lua",
"/SCRIPTS/RF2/PAGES/governor.lua",
"/SCRIPTS/RF2/PAGES/mixer.lua",
Expand Down
17 changes: 15 additions & 2 deletions src/SCRIPTS/RF2/MSP/mspSetProfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ local function setRateProfile(profileIndex, callback, callbackParam)
setPidProfile(profileIndex + 128, callback, callbackParam)
end

local function setBatteryProfile(profileIndex, callback, callbackParam)
local message = {
command = 244, -- MSP_SELECT_BATTERY
payload = { profileIndex },
processReply = function(self, buf)
if callback then callback(callbackParam) end
end,
simulatorResponse = {}
}
rf2.mspQueue:add(message)
end

return {
setPidProfile = setPidProfile,
setRateProfile = setRateProfile
}
setRateProfile = setRateProfile,
setBatteryProfile = setBatteryProfile
}
4 changes: 3 additions & 1 deletion src/SCRIPTS/RF2/MSP/mspStatus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ local function getStatus(callback, callbackParam)
--rf2.print("Number of motors: "..tostring(status.motorCount))
--status.servoCount = rf2.mspHelper.readU8(buf)
--rf2.print("Number of servos: "..tostring(status.servoCount))
buf.offset = 31
status.batteryProfile = rf2.mspHelper.readU8(buf)
callback(callbackParam, status)
end,
simulatorResponse = { 240, 1, 124, 0, 35, 0, 0, 0, 0, 0, 0, 224, 1, 10, 1, 0, 26, 0, 0, 0, 0, 0, 2, 0, 6, 0, 6, 1, 4, 1 }
simulatorResponse = { 240, 1, 124, 0, 35, 0, 0, 0, 0, 0, 0, 224, 1, 10, 1, 0, 26, 0, 0, 0, 0, 0, 2, 0, 6, 0, 6, 1, 4, 1, 1, 6 }
}

rf2.mspQueue:add(message)
Expand Down
77 changes: 77 additions & 0 deletions src/SCRIPTS/RF2/PAGES/battery.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
local template = assert(rf2.loadScript(rf2.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 = rf2.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 batteries = 6
local mspSetProfile = assert(rf2.loadScript("MSP/mspSetProfile.lua"))()
local mspStatus = assert(rf2.loadScript("MSP/mspStatus.lua"))()
local editing = false
local profileAdjustmentTS = nil

local startEditing = function(field, page)
editing = true
end

local endPidEditing = function(field, page)
mspSetProfile.setBatteryProfile(field.data.value, function() rf2.reloadPage() end, nil)
end

fields[1] = { t = "Current Profile", x = x, y = inc.y(lineSpacing), sp = x + sp * 1.17, data = { value = nil, min = 0, max = 5, table = { [0] = "1", "2", "3", "4", "5", "6" } }, preEdit = startEditing, postEdit = endPidEditing }

y = inc.y(lineSpacing)
labels[#labels + 1] = { t = "Battery", x = x, y = inc.y(lineSpacing) }
labels[#labels + 1] = { t = "Capacity", x = x + tableSpacing.col, y = y }
labels[#labels + 1] = { t = "CellCount", x = x + 2 * tableSpacing.col, y = y }

labels[#labels + 1] = { t = tostring(1), x = x, y = inc.y(lineSpacing) }
fields[#fields + 1] = { x = x + tableSpacing.col, y = y, min = 0, max = 20000, vals = { 1, 2 } }
fields[#fields + 1] = { x = x + 2 * tableSpacing.col, y = y, min = 0, max = 24, vals = { 3 } }
for i=1, batteries - 1 do
labels[#labels + 1] = { t = tostring(i + 1), x = x, y = inc.y(lineSpacing) }
fields[#fields + 1] = { x = x + tableSpacing.col, y = y, min = 0, max = 20000, vals = { 15 + (i - 1) * 3 + 1, 15 + (i - 1) * 3 + 2 } }
fields[#fields + 1] = { x = x + 2 * tableSpacing.col, y = y, min = 0, max = 24, vals = { 15 + (i - 1) * 3 + 3 } }
end

return {
read = 32, -- MSP_BATTERY_CONFIG
write = 33, -- MSP_SET_BATTERY_CONFIG
title = "Battery Config",
minBytes = 30,
eepromWrite = true,
labels = labels,
fields = fields,
simulatorResponse = { 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 0, 3, 5, 0, 4, 6, 0, 5, 8, 0, 0, 12 },

postLoad = function(self)
mspStatus.getStatus(self.onProcessedMspStatus, self)
end,

timer = function(self)
if profileAdjustmentTS and rf2.clock() - profileAdjustmentTS > 0.35 then
rf2.reloadPage()
elseif rf2.mspQueue:isProcessed() and not editing then
mspStatus.getStatus(self.onProcessedMspStatus, self)
end
end,

onProcessedMspStatus = function(self, status)
local currentField = self.fields[1]
if currentField.data.value ~= status.batteryProfile and not editing then
if currentField.data.value then
profileAdjustmentTS = rf2.clock()
end
currentField.data.value = status.batteryProfile
end

rf2.lcdNeedsInvalidate = true
self.isReady = true
end,
}
1 change: 1 addition & 0 deletions src/SCRIPTS/RF2/pages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PageFiles[#PageFiles + 1] = { title = "Profile - PIDs", script = "pids.lua" }
PageFiles[#PageFiles + 1] = { title = "Profile - Various", script = "profile.lua" }
PageFiles[#PageFiles + 1] = { title = "Profile - Rescue", script = "profile_rescue.lua" }
PageFiles[#PageFiles + 1] = { title = "Profile - Governor", script = "profile_governor.lua" }
PageFiles[#PageFiles + 1] = { title = "Battery", script = "battery.lua" }
PageFiles[#PageFiles + 1] = { title = "Servos", script = "servos.lua" }
PageFiles[#PageFiles + 1] = { title = "Mixer", script = "mixer.lua" }
PageFiles[#PageFiles + 1] = { title = "Gyro Filters", script = "filters.lua" }
Expand Down
2 changes: 2 additions & 0 deletions src/SCRIPTS/RF2/rf2tlm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ local RFSensors = {
[0x1212] = { name="RTE#", unit=UNIT_RAW, prec=0, dec=decU8 },
-- Current LED profile
[0x1213] = { name="LED#", unit=UNIT_RAW, prec=0, dec=decU8 },
-- Current Battery profile
[0x1214] = { name="BAT#", unit=UNIT_RAW, prec=0, dec=decU8 },

-- Adjustment function
[0x1220] = { name="ADJ", unit=UNIT_RAW, prec=0, dec=decAdjFunc },
Expand Down