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:
@@ -29,7 +29,7 @@ void FaceRenderer::begin(Display& display, Settings& settings) {
|
||||
_nextGazeMs = now + randRange(800, 2000);
|
||||
}
|
||||
|
||||
void FaceRenderer::loop(const MoistureSensor& moisture) {
|
||||
void FaceRenderer::loop(const MoistureSensor& moisture, const BatterySensor& battery) {
|
||||
unsigned long now = millis();
|
||||
if ((long)(now - _nextFrameMs) < 0) return;
|
||||
_nextFrameMs = now + FRAME_MS;
|
||||
@@ -38,7 +38,7 @@ void FaceRenderer::loop(const MoistureSensor& moisture) {
|
||||
updateDeathMode(now);
|
||||
|
||||
if (_deadMode) {
|
||||
renderDead(now);
|
||||
renderDead(now, battery);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ void FaceRenderer::loop(const MoistureSensor& moisture) {
|
||||
else if (_mood == DRY) updateDry(now);
|
||||
else updateTooWet(now);
|
||||
|
||||
renderNormal(now);
|
||||
renderNormal(now, battery);
|
||||
}
|
||||
|
||||
void FaceRenderer::updateMood(int moisturePct) {
|
||||
@@ -125,7 +125,7 @@ void FaceRenderer::updateTooWet(unsigned long now) {
|
||||
if (_blinking && (long)(now - _blinkUntilMs) >= 0) _blinking = false;
|
||||
}
|
||||
|
||||
void FaceRenderer::renderDead(unsigned long now) {
|
||||
void FaceRenderer::renderDead(unsigned long now, const BatterySensor& battery) {
|
||||
auto &d = _display->oled();
|
||||
d.clearDisplay();
|
||||
|
||||
@@ -145,10 +145,13 @@ void FaceRenderer::renderDead(unsigned long now) {
|
||||
drawMouthFlat();
|
||||
}
|
||||
|
||||
// Draw battery icon in top-right corner
|
||||
_display->drawBatteryIcon(110, 2, battery.percent(), battery.shouldBlink());
|
||||
|
||||
d.display();
|
||||
}
|
||||
|
||||
void FaceRenderer::renderNormal(unsigned long now) {
|
||||
void FaceRenderer::renderNormal(unsigned long now, const BatterySensor& battery) {
|
||||
auto &d = _display->oled();
|
||||
d.clearDisplay();
|
||||
|
||||
@@ -173,6 +176,9 @@ void FaceRenderer::renderNormal(unsigned long now) {
|
||||
drawBubbles((now / 100) % 12 - 6);
|
||||
}
|
||||
|
||||
// Draw battery icon in top-right corner
|
||||
_display->drawBatteryIcon(110, 2, battery.percent(), battery.shouldBlink());
|
||||
|
||||
d.display();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user