114 lines
3.2 KiB
C
114 lines
3.2 KiB
C
#pragma once
|
|
#include <Arduino.h>
|
|
#include <Preferences.h>
|
|
|
|
#include <licenceing.h>
|
|
#include <master.h>
|
|
|
|
// Persist and load button configuration
|
|
void saveButtonConfig() {
|
|
preferences.begin("buttons", false);
|
|
preferences.putBytes("config", &buttonConfigs, sizeof(buttonConfigs));
|
|
preferences.end();
|
|
}
|
|
|
|
void loadButtonConfig() {
|
|
preferences.begin("buttons", true);
|
|
size_t schLen = preferences.getBytesLength("config");
|
|
if (schLen == sizeof(buttonConfigs)) {
|
|
preferences.getBytes("config", &buttonConfigs, schLen);
|
|
}
|
|
preferences.end();
|
|
}
|
|
|
|
// Persist and load best times
|
|
void saveBestTimes() {
|
|
preferences.begin("times", false);
|
|
preferences.putULong("best1", timerData1.bestTime);
|
|
preferences.putULong("best2", timerData2.bestTime);
|
|
preferences.end();
|
|
}
|
|
|
|
void loadBestTimes() {
|
|
preferences.begin("times", true);
|
|
timerData1.bestTime = preferences.getULong("best1", 0);
|
|
timerData2.bestTime = preferences.getULong("best2", 0);
|
|
preferences.end();
|
|
}
|
|
|
|
// Persist and load general settings
|
|
void saveSettings() {
|
|
preferences.begin("settings", false);
|
|
preferences.putULong("maxTime", maxTimeBeforeReset);
|
|
preferences.putULong("maxTimeDisplay", maxTimeDisplay);
|
|
preferences.putUInt("gamemode", gamemode);
|
|
preferences.putUInt("laneConfigType", laneConfigType);
|
|
preferences.putUInt("lane1Diff", lane1DifficultyType);
|
|
preferences.putUInt("lane2Diff", lane2DifficultyType);
|
|
preferences.end();
|
|
}
|
|
|
|
void loadSettings() {
|
|
preferences.begin("settings", true);
|
|
maxTimeBeforeReset = preferences.getULong("maxTime", 300000);
|
|
maxTimeDisplay = preferences.getULong("maxTimeDisplay", 20000);
|
|
gamemode = preferences.getUInt("gamemode", 0);
|
|
laneConfigType = preferences.getUInt("laneConfigType", 0);
|
|
lane1DifficultyType = preferences.getUInt("lane1Diff", 0);
|
|
lane2DifficultyType = preferences.getUInt("lane2Diff", 0);
|
|
preferences.end();
|
|
}
|
|
|
|
// Persist and load WiFi settings
|
|
void saveWifiSettings() {
|
|
preferences.begin("wifi", false);
|
|
preferences.putString("ssid", ssidSTA);
|
|
preferences.putString("password", passwordSTA);
|
|
preferences.end();
|
|
delay(500);
|
|
ESP.restart();
|
|
}
|
|
|
|
void loadWifiSettings() {
|
|
preferences.begin("wifi", true);
|
|
String ssid = preferences.getString("ssid", "");
|
|
String password = preferences.getString("password", "");
|
|
ssidSTA = strdup(ssid.c_str());
|
|
passwordSTA = strdup(password.c_str());
|
|
preferences.end();
|
|
}
|
|
|
|
// Persist and load location settings
|
|
void loadLocationSettings() {
|
|
preferences.begin("location", true);
|
|
masterlocation = preferences.getString("location", "");
|
|
preferences.end();
|
|
}
|
|
|
|
void saveLocationSettings() {
|
|
preferences.begin("location", false);
|
|
preferences.putString("location", masterlocation);
|
|
preferences.end();
|
|
}
|
|
|
|
// Licence helper
|
|
int checkLicence() {
|
|
loadLicenceFromPrefs();
|
|
String id = getUniqueDeviceID();
|
|
int tier = getLicenseTier(id, licence);
|
|
return tier;
|
|
}
|
|
|
|
void saveLocationIdToPrefs(const String &locationId) {
|
|
preferences.begin("locationid", false);
|
|
preferences.putString("locationid", locationId);
|
|
preferences.end();
|
|
}
|
|
|
|
String getLocationIdFromPrefs() {
|
|
preferences.begin("locationid", true);
|
|
String locationId = preferences.getString("locationid", "");
|
|
preferences.end();
|
|
return locationId;
|
|
}
|