-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSettings.cpp
54 lines (45 loc) · 1.17 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
#include <Arduino.h>
#include <EEPROM.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include "Settings.h"
SettingsClass Settings;
static const size_t EEPROM_SIZE = 512;
void SettingsClass::begin() {
#if defined(ESP8266)
EEPROM.begin(EEPROM_SIZE);
#else
EEPROM.begin();
#endif
EEPROM.get(0, *this);
// Populate defaults if flash magic is unexpected
if (magic != FLASH_MAGIC) {
if (magic != FLASH_MAGIC_R2) {
if (magic != FLASH_MAGIC_R1) {
bzero(this, sizeof(*this));
#if defined(ESP8266)
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
sprintf(hostname, "espclock%02x", mac[WL_MAC_ADDR_LENGTH-1]);
#else
strcpy(hostname, "espclock");
#endif
strcpy(ntp_hostname, "us.pool.ntp.org");
}
memset(preset_r, 0xff, sizeof(preset_r));
memset(preset_g, 0xff, sizeof(preset_g));
memset(preset_b, 0xff, sizeof(preset_b));
memset(preset_w, 0xff, sizeof(preset_w));
}
bzero(owm_apikey, sizeof(owm_apikey));
magic = FLASH_MAGIC;
save(); // Is this really necessary?
}
}
void SettingsClass::save() {
EEPROM.put(0, *this);
#if defined(ESP8266)
EEPROM.commit();
#endif
}