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

Implement basic battery manager. #1142

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

kareltucek
Copy link
Collaborator

@kareltucek kareltucek commented Feb 20, 2025

Solves the most pressing issues of #974.

What it does:

  • implement controls that allow easily setting battery limits
  • implement a state machine that enables and disables the charger as needed
  • implement a charging mode for stationary use that targets 3.8V, and its macro controls
  • eliminate the big step of battery indicators between powered and unpowered states by:
    • when measuring the voltage, disable charging and allow the battery to settle for 500ms before measuring
    • apply a simple correction to the value as 500ms is not sufficient for the voltage to completely stabilize

What it does not do:

  • adaptively detect 100% voltage
  • it does not apply any artificial smoothing of the percentage
  • does not apply logarithmic correction to the battery percentage

@kareltucek
Copy link
Collaborator Author

This isn't tested very well yet.

@kareltucek kareltucek changed the title Implement basic battery manager. WIP: Implement basic battery manager. Feb 20, 2025
@kareltucek
Copy link
Collaborator Author

kareltucek commented Feb 21, 2025

Known issues:

  • battery presence detection is broken. fixed
  • there is still the step caused by whether battery is being drained or not during measurement. (I don't plan to fix this at the moment.)
  • i yet plan to implement shutdown mode when battery drops bellow "0". (It looks really bad when battery indicator says 0, but the keyboard still runs happily. implemented, although in a very basic manner.

@mondalaci
Copy link
Member

The code looks very good and well abstracted.

If the charger is disconnected, what policy will you implement for ChargeRegion_Empty vs. ChargeRegion_AlmostEmpty? It might be worth displaying Charge me on the OLED for either or both and not enabling per-key backlight in the first place.

@kareltucek
Copy link
Collaborator Author

For empty, uhk shuts down (as deep as I can make it).

Almost empty is just an auxiliarry region that makes sure that the keyboard doesnt oscillate between power on and off.

I am not displaying anything at the moment.

@mondalaci
Copy link
Member

Sounds reasonable.

Charge me may make sense for ChargeRegion_AlmostEmpty, but we'll see what works in practice.

@kareltucek
Copy link
Collaborator Author

I am not strictly against introducing the warning, but I would prefer to split into a separate issue (I am already writing another code on top of this, am not sure where to render it, and am not even sure we need it)...

@kareltucek kareltucek changed the title WIP: Implement basic battery manager. Implement basic battery manager. Feb 24, 2025
@kareltucek
Copy link
Collaborator Author

I think this is ready for merge.

@kareltucek
Copy link
Collaborator Author

Actually, not yet. Half will not wake up if restarted 🤦.

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

Successfully merging this pull request may close these issues.

2 participants