-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEEPROMControl.cpp
More file actions
58 lines (41 loc) · 1.29 KB
/
EEPROMControl.cpp
File metadata and controls
58 lines (41 loc) · 1.29 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
51
52
53
54
55
56
57
58
//This file contains the routines for reading, witing and updating the #
// data stored inthe EEPROM
#include <EEPROM.h>
#include <Arduino.h>
struct EEPROMDATA {
int currenttrack; // 2 bytes
long numofwrites; // 4 bytes
};
EEPROMDATA TraverserData;
long LastTrackChangeTime = millis();
int UpdateInterval = 600000; // 1000 * 60 * 10 for 10 minutes
int eeAddress = 0; // this is the base address. Once the number of writes
// exceeds 50000 to 100000 increase this address
int ReadEEProm(){
EEPROM.get(eeAddress, TraverserData);
if (TraverserData.currenttrack > 0 || TraverserData.currenttrack < 10){
return TraverserData.currenttrack;
}
else {
return 0;
}
} // end ReadEEProm
void UpdateEEProm(int newtrack){
TraverserData.currenttrack = newtrack;
TraverserData.numofwrites = TraverserData.numofwrites + 1;
EEPROM.put(eeAddress, TraverserData);
}
bool CheckIfEEPROMSaveDue(int newtrack){
if ((millis() - LastTrackChangeTime) > UpdateInterval){
UpdateEEProm(newtrack);
return true;
}
else {
return false;
}
}
// This function should be called when a new track is selected
// to restart the timer.
void TrackSelectionHasChanged(int newtrack){
LastTrackChangeTime = millis()
}