DCCpp
This is the library version of a program for Arduino to control railroading DCC devices.
EEStore.cpp
1
/**********************************************************************
2
3
EEStore.cpp
4
COPYRIGHT (c) 2013-2016 Gregg E. Berman
5
6
Part of DCC++ BASE STATION for the Arduino
7
8
**********************************************************************/
9
10
#include "EEStore.h"
11
12
#ifdef USE_EEPROM
13
#ifdef VISUALSTUDIO
14
#include "string.h"
15
#endif
16
#include "DCCpp_Uno.h"
17
#include "Turnout.h"
18
#include "Sensor.h"
19
#include "Outputs.h"
20
#include "EEPROM.h"
21
23
24
void
EEStore::init
(){
25
26
27
//eeStore=(EEStore *)calloc(1,sizeof(EEStore));
28
29
//EEPROM.get(0,eeStore->data); // get eeStore data
30
#ifdef VISUALSTUDIO
31
EEPROM.get(0, (
void
*)&
data
,
sizeof
(
EEStoreData
));
32
#else
33
EEPROM.get(0, data);
34
#endif
35
36
if
(strncmp(data.id,EESTORE_ID,
sizeof
(EESTORE_ID))!=0){
// check to see that eeStore contains valid DCC++ ID
37
sprintf(data.id,EESTORE_ID);
// if not, create blank eeStore structure (no turnouts, no sensors) and save it back to EEPROM
38
#ifdef USE_TURNOUT
39
data.nTurnouts=0;
40
#endif
41
#ifdef USE_SENSOR
42
data.nSensors=0;
43
#endif
44
#ifdef USE_OUTPUT
45
data.nOutputs=0;
46
#endif
47
#ifdef VISUALSTUDIO
48
EEPROM.put(0, (
void
*)&data,
sizeof
(
EEStoreData
));
49
#else
50
EEPROM.put(0, data);
51
#endif
52
}
53
54
reset
();
// set memory pointer to first free EEPROM space
55
#ifdef USE_TURNOUT
56
Turnout::load
();
// load turnout definitions
57
#endif
58
#ifdef USE_SENSOR
59
Sensor::load
();
// load sensor definitions
60
#endif
61
#ifdef USE_OUTPUT
62
Output::load
();
// load output definitions
63
#endif
64
}
65
67
68
void
EEStore::clear
(){
69
70
sprintf(
data
.
id
,EESTORE_ID);
// create blank eeStore structure (no turnouts, no sensors) and save it back to EEPROM
71
#ifdef USE_TURNOUT
72
data
.
nTurnouts
=0;
73
#endif
74
#ifdef USE_SENSOR
75
data
.
nSensors
=0;
76
#endif
77
#ifdef USE_OUTPUT
78
data
.
nOutputs
=0;
79
#endif
80
#ifdef VISUALSTUDIO
81
EEPROM.put(0, (
void
*)&
data
,
sizeof
(
EEStoreData
));
82
#else
83
EEPROM.put(0, data);
84
#endif
85
86
}
87
89
90
void
EEStore::store
() {
91
reset
();
92
#ifdef USE_TURNOUT
93
Turnout::store
();
94
#endif
95
#ifdef USE_SENSOR
96
Sensor::store
();
97
#endif
98
#ifdef USE_OUTPUT
99
Output::store
();
100
#endif
101
#ifdef VISUALSTUDIO
102
EEPROM.put(0, (
void
*)&
data
,
sizeof
(
EEStoreData
));
103
#else
104
EEPROM.put(0, data);
105
#endif
106
}
107
109
110
bool
EEStore::needsRefreshing
() {
111
#ifdef USE_TURNOUT
112
if
(
data
.
nTurnouts
!=
Turnout::count
())
113
return
true
;
114
#endif
115
#ifdef USE_SENSOR
116
if
(
data
.
nSensors
!=
Sensor::count
())
117
return
true
;
118
#endif
119
#ifdef USE_OUTPUT
120
if
(
data
.
nOutputs
!=
Output::count
())
121
return
true
;
122
#endif
123
return
false
;
124
}
125
127
128
void
EEStore::advance
(
int
n){
129
eeAddress
+=n;
130
}
131
133
134
void
EEStore::reset
(){
135
eeAddress
=
sizeof
(
EEStore
);
136
}
138
139
int
EEStore::pointer
(){
140
return
(
eeAddress
);
141
}
143
144
//EEStore *EEStore::eeStore=NULL;
145
EEStoreData
EEStore::data
;
146
147
int
EEStore::eeAddress
=0;
148
149
#endif
EEStore::pointer
static int pointer()
Definition:
EEStore.cpp:139
EEStore::eeAddress
static int eeAddress
Definition:
EEStore.h:46
EEStore::advance
static void advance(int inIncrement)
Definition:
EEStore.cpp:128
Sensor::count
static int count()
Definition:
Sensor.cpp:110
Turnout::count
static int count()
Definition:
Turnout.cpp:140
Output::count
static int count()
Definition:
Outputs.cpp:141
EEStore::needsRefreshing
static bool needsRefreshing()
Definition:
EEStore.cpp:110
Output::store
static void store()
Definition:
Outputs.cpp:190
Sensor::store
static void store()
Definition:
Sensor.cpp:227
EEStore
Definition:
EEStore.h:43
EEStore::store
static void store()
Definition:
EEStore.cpp:90
EEStoreData::nOutputs
int nOutputs
Definition:
EEStore.h:29
EEStoreData::nSensors
int nSensors
Definition:
EEStore.h:26
EEStoreData::nTurnouts
int nTurnouts
Definition:
EEStore.h:23
EEStoreData::id
char id[sizeof (EESTORE_ID)+1]
Definition:
EEStore.h:21
EEStore::clear
static void clear()
Definition:
EEStore.cpp:68
Output::load
static void load()
Definition:
Outputs.cpp:152
Turnout::store
static void store()
Definition:
Turnout.cpp:180
Sensor::load
static void load()
Definition:
Sensor.cpp:200
Turnout::load
static void load()
Definition:
Turnout.cpp:151
EEStore::reset
static void reset()
Definition:
EEStore.cpp:134
EEStoreData
Definition:
EEStore.h:20
EEStore::data
static EEStoreData data
Definition:
EEStore.h:45
EEStore::init
static void init()
Definition:
EEStore.cpp:24
src
EEStore.cpp
Generated on lun. déc. 11 2017 18:07:04 for DCCpp by
1.2.10