/* * © 2020, Chris Harlow. All rights reserved. * * This file is part of Asbelos DCC API * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * It is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with CommandStation. If not, see . */ #include "DCC.h" #include "DIAG.h" #include "DCCEXParser.h" #include "WifiInterface.h" // this code is here to demonstrate use of the DCC API and other techniques // myFilter is an example of an OPTIONAL command filter used to intercept < > commands from // the usb or wifi streamm. It demonstrates how a command may be intercepted // or even a new command created without having to break open the API library code. // The filter is permitted to use or modify the parameter list before passing it on to // the standard parser. By setting the opcode to 0, the standard parser will // just ignore the command on the assumption that you have already handled it. // // The filter must be enabled by calling the DCC EXParser::setFilter method, see use in setup(). 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 '!': // 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