1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

Turnout notification handling enhanced.

Ensure that the <H> message is sent on the serial USB (to JMRI) whenever the turnout is closed or thrown, even if the request didn't originate on the serial USB.
This commit is contained in:
Neil McKechnie 2021-08-20 00:07:50 +01:00
parent 7f6173825f
commit b4a3b503bc
3 changed files with 15 additions and 5 deletions

View File

@ -679,25 +679,29 @@ bool DCCEXParser::parseT(Print *stream, int16_t params, int16_t p[])
// turnout 1 or T=THROW, 0 or C=CLOSE // turnout 1 or T=THROW, 0 or C=CLOSE
case 1: case 0x54: // 1 or T case 1: case 0x54: // 1 or T
if (!Turnout::setClosed(p[0], false)) return false; if (!Turnout::setClosed(p[0], false)) return false;
p[1] = 1;
break; break;
case 0: case 0x43: // 0 or C case 0: case 0x43: // 0 or C
if (!Turnout::setClosed(p[0], true)) return false; if (!Turnout::setClosed(p[0], true)) return false;
p[1] = 0;
break; break;
#else #else
// turnout 0 or T=THROW,1 or C=CLOSE // turnout 0 or T=THROW,1 or C=CLOSE
case 0: case 0x54: // 0 or T case 0: case 0x54: // 0 or T
if (!Turnout::setClosed(p[0], false)) return false; if (!Turnout::setClosed(p[0], false)) return false;
p[1] = 0;
break; break;
case 1: case 0x43: // 1 or C case 1: case 0x43: // 1 or C
if (!Turnout::setClosed(p[0], true)) return false; if (!Turnout::setClosed(p[0], true)) return false;
p[1] = 1;
break; break;
#endif #endif
default: default:
return false; return false;
} }
// Send acknowledgement to caller, and to Serial. // Send acknowledgement to caller if the command was not received over Serial (acknowledgement
StringFormatter::send(stream, F("<H %d %d>\n"), p[0], p[1]); // messages on Serial are sent by the Turnout class).
if (stream != &Serial) StringFormatter::send(Serial, F("<H %d %d>\n"), p[0], p[1]); if (stream != &Serial) StringFormatter::send(stream, F("<H %d %d>\n"), p[0], p[1]);
return true; return true;
default: // Anything else is some kind of create function. default: // Anything else is some kind of create function.

View File

@ -125,7 +125,12 @@ const int16_t HASH_KEYWORD_VPIN=-415;
#if defined(RMFT_ACTIVE) #if defined(RMFT_ACTIVE)
RMFT2::turnoutEvent(id, closeFlag); RMFT2::turnoutEvent(id, closeFlag);
#endif #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.
StringFormatter::send(Serial, F("<H %d %d>\n"), id, closeFlag);
return ok; return ok;
} }

View File

@ -466,7 +466,8 @@ public:
} }
bool activate(bool close) override { bool activate(bool close) override {
LCN::send('T', _turnoutData.id, close); // Assume that the LCN command still uses 1 for throw and 0 for close...
LCN::send('T', _turnoutData.id, !close);
// The _turnoutData.closed flag should be updated by a message from the LCN master, later. // The _turnoutData.closed flag should be updated by a message from the LCN master, later.
return true; return true;
} }