36 lines
832 B
C++
36 lines
832 B
C++
#pragma once
|
|
#include <Arduino.h>
|
|
#include <Adafruit_MAX1704X.h>
|
|
|
|
class BatterySensor {
|
|
public:
|
|
void begin();
|
|
void loop();
|
|
|
|
// Battery status
|
|
int percent() const { return _percent; }
|
|
float voltage() const { return _voltage; }
|
|
bool isLow() const { return _isLow; }
|
|
bool isCharging() const { return _isCharging; }
|
|
bool shouldBlink() const;
|
|
|
|
// For display
|
|
int iconFillWidth(int maxWidth) const;
|
|
|
|
private:
|
|
static constexpr unsigned long CHECK_INTERVAL_MS = 2000;
|
|
|
|
static constexpr float VOLTAGE_LOW = 3.2; // Low battery threshold
|
|
static constexpr float CHARGE_RATE_MIN_PCT_PER_HR = 0.2f; // heuristic
|
|
|
|
int _percent = 100;
|
|
float _voltage = 3.7;
|
|
bool _isLow = false;
|
|
bool _isCharging = false;
|
|
unsigned long _lastCheckMs = 0;
|
|
bool _ok = false;
|
|
Adafruit_MAX17048 _maxlipo;
|
|
|
|
void refresh();
|
|
};
|