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 
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 
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 
91  reset();
92 #ifdef USE_TURNOUT
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 
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 
135  eeAddress=sizeof(EEStore);
136 }
138 
140  return(eeAddress);
141 }
143 
144 //EEStore *EEStore::eeStore=NULL;
146 
147 int EEStore::eeAddress=0;
148 
149 #endif
static int pointer()
Definition: EEStore.cpp:139
static int eeAddress
Definition: EEStore.h:46
static void advance(int inIncrement)
Definition: EEStore.cpp:128
static int count()
Definition: Outputs.cpp:141
static int count()
Definition: Sensor.cpp:110
static int count()
Definition: Turnout.cpp:140
static bool needsRefreshing()
Definition: EEStore.cpp:110
static void store()
Definition: Sensor.cpp:227
static void store()
Definition: Turnout.cpp:180
static void store()
Definition: EEStore.cpp:90
int nOutputs
Definition: EEStore.h:29
int nSensors
Definition: EEStore.h:26
int nTurnouts
Definition: EEStore.h:23
char id[sizeof (EESTORE_ID)+1]
Definition: EEStore.h:21
static void clear()
Definition: EEStore.cpp:68
static void load()
Definition: Outputs.cpp:152
static void load()
Definition: Sensor.cpp:200
static void load()
Definition: Turnout.cpp:151
static void reset()
Definition: EEStore.cpp:134
static void store()
Definition: Outputs.cpp:190
static EEStoreData data
Definition: EEStore.h:45
static void init()
Definition: EEStore.cpp:24