#pragma once #include 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 shouldBlink() const; // For display int iconFillWidth(int maxWidth) const; private: static constexpr int PIN_BATTERY_ADC = 2; // Voltage divider input static constexpr int PIN_LBO = 5; // PowerBoost LBO pin static constexpr unsigned long CHECK_INTERVAL_MS = 2000; static constexpr int SAMPLES = 10; // Number of ADC samples to average // LiPo voltage thresholds static constexpr float VOLTAGE_MIN = 3.0; // 0% static constexpr float VOLTAGE_MAX = 4.2; // 100% static constexpr float VOLTAGE_LOW = 3.2; // Low battery threshold // Voltage divider: R1=100k, R2=100k (2:1 ratio) static constexpr float DIVIDER_RATIO = 2.0; int _percent = 100; float _voltage = 3.7; bool _isLow = false; unsigned long _lastCheckMs = 0; float readBatteryVoltage(); int voltageToPercent(float voltage); };