From a14b9ef8bfa565310aa279b1cf36115de2ae3421 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 30 Jul 2020 15:34:56 +0100 Subject: [PATCH] <1 JOIN> and other commands <1 JOIN> for prog track siding to set locio function individually in Example filter to forget locos <$ .. or any unknown char> to deebug --- CVReader.ino | 13 ++++--------- DCCEXParser.cpp | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/CVReader.ino b/CVReader.ino index 1abe39c..267b833 100644 --- a/CVReader.ino +++ b/CVReader.ino @@ -38,16 +38,11 @@ void myFilter(Print & stream, byte & opcode, byte & paramCount, int p[]) { (void)stream; // avoid compiler warning if we don't access this parameter switch (opcode) { - case 'F': // Invent new command to call the new Loco Function API - DIAG(F("Setting loco %d F%d %S"),p[0],p[1],p[2]?F("ON"):F("OFF")); - DCC::setFn(p[0],p[1],p[2]==1); - opcode=0; // tell parser to ignore this command + case '!': // Create a bespoke new command to clear all loco reminders or specific locos e.g + if (paramCount==0) DCC::forgetAllLocos(); + else for (int i=0;i - DIAG(F("$ paramCount=%d\n"),paramCount); - for (int i=0;i command. The number is what you get if you use the keyword as a parameter. +// To discover new keyword numbers , use the <$ YOURKEYWORD> command const int HASH_KEYWORD_PROG=-29718; const int HASH_KEYWORD_MAIN=11339; +const int HASH_KEYWORD_JOIN=-30750; + int DCCEXParser::stashP[MAX_PARAMS]; bool DCCEXParser::stashBusy; @@ -202,23 +206,35 @@ void DCCEXParser::parse(Print & stream, const byte *com, bool blocking) { if (params>1) break; { POWERMODE mode= opcode=='1'?POWERMODE::ON:POWERMODE::OFF; + DCC::setProgTrackSyncMain(false); // Only <1 JOIN> will set this on, all others set it off if (params==0) { DCCWaveform::mainTrack.setPowerMode(mode); DCCWaveform::progTrack.setPowerMode(mode); StringFormatter::send(stream,F(""),opcode); return; } - if (p[0]==HASH_KEYWORD_MAIN) { + switch (p[0]) { + case HASH_KEYWORD_MAIN: DCCWaveform::mainTrack.setPowerMode(mode); StringFormatter::send(stream,F(""),opcode); return; - } - if (p[0]==HASH_KEYWORD_PROG) { + + case HASH_KEYWORD_PROG: DCCWaveform::progTrack.setPowerMode(mode); StringFormatter::send(stream,F(""),opcode); return; + case HASH_KEYWORD_JOIN: + DCCWaveform::mainTrack.setPowerMode(mode); + DCCWaveform::progTrack.setPowerMode(mode); + if (mode==POWERMODE::ON) { + DCC::setProgTrackSyncMain(true); + StringFormatter::send(stream,F(""),opcode); + } + else StringFormatter::send(stream,F("")); + return; + } - DIAG(F("keyword hash=%d\n"),p[0]); + DIAG(F("\nUnexpected keyword hash=%d\n"),p[0]); break; } return; @@ -258,10 +274,18 @@ void DCCEXParser::parse(Print & stream, const byte *com, bool blocking) { return; case '#': // NUMBER OF LOCOSLOTS <#> - StringFormatter::send(stream,F("<# %d>"), MAX_LOCOS); - return; - - default: //anything else will drop out to + StringFormatter::send(stream,F("<# %d>"), MAX_LOCOS); + return; + + case 'F': // New command to call the new Loco Function API + DIAG(F("Setting loco %d F%d %S"),p[0],p[1],p[2]?F("ON"):F("OFF")); + DCC::setFn(p[0],p[1],p[2]==1); + return; + + + default: //anything else will diagnose and drop out to + DIAG(F("\nOpcode=%c params=%d\n"),opcode,params); + for (int i=0;i