Initial Commit

This commit is contained in:
Joshua King
2026-02-09 11:41:12 -05:00
commit 558c209b6c
31 changed files with 1399 additions and 0 deletions

46
src/settings/Settings.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include "Settings.h"
static PlantThresholds thresholdsForProfile(const String& key) {
if (key == "succulent") return {20, 28, 80};
if (key == "herbs") return {35, 42, 88};
if (key == "tropical") return {45, 52, 90};
if (key == "fern") return {55, 62, 92};
if (key == "veg") return {40, 48, 90};
return {35, 42, 85}; // houseplant default
}
void Settings::begin() {
_prefs.begin("faceplant", false);
}
bool Settings::everConnected() const { return _prefs.getBool("ever_ok", false); }
void Settings::setEverConnected(bool v) { _prefs.putBool("ever_ok", v); }
bool Settings::hasWiFi() const { return _prefs.getString("wifi_ssid", "").length() > 0; }
String Settings::wifiSsid() const { return _prefs.getString("wifi_ssid", ""); }
String Settings::wifiPass() const { return _prefs.getString("wifi_pass", ""); }
void Settings::saveWiFi(const String& ssid, const String& pass) {
_prefs.putString("wifi_ssid", ssid);
_prefs.putString("wifi_pass", pass);
}
void Settings::clearWiFi() { _prefs.remove("wifi_ssid"); _prefs.remove("wifi_pass"); }
String Settings::plantProfile() const { return _prefs.getString("plant_profile", "house"); }
void Settings::setPlantProfile(const String& key) { _prefs.putString("plant_profile", key); }
PlantThresholds Settings::thresholds() const { return thresholdsForProfile(plantProfile()); }
int Settings::dryRaw() const { return _prefs.getInt("cal_dry_raw", 3000); }
int Settings::wetRaw() const { return _prefs.getInt("cal_wet_raw", 1600); }
void Settings::setCalibration(int dryRaw, int wetRaw) {
_prefs.putInt("cal_dry_raw", dryRaw);
_prefs.putInt("cal_wet_raw", wetRaw);
}
bool Settings::kidsMode() const { return _prefs.getBool("kids_mode", false); }
void Settings::setKidsMode(bool v) { _prefs.putBool("kids_mode", v); }
bool Settings::webhookEnabled() const { return _prefs.getBool("wh_en", false); }
void Settings::setWebhookEnabled(bool v) { _prefs.putBool("wh_en", v); }
String Settings::webhookUrl() const { return _prefs.getString("wh_url", ""); }
void Settings::setWebhookUrl(const String& url) { _prefs.putString("wh_url", url); }

48
src/settings/Settings.h Normal file
View File

@@ -0,0 +1,48 @@
#pragma once
#include <Arduino.h>
#include <Preferences.h>
struct PlantThresholds {
int dryPct;
int okPct;
int tooWetPct;
};
class Settings {
public:
void begin();
// Product state
bool everConnected() const;
void setEverConnected(bool v);
// Wi-Fi
bool hasWiFi() const;
String wifiSsid() const;
String wifiPass() const;
void saveWiFi(const String& ssid, const String& pass);
void clearWiFi();
// Plant profile
String plantProfile() const;
void setPlantProfile(const String& key);
PlantThresholds thresholds() const;
// Calibration
int dryRaw() const;
int wetRaw() const;
void setCalibration(int dryRaw, int wetRaw);
// Kids mode
bool kidsMode() const;
void setKidsMode(bool v);
// Webhook
bool webhookEnabled() const;
void setWebhookEnabled(bool v);
String webhookUrl() const;
void setWebhookUrl(const String& url);
private:
mutable Preferences _prefs;
};