mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06: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:
parent
69c4733f2b
commit
0d235b65d3
|
@ -139,7 +139,7 @@
|
||||||
// Write byte containing new closed/thrown state to EEPROM if required. Note that eepromAddress
|
// Write byte containing new closed/thrown state to EEPROM if required. Note that eepromAddress
|
||||||
// is always zero for LCN turnouts.
|
// is always zero for LCN turnouts.
|
||||||
if (EEStore::eeStore->data.nTurnouts > 0 && tt->_eepromAddress > 0)
|
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)
|
#if defined(RMFT_ACTIVE)
|
||||||
RMFT2::turnoutEvent(id, closeFlag);
|
RMFT2::turnoutEvent(id, closeFlag);
|
||||||
|
@ -174,7 +174,7 @@
|
||||||
Turnout *tt = 0;
|
Turnout *tt = 0;
|
||||||
// Read turnout type from EEPROM
|
// Read turnout type from EEPROM
|
||||||
struct TurnoutData turnoutData;
|
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);
|
EEPROM.get(EEStore::pointer(), turnoutData);
|
||||||
EEStore::advance(sizeof(turnoutData));
|
EEStore::advance(sizeof(turnoutData));
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@
|
||||||
}
|
}
|
||||||
if (tt) {
|
if (tt) {
|
||||||
// Save EEPROM address in object. Note that LCN turnouts always have eepromAddress of zero.
|
// 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
|
#ifdef EESTOREDEBUG
|
||||||
|
|
|
@ -53,9 +53,14 @@ protected:
|
||||||
// vice versa. If the turnout has been saved, then this byte is rewritten
|
// 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.
|
// when changed in RAM. The 'closed' flag must be located in the first byte.
|
||||||
struct TurnoutData {
|
struct TurnoutData {
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
bool closed : 1;
|
bool closed : 1;
|
||||||
bool _rfu: 2;
|
bool _rfu: 2;
|
||||||
uint8_t turnoutType : 5;
|
uint8_t turnoutType : 5;
|
||||||
|
};
|
||||||
|
uint8_t flags;
|
||||||
|
};
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
} _turnoutData; // 3 bytes
|
} _turnoutData; // 3 bytes
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user