Refactor BatterySensor and Display classes to integrate MAX17048 and SH110X support

This commit is contained in:
Joshua King
2026-02-21 22:09:13 -05:00
parent 63061bdab2
commit df00d77ce1
5 changed files with 45 additions and 99 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include <Arduino.h>
#include <Adafruit_MAX1704X.h>
class BatterySensor {
public:
@@ -17,27 +18,18 @@ public:
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 int PIN_CHG = 4; // PowerBoost CHG pin (LOW when charging)
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;
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;
float readBatteryVoltage();
int voltageToPercent(float voltage);
void refresh();
};