Skip to content
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

fix(BattAnalog): adapt lion voltage to 4.2 lion, graceful error if < 2.11 #181

Merged
merged 4 commits into from
Jan 19, 2025
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
7 changes: 4 additions & 3 deletions sdcard/c480x272/WIDGETS/BattAnalog/logic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ local percent_list_hv = {
{ {4.229, 91}, {4.237, 92}, {4.246, 93}, {4.254, 94}, {4.264, 95}, {4.278, 96}, {4.302, 97}, {4.320, 98}, {4.339, 99}, {4.350,100} },
}

local voltageRanges_lipo = {4.3, 8.6, 12.9, 17.2, 21.5, 25.8, 30.1, 34.4, 38.7, 43.0, 47.3, 51.6}
local voltageRanges_lion = {4.2, 8.4, 12.6, 16.8, 21, 25.2, 29.4, 33.6, 37.8, 42, 46.2, 50.4, 54.6}
local voltageRanges_hv = {4.45, 8.9, 13.35, 17.8, 22.25, 26.7, 31.15, 35.6, 40.05, 44.5, 48.95, 53.4, 57.85}
local voltageRanges_lipo = {4.30, 8.60, 12.90, 17.20, 21.50, 25.80, 30.10, 34.40, 38.70, 43.00, 47.30, 51.60}
--local voltageRanges_lion={4.20, 8.40, 12.60, 16.80, 21.00, 25.20, 29.40, 33.60, 37.80, 42.00, 46.20, 50.40}
local voltageRanges_lion = {4.30, 8.60, 12.90, 17.20, 21.50, 25.80, 30.10, 34.40, 38.70, 43.00, 47.30, 51.60}
local voltageRanges_hv = {4.45, 8.90, 13.35, 17.80, 22.25, 26.70, 31.15, 35.60, 40.05, 44.50, 48.95, 53.40}

--------------------------------------------------------------

Expand Down
33 changes: 15 additions & 18 deletions sdcard/c480x272/WIDGETS/BattAnalog/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
-- Author : Offer Shmuely
-- Date: 2021-2024
local app_name = "BattAnalog"
local app_ver = "1.1"
local app_ver = "1.2"

local CELL_DETECTION_TIME = 8
local lib_sensors = loadScript("/WIDGETS/" .. app_name .. "/lib_sensors.lua", "tcd")(m_log,app_name)
Expand Down Expand Up @@ -88,6 +88,20 @@ local function update(wgt, options)
-- wgt.log("batt_11 width: " .. wgt.batt_width .. ", height: " .. wgt.batt_height)


local ver, radio, maj, minor, rev, osname = getVersion()
wgt.is_valid_ver = (maj == 2 and minor >= 11)
if wgt.is_valid_ver==false then
local lytIvalidVer = {
{
type=LVGL_DEF.type.LABEL, x=0, y=0, font=0,
text="!! this widget \nis supported only \non ver 2.11 and above",
color=RED
}
}
lvgl.build(lytIvalidVer)
return
end

wgt.update_logic(wgt, options)
wgt.update_ui()
end
Expand All @@ -104,23 +118,6 @@ local function getDxByStick(stk)
end

local function refresh(wgt, event, touchState)
local is_need_update = false

local dw = getDxByStick("ail")
wgt.batt_width = wgt.batt_width + dw
wgt.batt_width = math.max(10, math.min(480, wgt.batt_width))
is_need_update = is_need_update or (dw ~= 0)

local dh = getDxByStick("ele")
wgt.batt_height = wgt.batt_height - dh
wgt.batt_height = math.max(10, math.min(272, wgt.batt_height))
is_need_update = is_need_update or (dh ~= 0)

if (is_need_update == true) then
wgt.zone.w = wgt.batt_width
wgt.zone.h = wgt.batt_height
wgt.update_ui()
end

wgt.refresh(event, touchState)
end
Expand Down
2 changes: 1 addition & 1 deletion sdcard/c480x272/WIDGETS/BattAnalog/ui_lvgl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ local function layoutTextZoneNormal(batSize)
sec_dh = ts_h + 5
line_space = ts_h * 0
sec_x = math.min(sec_x, wgt.zone.w -ts_w -space)
txtSizes.source = {y=wgt.zone.h +v_offset -space +line_space -sec_dh*3, visible=(function() return wgt.options.isTotalVoltage == 0 end), visible = true}
txtSizes.source = {y=wgt.zone.h +v_offset -space +line_space -sec_dh*3, visible=(function() return wgt.options.isTotalVoltage == 0 end)}


-- vSec + cell count
Expand Down
Loading