1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-01-11 13:21:01 +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
if (p[1] == HASH_KEYWORD_VPIN) { // <T id VPIN n>
if (params==3) {
if (VpinTurnout::create(p[0], p[2])) return false;
if (!VpinTurnout::create(p[0], p[2])) return false;
} else
return false;
} 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
// 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.
bool Turnout::activate(uint16_t id, bool closeFlag) {
#ifdef EESTOREDEBUG
@ -124,8 +124,7 @@ const int16_t HASH_KEYWORD_VPIN=-415;
EEPROM.put(tt->_eepromAddress, tt->_turnoutData.closed);
#if defined(RMFT_ACTIVE)
// TODO: Check that the inversion is correct here!
RMFT2::turnoutEvent(id, !closeFlag);
RMFT2::turnoutEvent(id, closeFlag);
#endif
return ok;
@ -149,10 +148,10 @@ const int16_t HASH_KEYWORD_VPIN=-415;
// Load one turnout from EEPROM
Turnout *Turnout::loadTurnout () {
Turnout *tt;
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(); // Address of byte containing the closed flag.
EEPROM.get(EEStore::pointer(), turnoutData);
EEStore::advance(sizeof(turnoutData));
@ -169,11 +168,14 @@ const int16_t HASH_KEYWORD_VPIN=-415;
// VPIN turnout
tt = VpinTurnout::load(&turnoutData);
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) {
// Save EEPROM address in object. Note that LCN turnouts always have eepromAddress of zero.
tt->_eepromAddress = eepromAddress;
add(tt);
}
#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) {
#ifndef IO_NO_HAL
Turnout *tt = get(id);
if (!tt) {
if (tt) {
// Object already exists, check if it is usable
if (tt->isType(TURNOUT_SERVO)) {
// Yes, so set parameters
@ -237,6 +237,7 @@ public:
#endif
}
// ServoTurnout-specific code for throwing or closing a servo turnout.
bool activate(bool close) override {
#ifndef IO_NO_HAL
IODevice::writeAnalogue(_servoTurnoutData.vpin,
@ -301,7 +302,7 @@ public:
// Create function
static Turnout *create(uint16_t id, uint16_t add, uint8_t subAdd) {
Turnout *tt = get(id);
if (!tt) {
if (tt) {
// Object already exists, check if it is usable
if (tt->isType(TURNOUT_DCC)) {
// Yes, so set parameters<T>
@ -378,7 +379,7 @@ public:
// Create function
static Turnout *create(uint16_t id, VPIN vpin, bool closed=true) {
Turnout *tt = get(id);
if (!tt) {
if (tt) {
// Object already exists, check if it is usable
if (tt->isType(TURNOUT_VPIN)) {
// Yes, so set parameters
@ -450,7 +451,7 @@ public:
// Create function
static Turnout *create(uint16_t id, bool closed=true) {
Turnout *tt = get(id);
if (!tt) {
if (tt) {
// Object already exists, check if it is usable
if (tt->isType(TURNOUT_LCN)) {
// Yes, so return this object