-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings.cpp
48 lines (43 loc) · 1.06 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
#include <Arduino.h>
#include <EEPROM.h>
#include <Time.h>
#include "vivarium.h"
#include "settings.h"
void clearSettings() {
memset(&herp,0,sizeof(herp));
herp.ver=VER;
memcpy_P(herp.welcome,PSTR("Welcome"),7);
herp.viv_count=1;
memcpy_P(&herp.vivs[0].name,PSTR("VIV #1"),6);
herp.vivs[0].temp.target=28.9;
herp.vivs[0].temp.hi=(byte)((32.0f-herp.vivs[0].temp.target)*10);
herp.vivs[0].temp.lo=(byte)abs((26.5f-herp.vivs[0].temp.target)*10);
herp.vivs[0].relay_pin=3;
herp.flags|=(TEMP_F << TEMP_FLAG);
writeEeprom();
didReset=true;
}
void readEeprom() {
if(EEPROM.read(0)!='h' ||
EEPROM.read(1)!='e' ||
EEPROM.read(2)!='r' ||
EEPROM.read(3)!='p' || EEPROM.read(20)!=VER) {
clearSettings();
return;
}
// Header matched
byte *ptr=(byte*)&herp;
for(int i=0;i<sizeof(herp);i++) {
*ptr++=EEPROM.read(i+4);
}
}
void writeEeprom() {
EEPROM.write(0,'h');
EEPROM.write(1,'e');
EEPROM.write(2,'r');
EEPROM.write(3,'p');
byte *ptr=(byte*)&herp;
for(int i=0;i<sizeof(herp);i++) {
EEPROM.write(i+4,*ptr++);
}
}