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:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "../ui/Display.h"
|
||||
#include "../sensors/MoistureSensor.h"
|
||||
#include "../sensors/BatterySensor.h"
|
||||
#include "../ui/FaceRenderer.h"
|
||||
|
||||
static Settings settings;
|
||||
@@ -21,6 +22,7 @@ static WebhookService webhook;
|
||||
|
||||
static Display display;
|
||||
static MoistureSensor moisture;
|
||||
static BatterySensor battery;
|
||||
static FaceRenderer face;
|
||||
|
||||
static unsigned long bootMs = 0;
|
||||
@@ -37,15 +39,27 @@ static PlantEventType moodToEvent(FaceRenderer::Mood m) {
|
||||
void App::setup() {
|
||||
bootMs = millis();
|
||||
|
||||
Serial.begin(115200);
|
||||
delay(100);
|
||||
Serial.println("\n\n=== FacePlant Starting ===");
|
||||
Serial.print("Firmware: ");
|
||||
Serial.println(PB_VERSION);
|
||||
|
||||
settings.begin();
|
||||
bool forceSetup = BootTrigger::checkAndConsume();
|
||||
|
||||
Serial.print("Force setup mode: ");
|
||||
Serial.println(forceSetup ? "YES" : "NO");
|
||||
Serial.print("Saved WiFi SSID: ");
|
||||
Serial.println(settings.hasWiFi() ? settings.wifiSsid() : "(none)");
|
||||
|
||||
display.begin();
|
||||
display.showStatus("FacePlant", "Starting...");
|
||||
|
||||
wifi.begin(settings, forceSetup);
|
||||
|
||||
moisture.begin(settings);
|
||||
battery.begin();
|
||||
face.begin(display, settings);
|
||||
|
||||
webhook.begin(settings);
|
||||
@@ -55,16 +69,39 @@ void App::setup() {
|
||||
|
||||
lastMood = face.mood();
|
||||
lastDead = face.isDeadMode();
|
||||
|
||||
Serial.println("=== Setup Complete ===\n");
|
||||
}
|
||||
|
||||
void App::loop() {
|
||||
static bool lastConnected = false;
|
||||
static unsigned long lastDisplayUpdate = 0;
|
||||
|
||||
BootTrigger::clearAfterStableUptime();
|
||||
|
||||
wifi.loop();
|
||||
web.loop();
|
||||
|
||||
// Show WiFi status on display during connection attempts
|
||||
bool currentConnected = wifi.connected();
|
||||
if (currentConnected != lastConnected) {
|
||||
if (currentConnected) {
|
||||
Serial.println("[App] WiFi connected - showing on display");
|
||||
display.showStatus("WiFi Connected!", wifi.ssid().c_str());
|
||||
delay(2000);
|
||||
} else if (wifi.mode() == NET_STA) {
|
||||
Serial.println("[App] WiFi disconnected");
|
||||
if (millis() - lastDisplayUpdate > 5000) {
|
||||
display.showStatus("WiFi", "Connecting...");
|
||||
lastDisplayUpdate = millis();
|
||||
}
|
||||
}
|
||||
lastConnected = currentConnected;
|
||||
}
|
||||
|
||||
moisture.loop();
|
||||
face.loop(moisture);
|
||||
battery.loop();
|
||||
face.loop(moisture, battery);
|
||||
|
||||
// Webhook events on state transitions
|
||||
FaceRenderer::Mood m = face.mood();
|
||||
|
||||
Reference in New Issue
Block a user