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

Various corrections to Turnout code.

This commit is contained in:
Neil McKechnie 2021-08-19 21:43:55 +01:00
parent fd36ca2b92
commit 7f6173825f
3 changed files with 14 additions and 11 deletions

View File

@ -710,7 +710,7 @@ bool DCCEXParser::parseT(Print *stream, int16_t params, int16_t p[])
} else } else
if (p[1] == HASH_KEYWORD_VPIN) { // <T id VPIN n> if (p[1] == HASH_KEYWORD_VPIN) { // <T id VPIN n>
if (params==3) { if (params==3) {
if (VpinTurnout::create(p[0], p[2])) return false; if (!VpinTurnout::create(p[0], p[2])) return false;
} else } else
return false; return false;
} else } else

View File

@ -105,7 +105,7 @@ const int16_t HASH_KEYWORD_VPIN=-415;
// Static activate function is invoked from close(), throw() etc. to perform the // Static activate function is invoked from close(), throw() etc. to perform the
// 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 polymorphic virtual function activate(bool) which is // type should be placed in the virtual function activate(bool) which is
// called from here. // called from here.
bool Turnout::activate(uint16_t id, bool closeFlag) { bool Turnout::activate(uint16_t id, bool closeFlag) {
#ifdef EESTOREDEBUG #ifdef EESTOREDEBUG
@ -124,8 +124,7 @@ const int16_t HASH_KEYWORD_VPIN=-415;
EEPROM.put(tt->_eepromAddress, tt->_turnoutData.closed); EEPROM.put(tt->_eepromAddress, tt->_turnoutData.closed);
#if defined(RMFT_ACTIVE) #if defined(RMFT_ACTIVE)
// TODO: Check that the inversion is correct here! RMFT2::turnoutEvent(id, closeFlag);
RMFT2::turnoutEvent(id, !closeFlag);
#endif #endif
return ok; return ok;
@ -149,10 +148,10 @@ const int16_t HASH_KEYWORD_VPIN=-415;
// Load one turnout from EEPROM // Load one turnout from EEPROM
Turnout *Turnout::loadTurnout () { Turnout *Turnout::loadTurnout () {
Turnout *tt; 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(); // 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));
@ -169,11 +168,14 @@ const int16_t HASH_KEYWORD_VPIN=-415;
// VPIN turnout // VPIN turnout
tt = VpinTurnout::load(&turnoutData); tt = VpinTurnout::load(&turnoutData);
break; break;
default:
// If we find anything else, then we don't know what it is or how long it is,
// 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. // Save EEPROM address in object. Note that LCN turnouts always have eepromAddress of zero.
tt->_eepromAddress = eepromAddress; tt->_eepromAddress = eepromAddress;
add(tt);
} }
#ifdef EESTOREDEBUG #ifdef EESTOREDEBUG

View File

@ -204,7 +204,7 @@ public:
static Turnout *create(uint16_t id, VPIN vpin, uint16_t thrownPosition, uint16_t closedPosition, uint8_t profile, bool closed = true) { static Turnout *create(uint16_t id, VPIN vpin, uint16_t thrownPosition, uint16_t closedPosition, uint8_t profile, bool closed = true) {
#ifndef IO_NO_HAL #ifndef IO_NO_HAL
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
if (tt->isType(TURNOUT_SERVO)) { if (tt->isType(TURNOUT_SERVO)) {
// Yes, so set parameters // Yes, so set parameters
@ -237,6 +237,7 @@ public:
#endif #endif
} }
// ServoTurnout-specific code for throwing or closing a servo turnout.
bool activate(bool close) override { bool activate(bool close) override {
#ifndef IO_NO_HAL #ifndef IO_NO_HAL
IODevice::writeAnalogue(_servoTurnoutData.vpin, IODevice::writeAnalogue(_servoTurnoutData.vpin,
@ -301,7 +302,7 @@ public:
// Create function // Create function
static Turnout *create(uint16_t id, uint16_t add, uint8_t subAdd) { static Turnout *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
if (tt->isType(TURNOUT_DCC)) { if (tt->isType(TURNOUT_DCC)) {
// Yes, so set parameters<T> // Yes, so set parameters<T>
@ -378,7 +379,7 @@ public:
// Create function // Create function
static Turnout *create(uint16_t id, VPIN vpin, bool closed=true) { static Turnout *create(uint16_t id, VPIN vpin, bool closed=true) {
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
if (tt->isType(TURNOUT_VPIN)) { if (tt->isType(TURNOUT_VPIN)) {
// Yes, so set parameters // Yes, so set parameters
@ -450,7 +451,7 @@ public:
// Create function // Create function
static Turnout *create(uint16_t id, bool closed=true) { static Turnout *create(uint16_t id, bool closed=true) {
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
if (tt->isType(TURNOUT_LCN)) { if (tt->isType(TURNOUT_LCN)) {
// Yes, so return this object // Yes, so return this object