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

Turnouts - make code clearer.

Overlay of flags bits added in struct TurnoutData,, called flags.  This simplifies the the EEPROM update code.
This commit is contained in:
Neil McKechnie 2021-08-23 17:36:50 +01:00
parent 69c4733f2b
commit 0d235b65d3
2 changed files with 11 additions and 6 deletions

View File

@ -139,7 +139,7 @@
// 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));
EEPROM.put(tt->_eepromAddress, tt->_turnoutData.flags);
#if defined(RMFT_ACTIVE)
RMFT2::turnoutEvent(id, closeFlag);
@ -174,7 +174,7 @@
Turnout *tt = 0;
// Read turnout type from EEPROM
struct TurnoutData turnoutData;
int eepromAddress = EEStore::pointer(); // Address of byte containing the closed flag.
int eepromAddress = EEStore::pointer() + offsetof(struct TurnoutData, flags); // Address of byte containing the closed flag.
EEPROM.get(EEStore::pointer(), turnoutData);
EEStore::advance(sizeof(turnoutData));
@ -198,7 +198,7 @@
}
if (tt) {
// Save EEPROM address in object. Note that LCN turnouts always have eepromAddress of zero.
tt->_eepromAddress = eepromAddress;
tt->_eepromAddress = eepromAddress + offsetof(struct TurnoutData, flags);
}
#ifdef EESTOREDEBUG

View File

@ -53,9 +53,14 @@ protected:
// vice versa. If the turnout has been saved, then this byte is rewritten
// when changed in RAM. The 'closed' flag must be located in the first byte.
struct TurnoutData {
bool closed : 1;
bool _rfu: 2;
uint8_t turnoutType : 5;
union {
struct {
bool closed : 1;
bool _rfu: 2;
uint8_t turnoutType : 5;
};
uint8_t flags;
};
uint16_t id;
} _turnoutData; // 3 bytes