diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 60b2233..9fb2b29 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -43,7 +43,8 @@ const int HASH_KEYWORD_WIT=31594; const int HASH_KEYWORD_WIFI=-5583; const int HASH_KEYWORD_ACK=3113; const int HASH_KEYWORD_ON=2657; -const int HASH_KEYWORD_OFF=22479; +const int HASH_KEYWORD_DCC=6436; +const int HASH_KEYWORD_SLOW=-17209; int DCCEXParser::stashP[MAX_PARAMS]; @@ -455,7 +456,7 @@ bool DCCEXParser::parseS( Print * stream,int params, int p[]) { bool DCCEXParser::parseD( Print * stream,int params, int p[]) { if (params==0) return false; - bool onOff=p[1]==1 || p[1]==HASH_KEYWORD_ON; // dont care if other stuff or missing... just means off + bool onOff=(params>0) && (p[1]==1 || p[1]==HASH_KEYWORD_ON); // dont care if other stuff or missing... just means off switch(p[0]){ case HASH_KEYWORD_CABS: // DCC::displayCabList(stream); @@ -481,6 +482,9 @@ bool DCCEXParser::parseD( Print * stream,int params, int p[]) { Diag::WITHROTTLE=onOff; return true; + case HASH_KEYWORD_DCC: + DCCWaveform::setDiagnosticSlowWave(params>=1 && p[1]==HASH_KEYWORD_SLOW); + return true; default: // invalid/unknown break; } diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 2a59852..67203aa 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -22,6 +22,8 @@ #include "DCCWaveform.h" #include "DIAG.h" +const int NORMAL_SIGNAL_TIME=58; // this is the 58uS DCC 1-bit waveform half-cycle +const int SLOW_SIGNAL_TIME=NORMAL_SIGNAL_TIME*256; DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true); DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false); @@ -47,10 +49,15 @@ void DCCWaveform::begin(MotorDriver * mainDriver, MotorDriver * progDriver, byte return; } interruptTimer->initialize(); - interruptTimer->setPeriod(58); // this is the 58uS DCC 1-bit waveform half-cycle + interruptTimer->setPeriod(NORMAL_SIGNAL_TIME); // this is the 58uS DCC 1-bit waveform half-cycle interruptTimer->attachInterrupt(interruptHandler); interruptTimer->start(); } +void DCCWaveform::setDiagnosticSlowWave(bool slow) { + interruptTimer->setPeriod(slow? SLOW_SIGNAL_TIME : NORMAL_SIGNAL_TIME); + interruptTimer->start(); + DIAG(F("\nDCC SLOW WAVE %S\n"),slow?F("SET. DO NOT ADD LOCOS TO TRACK"):F("RESET")); +} void DCCWaveform::loop() { mainTrack.checkPowerOverload(); diff --git a/DCCWaveform.h b/DCCWaveform.h index fa2d444..96e5887 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -49,6 +49,7 @@ class DCCWaveform { public: DCCWaveform( byte preambleBits, bool isMain); static void begin(MotorDriver * mainDriver, MotorDriver * progDriver, byte timerNumber); + static void setDiagnosticSlowWave(bool slow); static void loop(); static DCCWaveform mainTrack; static DCCWaveform progTrack;