mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-07-28 09:53:45 +02:00
Tidy up recent changes to Turnout class.
This commit is contained in:
@@ -58,6 +58,8 @@ const int16_t HASH_KEYWORD_SPEED28 = -17064;
|
||||
const int16_t HASH_KEYWORD_SPEED128 = 25816;
|
||||
const int16_t HASH_KEYWORD_SERVO=27709;
|
||||
const int16_t HASH_KEYWORD_VPIN=-415;
|
||||
const int16_t HASH_KEYWORD_C=67;
|
||||
const int16_t HASH_KEYWORD_T=84;
|
||||
|
||||
int16_t DCCEXParser::stashP[MAX_COMMAND_PARAMS];
|
||||
bool DCCEXParser::stashBusy;
|
||||
@@ -674,63 +676,62 @@ bool DCCEXParser::parseT(Print *stream, int16_t params, int16_t p[])
|
||||
return true;
|
||||
|
||||
case 2: // <T id 0|1|T|C>
|
||||
switch (p[1]) {
|
||||
#ifdef TURNOUT_LEGACY_BEHAVIOUR
|
||||
// turnout 1 or T=THROW, 0 or C=CLOSE
|
||||
case 1: case 0x54: // 1 or T
|
||||
if (!Turnout::setClosed(p[0], false)) return false;
|
||||
p[1] = 1;
|
||||
break;
|
||||
case 0: case 0x43: // 0 or C
|
||||
if (!Turnout::setClosed(p[0], true)) return false;
|
||||
p[1] = 0;
|
||||
break;
|
||||
#else
|
||||
// turnout 0 or T=THROW,1 or C=CLOSE
|
||||
case 0: case 0x54: // 0 or T
|
||||
if (!Turnout::setClosed(p[0], false)) return false;
|
||||
p[1] = 0;
|
||||
break;
|
||||
case 1: case 0x43: // 1 or C
|
||||
if (!Turnout::setClosed(p[0], true)) return false;
|
||||
p[1] = 1;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
// Send acknowledgement to caller if the command was not received over Serial (acknowledgement
|
||||
// messages on Serial are sent by the Turnout class).
|
||||
if (stream != &Serial) StringFormatter::send(stream, F("<H %d %d>\n"), p[0], p[1]);
|
||||
return true;
|
||||
{
|
||||
bool state = false;
|
||||
switch (p[1]) {
|
||||
// By default turnout command uses 0=throw, 1=close,
|
||||
// but legacy DCC++ behaviour is 1=throw, 0=close.
|
||||
case 0:
|
||||
state = Turnout::useLegacyTurnoutBehaviour;
|
||||
break;
|
||||
case 1:
|
||||
state = !Turnout::useLegacyTurnoutBehaviour;
|
||||
break;
|
||||
case HASH_KEYWORD_C:
|
||||
state = true;
|
||||
break;
|
||||
case HASH_KEYWORD_T:
|
||||
state= false;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (!Turnout::setClosed(p[0], state)) return false;
|
||||
|
||||
default: // Anything else is some kind of create function.
|
||||
if (p[1] == HASH_KEYWORD_SERVO) { // <T id SERVO n n n n>
|
||||
if (params == 6) {
|
||||
if (!ServoTurnout::create(p[0], (VPIN)p[2], (uint16_t)p[3], (uint16_t)p[4], (uint8_t)p[5]))
|
||||
return false;
|
||||
} else
|
||||
// Send acknowledgement to caller if the command was not received over Serial
|
||||
// (acknowledgement messages on Serial are sent by the Turnout class).
|
||||
if (stream != &Serial) Turnout::printState(p[0], stream);
|
||||
return true;
|
||||
}
|
||||
|
||||
default: // Anything else is some kind of turnout create function.
|
||||
if (params == 6 && p[1] == HASH_KEYWORD_SERVO) { // <T id SERVO n n n n>
|
||||
if (!ServoTurnout::create(p[0], (VPIN)p[2], (uint16_t)p[3], (uint16_t)p[4], (uint8_t)p[5]))
|
||||
return false;
|
||||
} else
|
||||
if (p[1] == HASH_KEYWORD_VPIN) { // <T id VPIN n>
|
||||
if (params==3) {
|
||||
if (!VpinTurnout::create(p[0], p[2])) return false;
|
||||
} else
|
||||
return false;
|
||||
} else
|
||||
if (p[1]==HASH_KEYWORD_DCC) {
|
||||
if (params==4 && p[2]>0 && p[2]<=512 && p[3]>=0 && p[3]<4) { // <T id DCC n n>
|
||||
if (params == 3 && p[1] == HASH_KEYWORD_VPIN) { // <T id VPIN n>
|
||||
if (!VpinTurnout::create(p[0], p[2])) return false;
|
||||
} else
|
||||
if (params >= 3 && p[1] == HASH_KEYWORD_DCC) {
|
||||
if (params==4 && p[2]>0 && p[2]<=512 && p[3]>=0 && p[3]<4) { // <T id DCC n m>
|
||||
if (!DCCTurnout::create(p[0], p[2], p[3])) return false;
|
||||
} else if (params==3 && p[2]>0 && p[2]<=512*4) { // <T id DCC nn>
|
||||
} else if (params==3 && p[2]>0 && p[2]<=512*4) { // <T id DCC nn>, 1<=nn<=2048
|
||||
if (!DCCTurnout::create(p[0], (p[2]-1)/4+1, (p[2]-1)%4)) return false;
|
||||
} else
|
||||
return false;
|
||||
} else if (params==3) { // <T id n n> for DCC or LCN
|
||||
if (!DCCTurnout::create(p[0], p[1], p[2])) return false;
|
||||
} else
|
||||
if (params==3) { // legacy <T id n n> for DCC accessory
|
||||
if (p[1]>0 && p[1]<=512 && p[2]>=0 && p[2]<4) {
|
||||
if (!DCCTurnout::create(p[0], p[1], p[2])) return false;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
else if (params==3) { // legacy <T id n n n> for Servo
|
||||
else
|
||||
if (params==4) { // legacy <T id n n n> for Servo
|
||||
if (!ServoTurnout::create(p[0], (VPIN)p[1], (uint16_t)p[2], (uint16_t)p[3], 1)) return false;
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
|
||||
StringFormatter::send(stream, F("<O>\n"));
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user