mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-07-28 18:03:45 +02:00
Turnout EEPROM improvements.
Ensure state is saved and restored from EEPROM as expected. Make constructors for turnouts private. Otherwise, a statically created turnout may be initialising itself before the underlying HAL device has been created. By requiring the create() call be used, there is more control over the timing of the turnout object's creation.
This commit is contained in:
26
Turnouts.cpp
26
Turnouts.cpp
@@ -121,19 +121,21 @@
|
||||
if (!tt) return false;
|
||||
bool ok = tt->activate(closeFlag);
|
||||
|
||||
// Write new closed/thrown state to EEPROM if required. Note that eepromAddress
|
||||
// is always zero for LCN turnouts.
|
||||
if (EEStore::eeStore->data.nTurnouts > 0 && tt->_eepromAddress)
|
||||
EEPROM.put(tt->_eepromAddress, tt->_turnoutData.closed);
|
||||
if (ok) {
|
||||
// Write byte containing new closed/thrown state to EEPROM if required. Note that eepromAddress
|
||||
// is always zero for LCN turnouts.
|
||||
if (EEStore::eeStore->data.nTurnouts > 0 && tt->_eepromAddress > 0)
|
||||
EEPROM.put(tt->_eepromAddress, *((uint8_t *) &tt->_turnoutData));
|
||||
|
||||
#if defined(RMFT_ACTIVE)
|
||||
RMFT2::turnoutEvent(id, closeFlag);
|
||||
#endif
|
||||
#if defined(RMFT_ACTIVE)
|
||||
RMFT2::turnoutEvent(id, closeFlag);
|
||||
#endif
|
||||
|
||||
// Send message to JMRI etc. over Serial USB. This is done here
|
||||
// to ensure that the message is sent when the turnout operation
|
||||
// is not initiated by a Serial command.
|
||||
printState(id, &Serial);
|
||||
// Send message to JMRI etc. over Serial USB. This is done here
|
||||
// to ensure that the message is sent when the turnout operation
|
||||
// is not initiated by a Serial command.
|
||||
printState(id, &Serial);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -180,7 +182,7 @@
|
||||
// so we can't go any further through the EEPROM!
|
||||
return NULL;
|
||||
}
|
||||
if (!tt) {
|
||||
if (tt) {
|
||||
// Save EEPROM address in object. Note that LCN turnouts always have eepromAddress of zero.
|
||||
tt->_eepromAddress = eepromAddress;
|
||||
}
|
||||
|
Reference in New Issue
Block a user