battery.h 753 B

123456789101112131415161718192021222324252627282930
  1. #pragma once
  2. #include <Arduino.h>
  3. // 18650 battery monitoring, read through the onboard divider on ADC1_CH3.
  4. //
  5. // The divider sits on the battery node, downstream of the charger, so there is
  6. // no way to tell "charging" from "full" here — only the cell voltage is
  7. // reported. See CLAUDE.md.
  8. namespace battery {
  9. void begin();
  10. // Samples the divider if BATTERY_READ_MS has elapsed. Call from loop().
  11. void loop();
  12. // Forces a reading now.
  13. void sample();
  14. // True once a plausible reading has been taken. False on a board with no cell
  15. // fitted and no sensible voltage present.
  16. bool hasReading();
  17. // Cell voltage in volts.
  18. float volts();
  19. // Remaining charge, 0-100, from a lithium-ion discharge curve.
  20. uint8_t percent();
  21. } // namespace battery