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

<1 JOIN> <F> and other commands

<1 JOIN> for prog track siding
<F> to set locio function individually
<!> in Example filter to forget locos
<$ .. or any unknown char> to deebug
This commit is contained in:
Asbelos 2020-07-30 15:34:56 +01:00
parent 45863a043f
commit a14b9ef8bf
2 changed files with 36 additions and 17 deletions

View File

@ -38,15 +38,10 @@
void myFilter(Print & stream, byte & opcode, byte & paramCount, int p[]) { void myFilter(Print & stream, byte & opcode, byte & paramCount, int p[]) {
(void)stream; // avoid compiler warning if we don't access this parameter (void)stream; // avoid compiler warning if we don't access this parameter
switch (opcode) { switch (opcode) {
case 'F': // Invent new command to call the new Loco Function API <F cab func 1|0> case '!': // Create a bespoke new command to clear all loco reminders <!> or specific locos e.g <! 3 4 99>
DIAG(F("Setting loco %d F%d %S"),p[0],p[1],p[2]?F("ON"):F("OFF")); if (paramCount==0) DCC::forgetAllLocos();
DCC::setFn(p[0],p[1],p[2]==1); else for (int i=0;i<paramCount;i++) DCC::forgetLoco(p[i]);
opcode=0; // tell parser to ignore this command opcode=0; // tell parser to ignore this command as we have done it already
break;
case '$': // Diagnose parser <$....>
DIAG(F("$ paramCount=%d\n"),paramCount);
for (int i=0;i<paramCount;i++) DIAG(F("p[%d]=%d (0x%x)\n"),i,p[i],p[i]);
opcode=0; // Normal parser wont understand $,
break; break;
default: // drop through and parser will use the command unaltered. default: // drop through and parser will use the command unaltered.
break; break;

View File

@ -29,8 +29,12 @@
const char VERSION[] PROGMEM ="99.666"; const char VERSION[] PROGMEM ="99.666";
// These keywords are used in the <1> 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_PROG=-29718;
const int HASH_KEYWORD_MAIN=11339; const int HASH_KEYWORD_MAIN=11339;
const int HASH_KEYWORD_JOIN=-30750;
int DCCEXParser::stashP[MAX_PARAMS]; int DCCEXParser::stashP[MAX_PARAMS];
bool DCCEXParser::stashBusy; bool DCCEXParser::stashBusy;
@ -202,23 +206,35 @@ void DCCEXParser::parse(Print & stream, const byte *com, bool blocking) {
if (params>1) break; if (params>1) break;
{ {
POWERMODE mode= opcode=='1'?POWERMODE::ON:POWERMODE::OFF; 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) { if (params==0) {
DCCWaveform::mainTrack.setPowerMode(mode); DCCWaveform::mainTrack.setPowerMode(mode);
DCCWaveform::progTrack.setPowerMode(mode); DCCWaveform::progTrack.setPowerMode(mode);
StringFormatter::send(stream,F("<p%c>"),opcode); StringFormatter::send(stream,F("<p%c>"),opcode);
return; return;
} }
if (p[0]==HASH_KEYWORD_MAIN) { switch (p[0]) {
case HASH_KEYWORD_MAIN:
DCCWaveform::mainTrack.setPowerMode(mode); DCCWaveform::mainTrack.setPowerMode(mode);
StringFormatter::send(stream,F("<p%c MAIN>"),opcode); StringFormatter::send(stream,F("<p%c MAIN>"),opcode);
return; return;
}
if (p[0]==HASH_KEYWORD_PROG) { case HASH_KEYWORD_PROG:
DCCWaveform::progTrack.setPowerMode(mode); DCCWaveform::progTrack.setPowerMode(mode);
StringFormatter::send(stream,F("<p%c PROG>"),opcode); StringFormatter::send(stream,F("<p%c PROG>"),opcode);
return; return;
case HASH_KEYWORD_JOIN:
DCCWaveform::mainTrack.setPowerMode(mode);
DCCWaveform::progTrack.setPowerMode(mode);
if (mode==POWERMODE::ON) {
DCC::setProgTrackSyncMain(true);
StringFormatter::send(stream,F("<p1 JOIN>"),opcode);
} }
DIAG(F("keyword hash=%d\n"),p[0]); else StringFormatter::send(stream,F("<p0>"));
return;
}
DIAG(F("\nUnexpected keyword hash=%d\n"),p[0]);
break; break;
} }
return; return;
@ -261,7 +277,15 @@ void DCCEXParser::parse(Print & stream, const byte *com, bool blocking) {
StringFormatter::send(stream,F("<# %d>"), MAX_LOCOS); StringFormatter::send(stream,F("<# %d>"), MAX_LOCOS);
return; return;
default: //anything else will drop out to <X> case 'F': // New command to call the new Loco Function API <F cab func 1|0>
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 <X>
DIAG(F("\nOpcode=%c params=%d\n"),opcode,params);
for (int i=0;i<params;i++) DIAG(F("p[%d]=%d (0x%x)\n"),i,p[i],p[i]);
break; break;
} // end of opcode switch } // end of opcode switch