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

Fix turnout handling of EEPROM (#147)

On activation, Turnout code was saving entire EEPROM twice, even if EEPROM save was switched off with the <e> command.  It's now been changed so that only the tStatus byte is updated, and only if the turnout has previously been saved into EEPROM.
This commit is contained in:
Neil McKechnie 2021-05-07 00:12:33 +01:00 committed by GitHub
parent 9b4c374cd4
commit 107e9d1d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -39,7 +39,6 @@ bool Turnout::activate(int n,bool state){
Turnout * tt=get(n); Turnout * tt=get(n);
if (tt==NULL) return false; if (tt==NULL) return false;
tt->activate(state); tt->activate(state);
EEStore::store();
turnoutlistHash++; turnoutlistHash++;
return true; return true;
} }
@ -68,7 +67,9 @@ void Turnout::activate(bool state) {
PWMServoDriver::setServo(data.tStatus & STATUS_PWMPIN, (data.inactiveAngle+(state?data.moveAngle:0))); PWMServoDriver::setServo(data.tStatus & STATUS_PWMPIN, (data.inactiveAngle+(state?data.moveAngle:0)));
else else
DCC::setAccessory(data.address,data.subAddress, state); DCC::setAccessory(data.address,data.subAddress, state);
EEStore::store(); // Save state if stored in EEPROM
if (EEStore::eeStore->data.nTurnouts > 0 && num > 0)
EEPROM.put(num, data.tStatus);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -107,6 +108,7 @@ void Turnout::load(){
if (data.tStatus & STATUS_PWM) tt=create(data.id,data.tStatus & STATUS_PWMPIN, data.inactiveAngle,data.moveAngle); if (data.tStatus & STATUS_PWM) tt=create(data.id,data.tStatus & STATUS_PWMPIN, data.inactiveAngle,data.moveAngle);
else tt=create(data.id,data.address,data.subAddress); else tt=create(data.id,data.address,data.subAddress);
tt->data.tStatus=data.tStatus; tt->data.tStatus=data.tStatus;
tt->num=EEStore::pointer()+offsetof(TurnoutData,tStatus); // Save pointer to status byte within EEPROM
EEStore::advance(sizeof(tt->data)); EEStore::advance(sizeof(tt->data));
#ifdef EESTOREDEBUG #ifdef EESTOREDEBUG
tt->print(tt); tt->print(tt);
@ -126,6 +128,7 @@ void Turnout::store(){
#ifdef EESTOREDEBUG #ifdef EESTOREDEBUG
tt->print(tt); tt->print(tt);
#endif #endif
tt->num=EEStore::pointer()+offsetof(TurnoutData,tStatus); // Save pointer to tstatus byte within EEPROM
EEPROM.put(EEStore::pointer(),tt->data); EEPROM.put(EEStore::pointer(),tt->data);
EEStore::advance(sizeof(tt->data)); EEStore::advance(sizeof(tt->data));
tt=tt->nextTurnout; tt=tt->nextTurnout;

View File

@ -54,6 +54,8 @@ class Turnout {
#ifdef EESTOREDEBUG #ifdef EESTOREDEBUG
void print(Turnout *tt); void print(Turnout *tt);
#endif #endif
private:
int num; // EEPROM address of tStatus in TurnoutData struct, or zero if not stored.
}; // Turnout }; // Turnout
#endif #endif