Skip to content

Low battery warning#1352

Merged
JF002 merged 21 commits intoInfiniTimeOrg:developfrom
minacode:battery-warning
Dec 27, 2022
Merged

Low battery warning#1352
JF002 merged 21 commits intoInfiniTimeOrg:developfrom
minacode:battery-warning

Conversation

@minacode
Copy link
Contributor

@minacode minacode commented Oct 3, 2022

This PR implements a low battery warning (issue #1342) when the battery percentage reaches 15%.
I added the threshold to the BatteryController that can be checked via BatteryController::BatteryIsLow().
The BatteryController sends a LowBattery message to the SystemTask that reacts by pushing a notification.

I also updated the BatteryInfo settings screen to use the threshold to color its charging bar differently.

@minacode
Copy link
Contributor Author

minacode commented Oct 3, 2022

I added a rescaling of the percentage values from 35-100 to 0-100 for better battery values and lowered the threshold to 20 (which corresponds to the 50 from before the rescaling).

Edit: removed this in the later commits.

@minacode minacode marked this pull request as ready for review October 3, 2022 13:09
@minacode minacode marked this pull request as draft October 9, 2022 20:03
@minacode minacode marked this pull request as ready for review October 10, 2022 16:01
@minacode
Copy link
Contributor Author

@NeroBurner, since the battery percentage is now fixed and you already accepted my PR for InfiniSim I would appreciate if you could also take a look at this PR. But no pressure, I know you have a lot to do.

@minacode minacode requested a review from NeroBurner November 20, 2022 23:12
Copy link
Contributor

@NeroBurner NeroBurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good, have just reviewed the code, not tested on InfiniSim or PineTime, currently out of time to check that

Comment on lines +431 to +432
"Low Battery\0Charge your watch to prevent data loss.\0"};
notif.message = message;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the temporary variable be omitted? just curious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The {} init syntax is needed to write the C string to the std::array. A simple assignment does not work as far as I know. My hope is that the compiler figures that out.
Cleaning up this interface would be nice though. The easiest two methods would be

  • moving the default fields id and valid to the end of the struct to allow unnamed struct initialization
  • C++20 allows C style init of structs with { .name = value }.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets leave it here as it is and I suggest that I make a PR in which I do the reordering.

@NeroBurner NeroBurner added this to the 1.12.0 milestone Dec 7, 2022
@minacode
Copy link
Contributor Author

minacode commented Dec 7, 2022

Thank you for taking the time you did! I will keep this updated.

@JF002
Copy link
Collaborator

JF002 commented Dec 7, 2022

Has anyone already had the opportunity to test this PR since we merged #1444 ? Does the low battery warning feels accurate?

@minacode
Copy link
Contributor Author

minacode commented Dec 7, 2022

I tested it for stability before, but can do it again for the feeling. You are asking if 15% are a good threshold value, right?

@JF002
Copy link
Collaborator

JF002 commented Dec 7, 2022

You are asking if 15% are a good threshold value, right?

Yes, and also if the battery level reported by the new algorithm works good enough for this use-case.

@minacode
Copy link
Contributor Author

minacode commented Dec 7, 2022

Ok, I will give it another try and report back in a few days.

@NeroBurner
Copy link
Contributor

15% gave me about 22 hours to charge the PineTime (although I think the current watch is at the upper limit of battery life with nearly 10 days from 100% to 0%)

no notification, just the linear interpolated battery curve

two full discharge curves:
Gadgetbridge two full discharge curves

Gadgetbridge 15% mark Gadgetbridge 12% mark Gadgetbridge 0% mark

@minacode
Copy link
Contributor Author

minacode commented Dec 7, 2022

Sounds good.

@minacode minacode mentioned this pull request Dec 8, 2022
@minacode
Copy link
Contributor Author

It just crashed at 15% battery and ended in a boot loop. Some of the last changes must have broken something 🤔 Good that we tested it again.

@minacode
Copy link
Contributor Author

My battery lasted approximately another day after reaching 15%. I saw 0%, so the new values are good on my watch.
We can set the threshold to 20% if you really want to be sure though.

Independently I fixed the crashes with a std::move but tested this with a threshold of 100% because I didn't want to wait so long for debugging 😉

@JF002 JF002 merged commit 298f80d into InfiniTimeOrg:develop Dec 27, 2022
@minacode minacode deleted the battery-warning branch December 27, 2022 15:00
FintasticMan added a commit to FintasticMan/InfiniTime that referenced this pull request Feb 3, 2023
Squashed commit of the following:

commit 11bdc2c
Merge: 59567a2 cb91943
Author: Riku Isokoski <riksu9000@gmail.com>
Date:   Tue Jan 31 22:05:04 2023 +0200

    Merge branch 'develop' into low-battery-indicator

commit 59567a2
Author: Riku Isokoski <riksu9000@gmail.com>
Date:   Sat Dec 31 10:05:38 2022 +0200

    Add low battery indicator to StatusIcons, digital and analog watchfaces

    Define deepOrange color in InfiniTimeTheme

commit 3e86ed2
Author: Riku Isokoski <riksu9000@gmail.com>
Date:   Sat Dec 31 09:56:03 2022 +0200

    Revert "added low battery message"

    This reverts PR InfiniTimeOrg#1352
Riksu9000 added a commit that referenced this pull request Mar 2, 2023
Ceimour pushed a commit to Ceimour/InfiniTime that referenced this pull request Mar 16, 2023
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

Successfully merging this pull request may close these issues.

4 participants