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

BattAnalog widget shows 1% when battery is fully charged #166

Open
LoooooKe opened this issue Oct 3, 2024 · 7 comments
Open

BattAnalog widget shows 1% when battery is fully charged #166

LoooooKe opened this issue Oct 3, 2024 · 7 comments

Comments

@LoooooKe
Copy link

LoooooKe commented Oct 3, 2024

The BattAnalog widget shows 1% when the battery is fully charged. I narrowed it down to the following line:

if singleVoltage < voltageRanges[i] then

If the voltage is equal or even .01 above the value in voltageRange, the method returns the wrong cell count, which then leads to a wrong calculation of the cellPercentage value here:

wgt.vCellLive = wgt.vTotalLive / wgt.cellCount

My suggestion is to round singleVoltage to one decimal and change the '<' to a '<='. This should fix the issue for all battery types.

@offer-shmuely
Copy link
Contributor

can you explain why it is happen in your scenario?
what voltage do you get on full, and what type of battery?

your suggestion can work, thanks
an another way will be to just enlarge a little the voltageRange array values.
but lets first understand way it is happening

image

@LoooooKe
Copy link
Author

Battery is 2S LI-Ion and the total voltage is like 8.41. I tried to enlarge the range but this didn't work because the cellCount is wrong. That's why I came up with this working solution:

-- Only invoke this function once.
local function calcCellCount(wgt, singleVoltage)
    local voltageRanges = voltageRanges_lipo
    local singleVoltageRounded = math.floor(singleVoltage*10)/10

    if wgt.options.Lithium_Ion == 1 and wgt.options.Lithium_HV == 0 then
        voltageRanges = voltageRanges_lion
    end
    if wgt.options.Lithium_Ion == 0 and wgt.options.Lithium_HV == 1 then
        voltageRanges = voltageRanges_hv
    end

    for i = 1, #voltageRanges do
        if singleVoltageRounded <= voltageRanges[i] then
            log("calcCellCount %s --> %s", singleVoltageRounded, i)
            return i
        end
    end

    log("no match found" .. singleVoltage)
    return 1
end

@offer-shmuely
Copy link
Contributor

isn't li-ion charge to 4.1v?
so you should get 8.2v

@pfeerick
Copy link
Member

No always... some li-ion are 4.1, some are 4.2.

@offer-shmuely
Copy link
Contributor

So i need to enlarge the voltage level of separation

@offer-shmuely
Copy link
Contributor

I updated the rates of the li-ion ranges
please try the test version at
https://github.com/offer-shmuely/edgetx-x10-widgets/tree/master/WIDGETS/BattAnalog

and update me here.

@offer-shmuely
Copy link
Contributor

@LoooooKe - reminder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants