1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-22 23:56:13 +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,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 <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);
opcode=0; // tell parser to ignore this command
case '!': // Create a bespoke new command to clear all loco reminders <!> or specific locos e.g <! 3 4 99>
if (paramCount==0) DCC::forgetAllLocos();
else for (int i=0;i<paramCount;i++) DCC::forgetLoco(p[i]);
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;
default: // drop through and parser will use the command unaltered.
break;
}

View File

@ -29,8 +29,12 @@
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_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("<p%c>"),opcode);
return;
}
if (p[0]==HASH_KEYWORD_MAIN) {
switch (p[0]) {
case HASH_KEYWORD_MAIN:
DCCWaveform::mainTrack.setPowerMode(mode);
StringFormatter::send(stream,F("<p%c MAIN>"),opcode);
return;
}
if (p[0]==HASH_KEYWORD_PROG) {
case HASH_KEYWORD_PROG:
DCCWaveform::progTrack.setPowerMode(mode);
StringFormatter::send(stream,F("<p%c PROG>"),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("<p1 JOIN>"),opcode);
}
else StringFormatter::send(stream,F("<p0>"));
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 <X>
StringFormatter::send(stream,F("<# %d>"), MAX_LOCOS);
return;
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;
} // end of opcode switch