- Neue Kategorie Extras: Lampe in wählbarer Farbe, Laufschrift mit eigener 5-LED-Schrift (A-Z, ÄÖÜß, Ziffern, Satzzeichen, °, ♥), Uhr per NTP, Wetter von Open-Meteo (eigener Task auf Kern 0, alle 15 min) - Favoriten: bis zu 12, aus den Favoriten gestartet wechselt der Würfel nur durch sie (playFavorites) - Effekt, Autowechsel, Helligkeit, Favoriten, Lampenfarbe, Text und Ort werden 2 s nach einer Änderung im NVS gespeichert und beim Start geladen - API: neue Felder in /api/state, GET /api/weather - App: Favoriten-Zeile, langes Drücken = Favorit, Einstellungen für Lampe, Laufschrift und Wetter-Ort (Suche über Open-Meteo) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
2.5 KiB
C++
74 lines
2.5 KiB
C++
// Einstellungen im Flash (NVS), damit der Würfel nach dem Ausschalten dort
|
|
// weitermacht, wo er war: Effekt, automatischer Wechsel, Helligkeit, Favoriten,
|
|
// Farbe der Lampe, Laufschrift und Ort fürs Wetter.
|
|
// Gespeichert wird erst 2 s nach der letzten Änderung, damit z. B. ein Regler,
|
|
// der viele Änderungen schickt, nicht jedes Mal den Flash beschreibt.
|
|
|
|
#include "cube.h"
|
|
#include <Preferences.h>
|
|
|
|
static Preferences prefs;
|
|
static bool dirty = false;
|
|
static uint32_t changedAt = 0;
|
|
|
|
void settingsChanged() {
|
|
dirty = true;
|
|
changedAt = millis();
|
|
}
|
|
|
|
static String loadString(const char *key, const char *fallback) {
|
|
return prefs.isKey(key) ? prefs.getString(key, fallback) : String(fallback);
|
|
}
|
|
|
|
void settingsLoad() {
|
|
prefs.begin("cube", false);
|
|
setBaseBrightness(prefs.getUChar("brightness", BRIGHTNESS));
|
|
autoAdvance = prefs.getBool("auto", true);
|
|
autoAll = prefs.getBool("all", false);
|
|
playFavorites = prefs.getBool("playFav", false);
|
|
|
|
// Favoriten als ids mit Komma; unbekannte (z. B. nach einem Update) fallen weg
|
|
String favs = loadString("favorites", "");
|
|
uint8_t list[MAX_FAVORITES], n = 0;
|
|
for (int start = 0; start < (int)favs.length() && n < MAX_FAVORITES;) {
|
|
int end = favs.indexOf(',', start);
|
|
if (end < 0) end = favs.length();
|
|
int i = findEffect(favs.substring(start, end).c_str());
|
|
if (i >= 0) list[n++] = i;
|
|
start = end + 1;
|
|
}
|
|
setFavorites(list, n);
|
|
|
|
lampColor = CRGB(prefs.getUInt("lamp", 0xFFA03C));
|
|
tickerText = loadString("text", "HALLO");
|
|
setLocation(loadString("place", "").c_str(), prefs.getFloat("lat", 0), prefs.getFloat("lon", 0));
|
|
|
|
int effect = findEffect(loadString("effect", "").c_str());
|
|
if (effect >= 0) selectEffect(effect);
|
|
}
|
|
|
|
void settingsUpdate(uint32_t now) {
|
|
if (!dirty || now - changedAt < 2000) return;
|
|
dirty = false;
|
|
prefs.putString("effect", effectId(currentEffect()));
|
|
prefs.putUChar("brightness", brightness);
|
|
prefs.putBool("auto", autoAdvance);
|
|
prefs.putBool("all", autoAll);
|
|
prefs.putBool("playFav", playFavorites);
|
|
String favs;
|
|
for (uint8_t k = 0; k < numFavorites(); k++) {
|
|
if (k) favs += ',';
|
|
favs += effectId(favorite(k));
|
|
}
|
|
prefs.putString("favorites", favs);
|
|
prefs.putUInt("lamp", uint32_t(lampColor.r) << 16 | uint32_t(lampColor.g) << 8 | lampColor.b);
|
|
prefs.putString("text", tickerText);
|
|
char place[48];
|
|
float lat, lon;
|
|
getLocation(place, sizeof(place), lat, lon);
|
|
prefs.putString("place", place);
|
|
prefs.putFloat("lat", lat);
|
|
prefs.putFloat("lon", lon);
|
|
Serial.println("Einstellungen gespeichert");
|
|
}
|