1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 21:01:25 +01:00

Emergency stop in JMRI and WiThrottle

JMRI -1 means speed=1 in DCC
This commit is contained in:
Asbelos 2020-07-23 15:41:43 +01:00
parent 7eae489b9e
commit a915331103
3 changed files with 14 additions and 6 deletions

View File

@ -47,7 +47,7 @@ void DCC::begin() {
}
void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
byte speedCode = tSpeed + (tSpeed > 0) + tDirection * 128; // max speed is 126, but speed codes range from 2-127 (0=stop, 1=emergency stop)
byte speedCode = (tSpeed & 0x7F) + tDirection * 128; //speed codes range from 2-127 (0=stop, 1=emergency stop)
setThrottle2(cab, speedCode);
// retain speed for loco reminders
updateLocoReminder(cab, speedCode );

View File

@ -141,10 +141,18 @@ void DCCEXParser::parse(Print & stream, const byte *com, bool blocking) {
switch(opcode) {
case '\0': return; // filterCallback asked us to ignore
case 't': // THROTTLE <t REGISTER CAB SPEED DIRECTION>
DCC::setThrottle(p[1],p[2],p[3]);
StringFormatter::send(stream,F("<T %d %d %d>"), p[0], p[2],p[3]);
{
// Convert JMRI bizarre -1=emergency stop, 0-126 as speeds
// to DCC 0=stop, 1= emergency stop, 2-127 speeds
int tspeed=p[2];
if (tspeed>126 | tspeed<-1) break; // invalid JMRI speed code
if (tspeed<0) tspeed=1; // emergency stop DCC speed
else if (tspeed>0) tspeed++; // map 1-126 -> 2-127
DCC::setThrottle(p[1],tspeed,p[3]);
// report speed 0 after emergency stop
StringFormatter::send(stream,F("<T %d %d %d>"), p[0], p[2]<0?0:p[2],p[3]);
return;
}
case 'f': // FUNCTION <f CAB BYTE1 [BYTE2]>
if (parsef(stream,params,p)) return;
break;

View File

@ -117,7 +117,7 @@ void WiThrottle::parse(Print & stream, byte * cmdx) {
case 'P':
if (cmd[1]=='P' && cmd[2]=='A' ) { //PPA power mode
DCCWaveform::mainTrack.setPowerMode(cmd[3]=='1'?POWERMODE::ON:POWERMODE::OFF);
StringFormatter::send(stream, F("PPA%c"),cmd[3]);
StringFormatter::send(stream, F("PPA%c\n"),cmd[3]);
}
else if (cmd[1]=='T' && cmd[2]=='A') { // PTA accessory toggle
// TODO... if we are given an address that is not a known Turnout...
@ -236,7 +236,7 @@ void WiThrottle::locoAction(Print & stream, byte* aval, char throttleChar, int c
}
break;
case 'X':
//Emergency Stop (TODO check we have the correct speed code here)
//Emergency Stop (speed code 1)
LOOPLOCOS(throttleChar, cab) {
DCC::setThrottle(myLocos[loco].cab,1, DCC::getThrottleDirection(myLocos[loco].cab));
}