1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

On <E> commmand, output EEPROM size and amount used.

Also, formatting and indentation fixed.
This commit is contained in:
Neil McKechnie 2021-08-27 12:56:27 +01:00
parent 0aea9169b1
commit 1dd574dc03

View File

@ -19,89 +19,87 @@
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>. * along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include "EEStore.h" #include "EEStore.h"
#include "Turnouts.h"
#include "Sensors.h"
#include "Outputs.h"
#include "DIAG.h" #include "DIAG.h"
#include "Outputs.h"
#include "Sensors.h"
#include "Turnouts.h"
#if defined(ARDUINO_ARCH_SAMD) #if defined(ARDUINO_ARCH_SAMD)
ExternalEEPROM EEPROM; ExternalEEPROM EEPROM;
#endif #endif
void EEStore::init(){ void EEStore::init() {
#if defined(ARDUINO_ARCH_SAMD) #if defined(ARDUINO_ARCH_SAMD)
EEPROM.begin(0x50); // Address for Microchip 24-series EEPROM with all three A pins grounded (0b1010000 = 0x50) EEPROM.begin(0x50); // Address for Microchip 24-series EEPROM with all three
// A pins grounded (0b1010000 = 0x50)
#endif #endif
eeStore=(EEStore *)calloc(1,sizeof(EEStore)); eeStore = (EEStore *)calloc(1, sizeof(EEStore));
EEPROM.get(0,eeStore->data); // get eeStore data
if(strncmp(eeStore->data.id,EESTORE_ID,sizeof(EESTORE_ID))!=0){ // check to see that eeStore contains valid DCC++ ID EEPROM.get(0, eeStore->data); // get eeStore data
sprintf(eeStore->data.id,EESTORE_ID); // if not, create blank eeStore structure (no turnouts, no sensors) and save it back to EEPROM
eeStore->data.nTurnouts=0;
eeStore->data.nSensors=0;
eeStore->data.nOutputs=0;
EEPROM.put(0,eeStore->data);
}
reset(); // set memory pointer to first free EEPROM space // check to see that eeStore contains valid DCC++ ID
Turnout::load(); // load turnout definitions if (strncmp(eeStore->data.id, EESTORE_ID, sizeof(EESTORE_ID)) != 0) {
Sensor::load(); // load sensor definitions // if not, create blank eeStore structure (no
Output::load(); // load output definitions // turnouts, no sensors) and save it back to EEPROM
strncpy(eeStore->data.id, EESTORE_ID, sizeof(EESTORE_ID));
eeStore->data.nTurnouts = 0;
eeStore->data.nSensors = 0;
eeStore->data.nOutputs = 0;
EEPROM.put(0, eeStore->data);
}
reset(); // set memory pointer to first free EEPROM space
Turnout::load(); // load turnout definitions
Sensor::load(); // load sensor definitions
Output::load(); // load output definitions
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void EEStore::clear(){ void EEStore::clear() {
sprintf(eeStore->data.id,
sprintf(eeStore->data.id,EESTORE_ID); // create blank eeStore structure (no turnouts, no sensors) and save it back to EEPROM EESTORE_ID); // create blank eeStore structure (no turnouts, no
eeStore->data.nTurnouts=0; // sensors) and save it back to EEPROM
eeStore->data.nSensors=0; eeStore->data.nTurnouts = 0;
eeStore->data.nOutputs=0; eeStore->data.nSensors = 0;
EEPROM.put(0,eeStore->data); eeStore->data.nOutputs = 0;
EEPROM.put(0, eeStore->data);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void EEStore::store(){ void EEStore::store() {
reset(); reset();
Turnout::store(); Turnout::store();
Sensor::store(); Sensor::store();
Output::store(); Output::store();
EEPROM.put(0,eeStore->data); EEPROM.put(0, eeStore->data);
DIAG(F("EEPROM used: %d bytes"), EEStore::pointer()); DIAG(F("EEPROM used: %d/%d bytes"), EEStore::pointer(), EEPROM.length());
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void EEStore::advance(int n){ void EEStore::advance(int n) { eeAddress += n; }
eeAddress+=n;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void EEStore::reset(){ void EEStore::reset() { eeAddress = sizeof(EEStore); }
eeAddress=sizeof(EEStore);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
int EEStore::pointer(){ int EEStore::pointer() { return (eeAddress); }
return(eeAddress);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void EEStore::dump(int num) { void EEStore::dump(int num) {
byte b; byte b;
DIAG(F("Addr 0x char")); DIAG(F("Addr 0x char"));
for (int n=0 ; n<num; n++) { for (int n = 0; n < num; n++) {
EEPROM.get(n, b); EEPROM.get(n, b);
DIAG(F("%d %x %c"),n,b,isprint(b) ? b : ' '); DIAG(F("%d %x %c"), n, b, isprint(b) ? b : ' ');
} }
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
EEStore *EEStore::eeStore=NULL; EEStore *EEStore::eeStore = NULL;
int EEStore::eeAddress=0; int EEStore::eeAddress = 0;