-
Notifications
You must be signed in to change notification settings - Fork 1
/
eeprom.h
59 lines (51 loc) · 1.81 KB
/
eeprom.h
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
/*
* _______ __ ______ __
* / ___ /________/ /_ __ / ____/___ __________/ /__ ____
* / /__/ / ___/ __ / / / /___/ / __/ __ `/ ___/ __ / _ _/ __ \
* / ___ / / / /_/ / /_/ /___/ /_/ / /_/ / / / /_/ / __/ / / /
* /_/ /_/_/ \__,_/\__,_/ \____/\__,_/_/ \__,_/\___/_/ /_/ C++
*
* By Pablo Luaces <pablo.luaces@gmail.com>
* Licensed under Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)
* Complete license text here: https://creativecommons.org/licenses/by-nc/4.0/
* [ Eeprom management file ]
*/
#include <EEPROM.h>
// Config data model
struct ArduGarden {
bool sistemaEncendido;
int sensorLluvia;
int temperaturaMinima;
int tiempoRiego[NUM_VALVES];
int horasRiego[MAX_DAY_TIMES];
int minutosRiego[MAX_DAY_TIMES];
bool diasRiego[WEEK_DAYS];
int estacion[YEAR_MONTHS];
int valvulas[NUM_VALVES];
};
// Data to store
ArduGarden arduGardenSettings = {
false,
0,
0,
{ 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ true, true, true, true, true, true, true },
{ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 },
{ 2, 3, 0, 0, 0, 0, 0, 0 }
};
void writeParams(unsigned int pointer){ // Dinamic data alocation extends EEPROM life
unsigned int dataSize = sizeof(arduGardenSettings);
EEPROM.write(0, 1); // Data saved flag
EEPROM.put(FIRST_EEPROM_POS, arduGardenSettings);
lcd.clear();
lcd.home();
lcd.print(STR_CONFIG_SAVED);
lcd.setCursor(0,1);
lcd.print(String(dataSize) + "Bytes, Pos " + String(FIRST_EEPROM_POS));
delay(1500);
}
void readParams(){
if (EEPROM.read(0) == 1) EEPROM.get(FIRST_EEPROM_POS, arduGardenSettings); // Store in data model
}