1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-11 21:31:02 +01:00

Ensure Turnout changes are notified on LCN activity.

Also, some comment updates.
This commit is contained in:
Neil McKechnie 2021-08-27 15:45:22 +01:00
parent 93dfdcce53
commit 6ebf908802

View File

@ -36,18 +36,18 @@
* Protected static data * Protected static data
*/ */
Turnout *Turnout::_firstTurnout = 0; /* static */ Turnout *Turnout::_firstTurnout = 0;
/* /*
* Public static data * Public static data
*/ */
int Turnout::turnoutlistHash = 0; /* static */ int Turnout::turnoutlistHash = 0;
/* /*
* Protected static functions * Protected static functions
*/ */
Turnout *Turnout::get(uint16_t id) { /* static */ Turnout *Turnout::get(uint16_t id) {
// Find turnout object from list. // Find turnout object from list.
for (Turnout *tt = _firstTurnout; tt != NULL; tt = tt->_nextTurnout) for (Turnout *tt = _firstTurnout; tt != NULL; tt = tt->_nextTurnout)
if (tt->_turnoutData.id == id) return tt; if (tt->_turnoutData.id == id) return tt;
@ -55,7 +55,7 @@
} }
// Add new turnout to end of chain // Add new turnout to end of chain
void Turnout::add(Turnout *tt) { /* static */ void Turnout::add(Turnout *tt) {
if (!_firstTurnout) if (!_firstTurnout)
_firstTurnout = tt; _firstTurnout = tt;
else { else {
@ -75,7 +75,7 @@
} }
// Remove nominated turnout from turnout linked list and delete the object. // Remove nominated turnout from turnout linked list and delete the object.
bool Turnout::remove(uint16_t id) { /* static */ bool Turnout::remove(uint16_t id) {
Turnout *tt,*pp=NULL; Turnout *tt,*pp=NULL;
for(tt=_firstTurnout; tt!=NULL && tt->_turnoutData.id!=id; pp=tt, tt=tt->_nextTurnout) {} for(tt=_firstTurnout; tt!=NULL && tt->_turnoutData.id!=id; pp=tt, tt=tt->_nextTurnout) {}
@ -97,7 +97,7 @@
* Public static functions * Public static functions
*/ */
bool Turnout::isClosed(uint16_t id) { /* static */ bool Turnout::isClosed(uint16_t id) {
Turnout *tt = get(id); Turnout *tt = get(id);
if (tt) if (tt)
return tt->isClosed(); return tt->isClosed();
@ -105,10 +105,21 @@
return false; return false;
} }
bool Turnout::setClosedStateOnly(uint16_t id, bool close) { /* static */ bool Turnout::setClosedStateOnly(uint16_t id, bool closeFlag) {
Turnout *tt = get(id); Turnout *tt = get(id);
if (!tt) return false; if (!tt) return false;
tt->_turnoutData.closed = close; tt->_turnoutData.closed = closeFlag;
// I know it says setClosedStateOnly, but we need to tell others
// that the state has changed too.
#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);
return true; return true;
} }
@ -117,7 +128,7 @@
// common parts of the turnout operation. Code which is specific to a turnout // common parts of the turnout operation. Code which is specific to a turnout
// type should be placed in the virtual function setClosedInternal(bool) which is // type should be placed in the virtual function setClosedInternal(bool) which is
// called from here. // called from here.
bool Turnout::setClosed(uint16_t id, bool closeFlag) { /* static */ bool Turnout::setClosed(uint16_t id, bool closeFlag) {
#ifdef EESTOREDEBUG #ifdef EESTOREDEBUG
if (closeFlag) if (closeFlag)
DIAG(F("Turnout::close(%d)"), id); DIAG(F("Turnout::close(%d)"), id);
@ -147,14 +158,14 @@
} }
// Load all turnout objects // Load all turnout objects
void Turnout::load() { /* static */ void Turnout::load() {
for (uint16_t i=0; i<EEStore::eeStore->data.nTurnouts; i++) { for (uint16_t i=0; i<EEStore::eeStore->data.nTurnouts; i++) {
Turnout::loadTurnout(); Turnout::loadTurnout();
} }
} }
// Save all turnout objects // Save all turnout objects
void Turnout::store() { /* static */ void Turnout::store() {
EEStore::eeStore->data.nTurnouts=0; EEStore::eeStore->data.nTurnouts=0;
for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout) { for (Turnout *tt = _firstTurnout; tt != 0; tt = tt->_nextTurnout) {
tt->save(); tt->save();
@ -163,7 +174,7 @@
} }
// Load one turnout from EEPROM // Load one turnout from EEPROM
Turnout *Turnout::loadTurnout () { /* static */ Turnout *Turnout::loadTurnout () {
Turnout *tt = 0; Turnout *tt = 0;
// Read turnout type from EEPROM // Read turnout type from EEPROM
struct TurnoutData turnoutData; struct TurnoutData turnoutData;
@ -201,7 +212,7 @@
} }
// Display, on the specified stream, the current state of the turnout (1=thrown or 0=closed). // Display, on the specified stream, the current state of the turnout (1=thrown or 0=closed).
void Turnout::printState(uint16_t id, Print *stream) { /* static */ void Turnout::printState(uint16_t id, Print *stream) {
Turnout *tt = get(id); Turnout *tt = get(id);
if (!tt) tt->printState(stream); if (!tt) tt->printState(stream);
} }
@ -223,7 +234,7 @@
} }
// Create function // Create function
Turnout *ServoTurnout::create(uint16_t id, VPIN vpin, uint16_t thrownPosition, uint16_t closedPosition, uint8_t profile, bool closed) { /* static */ Turnout *ServoTurnout::create(uint16_t id, VPIN vpin, uint16_t thrownPosition, uint16_t closedPosition, uint8_t profile, bool closed) {
#ifndef IO_NO_HAL #ifndef IO_NO_HAL
Turnout *tt = get(id); Turnout *tt = get(id);
if (tt) { if (tt) {
@ -330,7 +341,7 @@
} }
// Create function // Create function
Turnout *DCCTurnout::create(uint16_t id, uint16_t add, uint8_t subAdd) { /* static */ Turnout *DCCTurnout::create(uint16_t id, uint16_t add, uint8_t subAdd) {
Turnout *tt = get(id); Turnout *tt = get(id);
if (tt) { if (tt) {
// Object already exists, check if it is usable // Object already exists, check if it is usable
@ -350,7 +361,7 @@
} }
// Load a DCC turnout definition from EEPROM. The common Turnout data has already been read at this point. // Load a DCC turnout definition from EEPROM. The common Turnout data has already been read at this point.
Turnout *DCCTurnout::load(struct TurnoutData *turnoutData) { /* static */ Turnout *DCCTurnout::load(struct TurnoutData *turnoutData) {
DCCTurnoutData dccTurnoutData; DCCTurnoutData dccTurnoutData;
// Read class-specific data from EEPROM // Read class-specific data from EEPROM
EEPROM.get(EEStore::pointer(), dccTurnoutData); EEPROM.get(EEStore::pointer(), dccTurnoutData);
@ -407,7 +418,7 @@
} }
// Create function // Create function
Turnout *VpinTurnout::create(uint16_t id, VPIN vpin, bool closed) { /* static */ Turnout *VpinTurnout::create(uint16_t id, VPIN vpin, bool closed) {
Turnout *tt = get(id); Turnout *tt = get(id);
if (tt) { if (tt) {
// Object already exists, check if it is usable // Object already exists, check if it is usable
@ -427,7 +438,7 @@
} }
// Load a VPIN turnout definition from EEPROM. The common Turnout data has already been read at this point. // Load a VPIN turnout definition from EEPROM. The common Turnout data has already been read at this point.
Turnout *VpinTurnout::load(struct TurnoutData *turnoutData) { /* static */ Turnout *VpinTurnout::load(struct TurnoutData *turnoutData) {
VpinTurnoutData vpinTurnoutData; VpinTurnoutData vpinTurnoutData;
// Read class-specific data from EEPROM // Read class-specific data from EEPROM
EEPROM.get(EEStore::pointer(), vpinTurnoutData); EEPROM.get(EEStore::pointer(), vpinTurnoutData);
@ -477,7 +488,7 @@
{ } { }
// Create function // Create function
Turnout *LCNTurnout::create(uint16_t id, bool closed) { /* static */ Turnout *LCNTurnout::create(uint16_t id, bool closed) {
Turnout *tt = get(id); Turnout *tt = get(id);
if (tt) { if (tt) {
// Object already exists, check if it is usable // Object already exists, check if it is usable