Add Battery Sensor functionality and integrate with display and app

- Implement BatterySensor class to monitor battery voltage and status.
- Update App to initialize and loop BatterySensor.
- Modify FaceRenderer to display battery status on the screen.
- Enhance Display class with a method to draw battery icon.
- Update WebUI to include battery status in the interface.
- Refactor WiFiManager to improve connection handling and logging.
- Adjust Settings to include factory reset functionality.
- Improve HTML structure and styling in WebUI for better user experience.
This commit is contained in:
Joshua King
2026-02-10 17:05:42 -05:00
parent 483507e26c
commit 0b627ffa75
12 changed files with 536 additions and 47 deletions

View File

@@ -0,0 +1,40 @@
#pragma once
#include <Arduino.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 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);
};