From 895b2aaaaaee935b92fef5d41c0487dfa6db9fd2 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Thu, 7 Jan 2021 20:58:23 +0000 Subject: [PATCH] Implement mySetup.h facility --- CommandStation-EX.ino | 10 ++++++++-- DCCEXParser.cpp | 8 ++++++++ DCCEXParser.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 18f2aaa..c0c3a1d 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -53,11 +53,17 @@ void setup() // waveform generation. e.g. DCC::begin(STANDARD_MOTOR_SHIELD,2); to use timer 2 DCC::begin(MOTOR_SHIELD_TYPE); - + #if defined(RMFT_ACTIVE) RMFT::begin(); #endif - + + #if __has_include ( "mySetup.h") + #define SETUP(cmd) serialParser.parse(F(cmd)) + #include "mySetup.h" + #undef SETUP + #endif + LCD(1,F("Ready")); } diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index c488fc1..59d0b74 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -236,6 +236,14 @@ void DCCEXParser::setAtCommandCallback(AT_COMMAND_CALLBACK callback) atCommandCallback = callback; } +// Parse an F() string +void DCCEXParser::parse(const __FlashStringHelper * cmd) { + int size=strlen_P((char *)cmd)+1; + char buffer[size]; + strcpy_P(buffer,(char *)cmd); + parse(&Serial,(byte *)buffer,true); +} + // See documentation on DCC class for info on this section void DCCEXParser::parse(Print *stream, byte *com, bool blocking) { diff --git a/DCCEXParser.h b/DCCEXParser.h index bef1199..d2423d0 100644 --- a/DCCEXParser.h +++ b/DCCEXParser.h @@ -28,6 +28,7 @@ struct DCCEXParser DCCEXParser(); void loop(Stream & stream); void parse(Print * stream, byte * command, bool blocking); + void parse(const __FlashStringHelper * cmd); void flush(); static void setFilter(FILTER_CALLBACK filter); static void setRMFTFilter(FILTER_CALLBACK filter);