-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstate.cpp
More file actions
50 lines (41 loc) · 1.14 KB
/
state.cpp
File metadata and controls
50 lines (41 loc) · 1.14 KB
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
#include "regulator.h"
#include "state.h"
#include <EEPROM.h>
#define VERSION 1 // this must be written on first byte of memory to verify that memory can be read from
struct Data {
unsigned long dhwNotRunMs;
unsigned long chNotRunMs;
unsigned long accumulatorDhwTotalMs;
unsigned long accumulatorChTotalMs;
unsigned long boilerDhwTotalMs;
unsigned long boilerChTotalMs;
};
void STATE::store() {
byte versionCode = VERSION;
EEPROM.write(0, versionCode);
Data data = {
accumulator.dhwNotRunMs,
accumulator.chNotRunMs,
accumulator.dhwTotalMs,
accumulator.chTotalMs,
boiler.dhwTotalMs,
boiler.chTotalMs
};
EEPROM.put(1, data);
}
bool STATE::load() {
Data data;
byte versionCode;
versionCode = EEPROM.read(0); // version
if (versionCode == VERSION) {
EEPROM.get(1, data);
accumulator.dhwNotRunMs = data.dhwNotRunMs;
accumulator.chNotRunMs = data.chNotRunMs;
accumulator.dhwTotalMs = data.accumulatorDhwTotalMs;
accumulator.chTotalMs = data.accumulatorChTotalMs;
boiler.dhwTotalMs = data.boilerDhwTotalMs;
boiler.chTotalMs = data.boilerChTotalMs;
return true;
}
return false;
}