-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.cpp
169 lines (148 loc) · 3.39 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* Settings.cpp
* Die vom Benutzer getaetigten Einstellungen werden hier verwaltet
* und im EEPROM persistiert.
*
* @mc Arduino/RBBB
* @autor Christian Aschoff / caschoff _AT_ mac _DOT_ com
* @version 1.2
* @created 23.1.2013
* @updated 20.8.2013
*
* Versionshistorie:
* V 1.0: - Erstellt.
* V 1.1: - LDR-Modus aufgenommen.
* V 1.2: - Brightness aufgenommen.
* - EnableAlarm aufgenommen.
* - DcfSignalIsInverted aufgenommen.
* - TimeShift aufgenommen.
*/
#include "Settings.h"
#include <EEPROM.h>
#include "Renderer.h"
#define SETTINGS_MAGIC_NUMBER 0xCA
#define SETTINGS_VERSION 4
/**
* Konstruktor.
*/
Settings::Settings() {
_language = LANGUAGE_DE_DE;
_renderCornersCw = true;
_use_ldr = true;
_brightness = 75;
_enableAlarm = false;
_dcfSignalIsInverted = false;
_timeShift = 0;
// Versuche alte Einstellungen zu laden...
loadFromEEPROM();
}
/**
* Die Sprache. Werte siehe Renderer.h
*/
byte Settings::getLanguage() {
return _language;
}
void Settings::setLanguage(byte language) {
_language = language;
}
/**
* Die Laufrichtung der Eck-LEDs.
*/
boolean Settings::getRenderCornersCw() {
return _renderCornersCw;
}
void Settings::setRenderCornersCw(boolean cw) {
_renderCornersCw = cw;
}
/**
* Der LDR-Modus.
*/
boolean Settings::getUseLdr() {
return _use_ldr;
}
void Settings::setUseLdr(boolean useLdr) {
_use_ldr = useLdr;
}
/**
* Die Helligkeit.
*/
byte Settings::getBrightness() {
return _brightness;
}
void Settings::setBrightness(byte brightness) {
_brightness = brightness;
}
/**
* Wecker enablen?
*/
boolean Settings::getEnableAlarm() {
return _enableAlarm;
}
void Settings::setEnableAlarm(boolean enableAlarm) {
_enableAlarm = enableAlarm;
}
/**
* Ist das DCF-Signal invertiert?
*/
boolean Settings::getDcfSignalIsInverted() {
return _dcfSignalIsInverted;
}
void Settings::setDcfSignalIsInverted(boolean dcfSignalIsInverted) {
_dcfSignalIsInverted = dcfSignalIsInverted;
}
/**
* Zeitverschiebung
*/
char Settings::getTimeShift() {
return _timeShift;
}
void Settings::setTimeShift(char timeShift) {
_timeShift = timeShift;
}
/**
* Die Einstellungen laden.
*/
void Settings::loadFromEEPROM() {
if((EEPROM.read(0) == SETTINGS_MAGIC_NUMBER) && (EEPROM.read(1) == SETTINGS_VERSION)) {
// es sind gueltige Einstellungen vorhanden...
_language = EEPROM.read(2);
_renderCornersCw = EEPROM.read(3);
_use_ldr = EEPROM.read(4);
_brightness = EEPROM.read(5);
_enableAlarm = EEPROM.read(6);
_dcfSignalIsInverted = EEPROM.read(7);
_timeShift = EEPROM.read(8);
}
}
/**
* Die Einstellungen speichern.
*/
void Settings::saveToEEPROM() {
if(EEPROM.read(0) != SETTINGS_MAGIC_NUMBER) {
EEPROM.write(0, SETTINGS_MAGIC_NUMBER);
}
if(EEPROM.read(1) != SETTINGS_VERSION) {
EEPROM.write(1, SETTINGS_VERSION);
}
if(EEPROM.read(2) != _language) {
EEPROM.write(2, _language);
}
if(EEPROM.read(3) != _renderCornersCw) {
EEPROM.write(3, _renderCornersCw);
}
if(EEPROM.read(4) != _use_ldr) {
EEPROM.write(4, _use_ldr);
}
if(EEPROM.read(5) != _brightness) {
EEPROM.write(5, _brightness);
}
if(EEPROM.read(6) != _enableAlarm) {
EEPROM.write(6, _enableAlarm);
}
if(EEPROM.read(7) != _dcfSignalIsInverted) {
EEPROM.write(7, _dcfSignalIsInverted);
}
if(EEPROM.read(8) != _timeShift) {
EEPROM.write(8, _timeShift);
}
}