-
Notifications
You must be signed in to change notification settings - Fork 7
/
Settings.cpp
139 lines (109 loc) · 2.83 KB
/
Settings.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/******************************************************************************
Settings.cpp
******************************************************************************/
#include "Settings.h"
Settings::Settings() {
loadFromEEPROM();
}
uint8_t Settings::getLanguage() {
return mySettings.language;
}
void Settings::setLanguage(uint8_t language) {
mySettings.language = language;
}
boolean Settings::getUseLdr() {
return mySettings.useLdr;
}
void Settings::toggleUseLdr() {
mySettings.useLdr = !mySettings.useLdr;
}
int16_t Settings::getBrightness() {
return mySettings.brightness;
}
void Settings::setBrightness(int16_t ledBrightness) {
mySettings.brightness = ledBrightness;
}
void Settings::setColor(uint8_t color) {
mySettings.color = color;
}
uint8_t Settings::getColor() {
return mySettings.color;
}
uint8_t Settings::getTimeout() {
return mySettings.timeout;
}
void Settings::setTimeout(uint8_t timeout) {
mySettings.timeout = timeout;
}
boolean Settings::getEsIst() {
return mySettings.esIst;
}
void Settings::toggleEsIst() {
mySettings.esIst = !mySettings.esIst;
}
boolean Settings::getAlarm1() {
return mySettings.alarm1;
}
void Settings::toggleAlarm1() {
mySettings.alarm1 = !mySettings.alarm1;
}
time_t Settings::getAlarmTime1() {
return mySettings.alarmTime1;
}
void Settings::setAlarmTime1(time_t alarmTime) {
mySettings.alarmTime1 = alarmTime;
}
boolean Settings::getAlarm2() {
return mySettings.alarm2;
}
void Settings::toggleAlarm2() {
mySettings.alarm2 = !mySettings.alarm2;
}
time_t Settings::getAlarmTime2() {
return mySettings.alarmTime2;
}
void Settings::setAlarmTime2(time_t alarmTime) {
mySettings.alarmTime2 = alarmTime;
}
time_t Settings::getNightOffTime() {
return mySettings.nightOffTime;
}
void Settings::setNightOffTime(time_t nightOffTime) {
mySettings.nightOffTime = nightOffTime;
}
time_t Settings::getNightOnTime() {
return mySettings.nightOnTime;
}
void Settings::setNightOnTime(time_t nightOnTime) {
mySettings.nightOnTime = nightOnTime;
}
// Setzt alle Werte auf Defaulteinstellungen
void Settings::resetToDefault() {
mySettings.magicNumber = SETTINGS_MAGIC_NUMBER;
mySettings.version = SETTINGS_VERSION;
mySettings.language = 0;
mySettings.useLdr = false;
mySettings.brightness = 128;
mySettings.color = 0;
mySettings.timeout = 5;
mySettings.esIst = true;
mySettings.alarm1 = false;
mySettings.alarmTime1 = 0;
mySettings.alarm2 = false;
mySettings.alarmTime2 = 0;
mySettings.nightOffTime = 0;
mySettings.nightOnTime = 0;
saveToEEPROM();
}
// Einstellungen laden
void Settings::loadFromEEPROM() {
EEPROM.begin(512);
EEPROM.get(0, mySettings);
if ((mySettings.magicNumber != SETTINGS_MAGIC_NUMBER) || (mySettings.version != SETTINGS_VERSION)) resetToDefault();
}
// Einstellungen speichern
void Settings::saveToEEPROM() {
EEPROM.begin(512);
EEPROM.put(0, mySettings);
EEPROM.commit();
}