-
Notifications
You must be signed in to change notification settings - Fork 38
/
CWPreferences.h
72 lines (60 loc) · 2.43 KB
/
CWPreferences.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <Preferences.h>
Preferences preferences;
struct ClockwiseParams
{
const char* const PREF_SWAP_BLUE_GREEN = "swapBlueGreen";
const char* const PREF_USE_24H_FORMAT = "use24hFormat";
const char* const PREF_DISPLAY_BRIGHT = "displayBright";
const char* const PREF_DISPLAY_ABC_MIN = "autoBrightMin";
const char* const PREF_DISPLAY_ABC_MAX = "autoBrightMax";
const char* const PREF_LDR_PIN = "ldrPin";
const char* const PREF_TIME_ZONE = "timeZone";
const char* const PREF_WIFI_SSID = "wifiSsid";
const char* const PREF_WIFI_PASSWORD = "wifiPwd";
const char* const PREF_NTP_SERVER = "ntpServer";
bool swapBlueGreen;
bool use24hFormat;
uint8_t displayBright;
uint16_t autoBrightMin;
uint16_t autoBrightMax;
uint8_t ldrPin;
String timeZone;
String wifiSsid;
String wifiPwd;
String ntpServer;
ClockwiseParams() {
preferences.begin("clockwise", false);
//preferences.clear();
}
static ClockwiseParams* getInstance() {
static ClockwiseParams base;
return &base;
}
void save()
{
preferences.putBool(PREF_SWAP_BLUE_GREEN, swapBlueGreen);
preferences.putBool(PREF_USE_24H_FORMAT, use24hFormat);
preferences.putUInt(PREF_DISPLAY_BRIGHT, displayBright);
preferences.putUInt(PREF_DISPLAY_ABC_MIN, autoBrightMin);
preferences.putUInt(PREF_DISPLAY_ABC_MAX, autoBrightMax);
preferences.putUInt(PREF_LDR_PIN, ldrPin);
preferences.putString(PREF_TIME_ZONE, timeZone);
preferences.putString(PREF_WIFI_SSID, wifiSsid);
preferences.putString(PREF_WIFI_PASSWORD, wifiPwd);
preferences.putString(PREF_NTP_SERVER, ntpServer);
}
void load()
{
swapBlueGreen = preferences.getBool(PREF_SWAP_BLUE_GREEN, false);
use24hFormat = preferences.getBool(PREF_USE_24H_FORMAT, true);
displayBright = preferences.getUInt(PREF_DISPLAY_BRIGHT, 32);
autoBrightMin = preferences.getUInt(PREF_DISPLAY_ABC_MIN, 0);
autoBrightMax = preferences.getUInt(PREF_DISPLAY_ABC_MAX, 0);
ldrPin = preferences.getUInt(PREF_LDR_PIN, 35);
timeZone = preferences.getString(PREF_TIME_ZONE, "America/Sao_Paulo");
wifiSsid = preferences.getString(PREF_WIFI_SSID, "");
wifiPwd = preferences.getString(PREF_WIFI_PASSWORD, "");
ntpServer = preferences.getString(PREF_NTP_SERVER, NTP_SERVER);
}
};