@@ -16,11 +16,16 @@
|
|||||||
---- # #
|
---- # #
|
||||||
---- #########################################################################
|
---- #########################################################################
|
||||||
|
|
||||||
|
-- Horus Widget to display the levels of lipo battery with per cell indication
|
||||||
|
-- 3djc & Offer Shmuely
|
||||||
|
-- Date: 2020
|
||||||
|
-- ver: 0.4
|
||||||
|
|
||||||
local _options = {
|
local _options = {
|
||||||
{ "Sensor", SOURCE, 0 },
|
{ "Sensor", SOURCE, 0 }, -- default to 'Cels'
|
||||||
{ "Color", COLOR, WHITE },
|
{ "Color", COLOR, WHITE },
|
||||||
{ "Shadow", BOOL, 0 },
|
{ "Shadow", BOOL, 0 },
|
||||||
{ "LowestCell", BOOL, 1 }
|
{ "LowestCell", BOOL, 1 } -- 0=main voltage display shows all-cell-voltage, 1=main voltage display shows lowest-cell
|
||||||
}
|
}
|
||||||
|
|
||||||
-- This function is run once at the creation of the widget
|
-- This function is run once at the creation of the widget
|
||||||
@@ -29,12 +34,12 @@ local function create(zone, options)
|
|||||||
zone = zone,
|
zone = zone,
|
||||||
options = options,
|
options = options,
|
||||||
counter = 0,
|
counter = 0,
|
||||||
|
|
||||||
shadowed = 0,
|
shadowed = 0,
|
||||||
|
|
||||||
no_telem_blink = 0,
|
no_telem_blink = 0,
|
||||||
isDataAvailable = 0,
|
isDataAvailable = 0,
|
||||||
cellDataLive = {0,0,0,0,0,0},
|
cellDataLive = {0,0,0,0,0,0},
|
||||||
cellDataHistoryLowest = {0,0,0,0,0,0},
|
cellDataHistoryLowest = {5,5,5,5,5,5},
|
||||||
cellDataHistoryCellLowest = 5,
|
cellDataHistoryCellLowest = 5,
|
||||||
cellMax = 0,
|
cellMax = 0,
|
||||||
cellMin = 0,
|
cellMin = 0,
|
||||||
@@ -112,51 +117,47 @@ local function calculateBatteryData(wgt)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- this is necessary for simu where cell-count can change
|
-- this is necessary for simu where cell-count can change
|
||||||
if #wgt.cellDataHistoryLowest ~= #newCellData then
|
if #wgt.cellDataHistoryLowest ~= #newCellData then
|
||||||
wgt.cellDataHistoryLowest = {}
|
wgt.cellDataHistoryLowest = {}
|
||||||
for k, v in pairs(newCellData) do
|
for k, v in pairs(newCellData) do
|
||||||
wgt.cellDataHistoryLowest[k] = v
|
wgt.cellDataHistoryLowest[k] = 5 -- invalid reading, set high value so the min() will update it soon
|
||||||
end
|
|
||||||
end
|
|
||||||
-- stores the lowest cell values in historical table
|
|
||||||
for k, v in pairs(newCellData) do
|
|
||||||
if v < wgt.cellDataHistoryLowest[k] then
|
|
||||||
wgt.cellDataHistoryLowest[k] = v
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- calc highest of all cels
|
|
||||||
local cellMax = 0
|
local cellMax = 0
|
||||||
|
local cellMin = 5
|
||||||
|
local cellSum = 0
|
||||||
for k, v in pairs(newCellData) do
|
for k, v in pairs(newCellData) do
|
||||||
|
-- stores the lowest cell values in historical table
|
||||||
|
if v > 1 and v < wgt.cellDataHistoryLowest[k] then -- min 1v to consider a valid reading
|
||||||
|
wgt.cellDataHistoryLowest[k] = v
|
||||||
|
|
||||||
|
--- calc history lowest of all cells
|
||||||
|
if v < wgt.cellDataHistoryCellLowest then
|
||||||
|
wgt.cellDataHistoryCellLowest = v
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- calc highest of all cells
|
||||||
if v > cellMax then
|
if v > cellMax then
|
||||||
cellMax = v
|
cellMax = v
|
||||||
end
|
end
|
||||||
end
|
|
||||||
wgt.cellMax = cellMax
|
|
||||||
|
|
||||||
--- calc lowest of all cels
|
--- calc lowest of all cells
|
||||||
local cellMin = 5
|
if v < cellMin and v > 1 then -- min 1v to consider a valid reading
|
||||||
for k, v in pairs(newCellData) do
|
|
||||||
if v < cellMin and v > 1 then -- >1 to ignore invalid values
|
|
||||||
cellMin = v
|
cellMin = v
|
||||||
end
|
end
|
||||||
end
|
--- sum of all cells
|
||||||
wgt.cellMin = cellMin
|
|
||||||
|
|
||||||
--- calc history lowest of all cells
|
|
||||||
if cellMin < wgt.cellDataHistoryCellLowest and cellMin > 1 then -- >1 to ignore invalid values
|
|
||||||
wgt.cellDataHistoryCellLowest = cellMin
|
|
||||||
end
|
|
||||||
|
|
||||||
wgt.cellCount = #newCellData
|
|
||||||
|
|
||||||
--- sum of all cells
|
|
||||||
local cellSum = 0
|
|
||||||
for k, v in pairs(newCellData) do
|
|
||||||
cellSum = cellSum + v
|
cellSum = cellSum + v
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
wgt.cellMin = cellMin
|
||||||
|
wgt.cellMax = cellMax
|
||||||
|
wgt.cellCount = #newCellData
|
||||||
wgt.cellSum = cellSum
|
wgt.cellSum = cellSum
|
||||||
|
|
||||||
--- average of all cells
|
--- average of all cells
|
||||||
@@ -328,7 +329,7 @@ local function refreshZoneLarge(wgt)
|
|||||||
|
|
||||||
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y, wgt.cellPercent .. "%", RIGHT + DBLSIZE + CUSTOM_COLOR + wgt.shadowed)
|
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y, wgt.cellPercent .. "%", RIGHT + DBLSIZE + CUSTOM_COLOR + wgt.shadowed)
|
||||||
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + 30, string.format("%2.1fV", wgt.mainValue), RIGHT + DBLSIZE + CUSTOM_COLOR + wgt.shadowed)
|
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + 30, string.format("%2.1fV", wgt.mainValue), RIGHT + DBLSIZE + CUSTOM_COLOR + wgt.shadowed)
|
||||||
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + 70, string.format("%2.1fV %2.1fS", wgt.secondaryValue, wgt.cellCount), RIGHT + SMLSIZE + CUSTOM_COLOR + wgt.shadowed)
|
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + 70, string.format("%2.1fV %dS", wgt.secondaryValue, wgt.cellCount), RIGHT + SMLSIZE + CUSTOM_COLOR + wgt.shadowed)
|
||||||
-- fill batt
|
-- fill batt
|
||||||
lcd.setColor(CUSTOM_COLOR, getPercentColor(wgt.cellPercent))
|
lcd.setColor(CUSTOM_COLOR, getPercentColor(wgt.cellPercent))
|
||||||
lcd.drawFilledRectangle(wgt.zone.x + myBatt.x, wgt.zone.y + myBatt.y + myBatt.h + myBatt.cath_h - math.floor(wgt.cellPercent / 100 * myBatt.h), myBatt.w, math.floor(wgt.cellPercent / 100 * myBatt.h), CUSTOM_COLOR)
|
lcd.drawFilledRectangle(wgt.zone.x + myBatt.x, wgt.zone.y + myBatt.y + myBatt.h + myBatt.cath_h - math.floor(wgt.cellPercent / 100 * myBatt.h), myBatt.w, math.floor(wgt.cellPercent / 100 * myBatt.h), CUSTOM_COLOR)
|
||||||
@@ -372,7 +373,7 @@ local function refreshZoneXLarge(wgt)
|
|||||||
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + myBatt.y, wgt.cellPercent .. "%", RIGHT + DBLSIZE + CUSTOM_COLOR + wgt.shadowed + wgt.no_telem_blink)
|
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + myBatt.y, wgt.cellPercent .. "%", RIGHT + DBLSIZE + CUSTOM_COLOR + wgt.shadowed + wgt.no_telem_blink)
|
||||||
|
|
||||||
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + myBatt.y + 30, string.format("%2.1fV", wgt.mainValue), RIGHT + DBLSIZE + CUSTOM_COLOR + wgt.shadowed + wgt.no_telem_blink)
|
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + myBatt.y + 30, string.format("%2.1fV", wgt.mainValue), RIGHT + DBLSIZE + CUSTOM_COLOR + wgt.shadowed + wgt.no_telem_blink)
|
||||||
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + myBatt.y + 105, string.format("%2.1fV %2.1fS", wgt.secondaryValue, wgt.cellCount), RIGHT + SMLSIZE + CUSTOM_COLOR + wgt.shadowed + wgt.no_telem_blink)
|
lcd.drawText(wgt.zone.x + wgt.zone.w, wgt.zone.y + myBatt.y + 105, string.format("%2.1fV %dS", wgt.secondaryValue, wgt.cellCount), RIGHT + SMLSIZE + CUSTOM_COLOR + wgt.shadowed + wgt.no_telem_blink)
|
||||||
|
|
||||||
-- draw cells
|
-- draw cells
|
||||||
local pos = { { x = 111, y = 38 }, { x = 164, y = 38 }, { x = 217, y = 38 }, { x = 111, y = 57 }, { x = 164, y = 57 }, { x = 217, y = 57 } }
|
local pos = { { x = 111, y = 38 }, { x = 164, y = 38 }, { x = 217, y = 38 }, { x = 111, y = 57 }, { x = 164, y = 57 }, { x = 217, y = 57 } }
|
||||||
|
|||||||
Reference in New Issue
Block a user