Speicher
This commit is contained in:
parent
bad613780e
commit
eb2309a6d7
1 changed files with 62 additions and 1 deletions
63
main.ino
63
main.ino
|
|
@ -1,4 +1,5 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Preferences.h>
|
||||||
#include <FastAccelStepper.h>
|
#include <FastAccelStepper.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
@ -53,7 +54,7 @@ struct settings{
|
||||||
int endMin = 0;
|
int endMin = 0;
|
||||||
bool timerEnabled = false;
|
bool timerEnabled = false;
|
||||||
bool editMaxTemp = false;
|
bool editMaxTemp = false;
|
||||||
int maxTemp = 70; //in °C
|
int16_t maxTemp = 70; //in °C
|
||||||
bool editAcc = false;
|
bool editAcc = false;
|
||||||
int32_t accelRate = 2000;
|
int32_t accelRate = 2000;
|
||||||
}
|
}
|
||||||
|
|
@ -68,12 +69,67 @@ enum TimeEditStep {
|
||||||
|
|
||||||
TimeEditStep timeEditStep = EDIT_NONE;
|
TimeEditStep timeEditStep = EDIT_NONE;
|
||||||
|
|
||||||
|
// fest in den Speicher schreiben
|
||||||
|
Preferences prefs;
|
||||||
|
|
||||||
|
// Dein Einstellungs-Struct
|
||||||
|
struct SystemSettings {
|
||||||
|
uint8_t startHour = 0;
|
||||||
|
uint8_t startMin = 0;
|
||||||
|
uint8_t endHour = 0;
|
||||||
|
uint8_t endMin = 0;
|
||||||
|
bool timerEnabled = false;
|
||||||
|
int16_t maxTemp = 70;
|
||||||
|
int32_t accelRate = 2000;
|
||||||
|
};
|
||||||
|
|
||||||
|
SystemSettings settings;
|
||||||
|
|
||||||
|
|
||||||
|
//#####################################
|
||||||
|
//########### Hilfsfunktion ###########
|
||||||
|
//#####################################
|
||||||
|
|
||||||
// Überladung des Präfix-Operators (++timeEditStep)
|
// Überladung des Präfix-Operators (++timeEditStep)
|
||||||
TimeEditStep& operator++(TimeEditStep& step) {
|
TimeEditStep& operator++(TimeEditStep& step) {
|
||||||
step = (step == EDIT_END_MIN) ? EDIT_NONE : static_cast<TimeEditStep>(step + 1);
|
step = (step == EDIT_END_MIN) ? EDIT_NONE : static_cast<TimeEditStep>(step + 1);
|
||||||
return step;
|
return step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Werte aus dem Flash speicher laden
|
||||||
|
void loadSettings() {
|
||||||
|
// Namespace öffnen (Name max. 15 Zeichen, "true" = read-only)
|
||||||
|
prefs.begin("timer_cfg", true);
|
||||||
|
|
||||||
|
// Werte auslesen
|
||||||
|
settings.startHour = prefs.getUChar("s_hour", 0);
|
||||||
|
settings.startMin = prefs.getUChar("s_min", 0);
|
||||||
|
settings.endHour = prefs.getUChar("e_hour", 0);
|
||||||
|
settings.endMin = prefs.getUChar("e_min", 0);
|
||||||
|
settings.timerEnabled = prefs.getBool("t_on", false);
|
||||||
|
settings.maxTemp = prefs.getShort("max_temp", 70);
|
||||||
|
settings.accelRate = prefs.getInt("accel_rate", 2000);
|
||||||
|
|
||||||
|
prefs.end();
|
||||||
|
Serial.println("[NVS] Einstellungen erfolgreich geladen.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save Settings in Flash Speichern
|
||||||
|
void saveSettings() {
|
||||||
|
prefs.begin("timer_cfg", false); // "false" = Read/Write
|
||||||
|
|
||||||
|
prefs.putUChar("s_hour", settings.startHour);
|
||||||
|
prefs.putUChar("s_min", settings.startMin);
|
||||||
|
prefs.putUChar("e_hour", settings.endHour);
|
||||||
|
prefs.putUChar("e_min", settings.endMin);
|
||||||
|
prefs.putBool("t_on", settings.timerEnabled);
|
||||||
|
prefs.putShort("max_temp", settings.maxTemp);
|
||||||
|
prefs.putInt("accel_rate", settings.accelRate);
|
||||||
|
|
||||||
|
prefs.end();
|
||||||
|
Serial.println("[NVS] Einstellungen im Flash gespeichert.");
|
||||||
|
}
|
||||||
|
|
||||||
void initWiFiAndTime() {
|
void initWiFiAndTime() {
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
|
@ -287,6 +343,8 @@ void setting(){
|
||||||
}else if (settings.settingIdx == 4) {
|
}else if (settings.settingIdx == 4) {
|
||||||
// Menü verlassen
|
// Menü verlassen
|
||||||
bSettings = false;
|
bSettings = false;
|
||||||
|
// Einstellungen Speichern
|
||||||
|
saveSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -338,6 +396,9 @@ void printStatus(FastAccelStepper *stepper, int speed, int clickPlus, int clickM
|
||||||
void loop() {
|
void loop() {
|
||||||
int32_t speed = 0;
|
int32_t speed = 0;
|
||||||
|
|
||||||
|
// Daten aus Flash speicher laden
|
||||||
|
loadSettings();
|
||||||
|
|
||||||
if (!stepper) {
|
if (!stepper) {
|
||||||
Serial.println("[HALT] Kein Stepper-Objekt aktiv.");
|
Serial.println("[HALT] Kein Stepper-Objekt aktiv.");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue