-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.cpp
71 lines (54 loc) · 1.47 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
#include "Settings.h"
Settings::Settings() {
if (!(load())) {
save();
}
analogWrite(BACKLIGHT_PIN, _settings.backlight);
analogWrite(CONTRAST_PIN, _settings.contrast);
}
bool Settings::load() {
for (unsigned int i = 0; i < sizeof(_settings.ver); i++) if ( !(EEPROM.read(CONFIG_START + i) == CONFIG_VERSION[i]) ) return false;
for (unsigned int j = 0; j < sizeof(_settings); j++) *((char*)&_settings + j) = EEPROM.read(CONFIG_START + j);
return true;
}
void Settings::save() {
for (unsigned int i = 0; i < sizeof(_settings); i++) EEPROM.write(CONFIG_START + i, *((char*)&_settings + i));
}
float Settings::vStep() {
return _settings.vStep;
}
float Settings::vMax() {
return _settings.vMax;
}
float Settings::minPow() {
return _settings.minPow;
}
int Settings::attenuator() {
return _settings.attenuator;
}
byte Settings::backlight() {
return _settings.backlight;
}
byte Settings::contrast() {
return _settings.contrast;
}
void Settings::setVStep(float vStep) {
_settings.vStep = vStep;
}
void Settings::setVMax(float vMax) {
_settings.vMax = vMax;
}
void Settings::setMinPow(float minPow) {
_settings.minPow = minPow;
}
void Settings::setAttenuator(int attenuator) {
_settings.attenuator = attenuator;
}
void Settings::setBacklight(byte brightness) {
analogWrite(BACKLIGHT_PIN, brightness);
_settings.backlight = brightness;
}
void Settings::setContrast(byte contrast) {
analogWrite(CONTRAST_PIN, contrast);
_settings.contrast = contrast;
}