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 "Arduino.h"
11 
12 #include "EEStore.h"
13 
14 #ifdef USE_EEPROM
15 #ifdef VISUALSTUDIO
16 #include "string.h"
17 #endif
18 #include "DCCpp_Uno.h"
19 #include "Turnout.h"
20 #include "Sensor.h"
21 #include "Outputs.h"
22 #include "EEPROM.h"
23 
25 
27 
28 
29  //eeStore=(EEStore *)calloc(1,sizeof(EEStore));
30 
31  //EEPROM.get(0,eeStore->data); // get eeStore data
32 #ifdef VISUALSTUDIO
33  EEPROM.get(0, (void *)&data, sizeof(EEStoreData));
34 #else
35  EEPROM.get(0, data);
36 #endif
37 
38  if(strncmp(data.id,EESTORE_ID,sizeof(EESTORE_ID))!=0){ // check to see that eeStore contains valid DCC++ ID
39  sprintf(data.id,EESTORE_ID); // if not, create blank eeStore structure (no turnouts, no sensors) and save it back to EEPROM
40 #ifdef USE_TURNOUT
41  data.nTurnouts=0;
42 #endif
43 #ifdef USE_SENSOR
44  data.nSensors=0;
45 #endif
46 #ifdef USE_OUTPUT
47  data.nOutputs=0;
48 #endif
49 #ifdef VISUALSTUDIO
50  EEPROM.put(0, (void *)&data, sizeof(EEStoreData));
51 #else
52  EEPROM.put(0, data);
53 #endif
54  }
55 
56  reset(); // set memory pointer to first free EEPROM space
57 #ifdef USE_TURNOUT
58  Turnout::load(); // load turnout definitions
59 #endif
60 #ifdef USE_SENSOR
61  Sensor::load(); // load sensor definitions
62 #endif
63 #ifdef USE_OUTPUT
64  Output::load(); // load output definitions
65 #endif
66 }
67 
69 
71 
72  sprintf(data.id,EESTORE_ID); // create blank eeStore structure (no turnouts, no sensors) and save it back to EEPROM
73 #ifdef USE_TURNOUT
74  data.nTurnouts=0;
75 #endif
76 #ifdef USE_SENSOR
77  data.nSensors=0;
78 #endif
79 #ifdef USE_OUTPUT
80  data.nOutputs=0;
81 #endif
82 #ifdef VISUALSTUDIO
83  EEPROM.put(0, (void *)&data, sizeof(EEStoreData));
84 #else
85  EEPROM.put(0, data);
86 #endif
87 
88 }
89 
91 
93  reset();
94 #ifdef USE_TURNOUT
96 #endif
97 #ifdef USE_SENSOR
98  Sensor::store();
99 #endif
100 #ifdef USE_OUTPUT
101  Output::store();
102 #endif
103 #ifdef VISUALSTUDIO
104  EEPROM.put(0, (void *)&data, sizeof(EEStoreData));
105 #else
106  EEPROM.put(0, data);
107 #endif
108 }
109 
111 
113 #ifdef USE_TURNOUT
114  if (data.nTurnouts != Turnout::count())
115  return true;
116 #endif
117 #ifdef USE_SENSOR
118  if (data.nSensors != Sensor::count())
119  return true;
120 #endif
121 #ifdef USE_OUTPUT
122  if (data.nOutputs!= Output::count())
123  return true;
124 #endif
125  return false;
126 }
127 
129 
130 void EEStore::advance(int n){
131  eeAddress+=n;
132 }
133 
135 
137  eeAddress=sizeof(EEStoreData);
138 }
140 
142  return(eeAddress);
143 }
145 
146 //EEStore *EEStore::eeStore=NULL;
148 
149 int EEStore::eeAddress=0;
150 
151 #endif
static int pointer()
Definition: EEStore.cpp:141
static void advance(int inIncrement)
Definition: EEStore.cpp:130
static int count()
Definition: Sensor.cpp:113
static int count()
Definition: Turnout.cpp:141
static int eeAddress
Definition: EEStore.h:46
static bool needsRefreshing()
Definition: EEStore.cpp:112
static void store()
Definition: Sensor.cpp:233
static void store()
Definition: Turnout.cpp:181
static void store()
Definition: EEStore.cpp:92
static void clear()
Definition: EEStore.cpp:70
static void load()
Definition: Sensor.cpp:206
static void load()
Definition: Turnout.cpp:152
static void reset()
Definition: EEStore.cpp:136
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 EEStoreData data
Definition: EEStore.h:45
static void init()
Definition: EEStore.cpp:26