Giter Club home page Giter Club logo

Comments (14)

ClementTsang avatar ClementTsang commented on July 19, 2024 1

Btw if upstream doesn't respond after a while, I can also look into forking the crate and including your fix to help get it out.

from bottom.

WenqingZong avatar WenqingZong commented on July 19, 2024 1

Btw if upstream doesn't respond after a while, I can also look into forking the crate and including your fix to help get it out.

The upstream approves my PR, waiting for someone to merge it.

from bottom.

ClementTsang avatar ClementTsang commented on July 19, 2024

Thanks, can reproduce. It's probably an issue with an upstream dependency, I'll investigate.

from bottom.

ClementTsang avatar ClementTsang commented on July 19, 2024

Hm. Just some rambling as I debug this issue.

So I'm wondering if something's strange with what macOS reports - if I run ioreg -l -w0 | grep Capacity to get battery stats:

"MaxCapacity" = 100
"DesignCapacity" = 6075
"AppleRawMaxCapacity" = 5643

Which gives a calculated "battery health" of ~1.65 percent, if you divide the current max capacity by the designed capacity. This is how the library bottom uses calculates it, which you can see if you run btm --battery

image

Matches perfectly, 1.65%.


But as you noted, this is definitely wrong, if I check in settings, I have about 97% battery health. But I'm also not sure what I'm supposed to do then if what macOS is spitting out seems... wrong then? I could try using the raw max value which is closer, but that's still wrong (5643 / 6075 gives 93%, which still doesn't match what I see in Settings).

from bottom.

ClementTsang avatar ClementTsang commented on July 19, 2024

And right as I post the comment, I think I figured out what I need... but I might need some extra information.

I think the columns I need are AppleRawMaxCapacity and NominalChargeCapacity - for me, this is:

"NominalChargeCapacity" = 5793
"AppleRawMaxCapacity" = 5643

5643 / 5793 = 97.4% - which is what I see in Settings! So this might be it - if it is, I'll submit and/or fork a patch.

Could you help me confirm if this is the case by running ioreg -l -w0 | grep Capacity and giving me back:

  • NominalChargeCapacity
  • AppleRawMaxCapacity
  • MaxCapacity
  • DesignCapacity

Thanks!

from bottom.

WenqingZong avatar WenqingZong commented on July 19, 2024

Hi, glad to receive your timely reply, here is what I get:

NominalChargeCapacity 4507
AppleRawMaxCapacity 4377
MaxCapacity 100
DesignCapacity 4382

BTW, there is a Health Information section if you run system_profiler detailLevel=mini SPPowerDataType, but as it also reports Maximum Capacity so I'm not sure if it's what we need here.

from bottom.

WenqingZong avatar WenqingZong commented on July 19, 2024

If it's possible, can I get the honour to fix this issue? I'm a recent graduate and seeking opportunities to build my reputation and contribution to FOSS.

from bottom.

ClementTsang avatar ClementTsang commented on July 19, 2024

Go for it! I think the best place to look to make a change is https://github.com/starship/rust-battery to fix it upstream for everyone.

from bottom.

WenqingZong avatar WenqingZong commented on July 19, 2024

Somehow I feel the bug is caused by different physics units. rust-battery represents energy in joule, but MacOS returns energy in mAh.

from bottom.

WenqingZong avatar WenqingZong commented on July 19, 2024

Well, I got stuck at fixing it, and might need your help. My modifications cannot satisfy both our cases.

Your case:

"MaxCapacity" = 100
"DesignCapacity" = 6075
"AppleRawMaxCapacity" = 5643
"NominalChargeCapacity" = 5793

and ground truth battery health: 97%

My case:

AppleRawCurrentCapacity = 3338
AppleRawMaxCapacity = 4380
DesignCapacity = 4382
NominalChargeCapacity = 4515

and ground truth battery percentage: 80%, ground truth battery health: 100%

In file rust-battery/src/platform/darwin/iokit/power_source.rs, if I change

static MAX_CAPACITY_KEY: &str = "MaxCapacity";
static CURRENT_CAPACITY_KEY: &str = "CurrentCapacity";

to

static MAX_CAPACITY_KEY: &str = "AppleRawMaxCapacity";
static CURRENT_CAPACITY_KEY: &str = "AppleRawCurrentCapacity";

then it match my battery health, but does not match my battery percentage and your battery health.

If, in addition to the previous two modifications, change:

static DESIGN_CAPACITY_KEY: &str = "DesignCapacity";

to

static DESIGN_CAPACITY_KEY: &str = "NominalChargeCapacity";

Then, it does not match my percentage and health, but can match yours. :-(

Currently I have no idea why it bahaves in such a strange way. The only thing I can think of is I turned on Charge on hold, but I don't think it makes a difference.

I'd appreciate it if you could give me some guidelines/ideas. Cheers.

from bottom.

ClementTsang avatar ClementTsang commented on July 19, 2024

Some quick looking around gives this thread which might be helpful to take a peek at. Note that whatever bottom/starship-battery is doing on at least M1, it's definitely wrong, so it does need to change for sure.

Also I'm curious if anyone has an Intel macbook to see if this is just an Apple Silicon issue or an overall macOS issue.

from bottom.

WenqingZong avatar WenqingZong commented on July 19, 2024

Merge Request created: starship/rust-battery#33

This fix only affects M-series-chip Mac as we have no idea if it's a bug for Intel-chip Mac.

I'll accept the fact that Apple might use some other data source to calculate battery percentage to deliver a better "user experience".

from bottom.

WenqingZong avatar WenqingZong commented on July 19, 2024

PR merged, and this bug will be fixed in the next version, 0.8.1, of rust-battery. \o/

Happy to be a FOSS contributor :-)

from bottom.

ClementTsang avatar ClementTsang commented on July 19, 2024

Thanks for fixing this! I'll make the relevant dependency bumps to include your fix (or if you want, you can also feel free to submit a PR), and I'll probably do a stable release sometime this week that fixes a few bugs.

from bottom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.