From 42075f838ecc5f52da388b3a3fda1f08906dabf8 Mon Sep 17 00:00:00 2001 From: mstevetodd Date: Mon, 4 Jan 2021 10:57:03 -0500 Subject: [PATCH 1/2] should send turnout definitions, not just states (#110) * use int, not byte for witSpeed * add turnout, sensor and output states to 's'tatus message * should send turnout definitions, not just states --- DCCEXParser.cpp | 11 ++++++----- Turnouts.cpp | 7 +++++++ Turnouts.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 0a78676..753f69b 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -445,7 +445,7 @@ void DCCEXParser::parse(Print *stream, byte *com, bool blocking) case 's': // StringFormatter::send(stream, F(""), DCCWaveform::mainTrack.getPowerMode() == POWERMODE::ON); StringFormatter::send(stream, F(""), F(VERSION), F(ARDUINO_TYPE), DCC::getMotorShieldName(), F(GITHUB_SHA)); - parseT(stream, 0, p); //send all Turnout states + Turnout::printAll(stream); //send all Turnout states Output::printAll(stream); //send all Output states Sensor::printAll(stream); //send all Sensor states // TODO Send stats of speed reminders table @@ -529,7 +529,7 @@ bool DCCEXParser::parseZ(Print *stream, int params, int p[]) StringFormatter::send(stream, F("")); return true; - case 0: // + case 0: // list Output definitions { bool gotone = false; for (Output *tt = Output::firstOutput; tt != NULL; tt = tt->nextOutput) @@ -591,13 +591,14 @@ bool DCCEXParser::parseT(Print *stream, int params, int p[]) { switch (params) { - case 0: // list all turnout states + case 0: // list turnout definitions { bool gotOne = false; for (Turnout *tt = Turnout::firstTurnout; tt != NULL; tt = tt->nextTurnout) { gotOne = true; - StringFormatter::send(stream, F(""), tt->data.id, (tt->data.tStatus & STATUS_ACTIVE)!=0); + StringFormatter::send(stream, F(""), tt->data.id, tt->data.address, + tt->data.subAddress, (tt->data.tStatus & STATUS_ACTIVE)!=0); } return gotOne; // will if none found } @@ -646,7 +647,7 @@ bool DCCEXParser::parseS(Print *stream, int params, int p[]) StringFormatter::send(stream, F("")); return true; - case 0: // list sensor states + case 0: // list sensor definitions if (Sensor::firstSensor == NULL) return false; for (Sensor *tt = Sensor::firstSensor; tt != NULL; tt = tt->nextSensor) diff --git a/Turnouts.cpp b/Turnouts.cpp index 45b3c1b..03093a1 100644 --- a/Turnouts.cpp +++ b/Turnouts.cpp @@ -21,10 +21,17 @@ #include "Turnouts.h" #include "EEStore.h" #include "PWMServoDriver.h" +#include "StringFormatter.h" #ifdef EESTOREDEBUG #include "DIAG.h" #endif +// print all turnout states to stream +void Turnout::printAll(Print *stream){ + for (Turnout *tt = Turnout::firstTurnout; tt != NULL; tt = tt->nextTurnout) + StringFormatter::send(stream, F(""), tt->data.id, (tt->data.tStatus & STATUS_ACTIVE)!=0); +} // Turnout::printAll + bool Turnout::activate(int n,bool state){ #ifdef EESTOREDEBUG DIAG(F("\nTurnout::activate(%d,%d)\n"),n,state); diff --git a/Turnouts.h b/Turnouts.h index 2aff97d..186149b 100644 --- a/Turnouts.h +++ b/Turnouts.h @@ -49,6 +49,7 @@ class Turnout { static Turnout *create(int id , byte pin , int activeAngle, int inactiveAngle); static Turnout *create(int id); void activate(bool state); + static void printAll(Print *); #ifdef EESTOREDEBUG void print(Turnout *tt); #endif From 0618a0bd72c974ecd130ad95ac3d9d6f3e45e212 Mon Sep 17 00:00:00 2001 From: Fred Date: Tue, 5 Jan 2021 13:05:17 -0500 Subject: [PATCH 2/2] RMFT Hooks (#112) These hooks do NOT require RMFT code to be present.... but they offer the hooks that RMFT will need when available. authored-by: Asbelos --- CommandStation-EX.ino | 9 +++++++++ DCCEX.h | 6 +++++- DCCEXParser.cpp | 7 +++++++ DCCEXParser.h | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 8b75fc4..18f2aaa 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -53,6 +53,11 @@ 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 + LCD(1,F("Ready")); } @@ -75,6 +80,10 @@ void loop() EthernetInterface::loop(); #endif +#if defined(RMFT_ACTIVE) + RMFT::loop(); +#endif + LCDDisplay::loop(); // ignored if LCD not in use // Optionally report any decrease in memory (will automatically trigger on first call) diff --git a/DCCEX.h b/DCCEX.h index d89d581..2d1d183 100644 --- a/DCCEX.h +++ b/DCCEX.h @@ -15,6 +15,10 @@ #endif #include "LCD_Implementation.h" #include "freeMemory.h" -#include +#if __has_include ( "myAutomation.h") + #include "RMFT.h" + #define RMFT_ACTIVE +#endif + #endif diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 753f69b..c488fc1 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -221,11 +221,16 @@ int DCCEXParser::splitHexValues(int result[MAX_PARAMS], const byte *cmd) } FILTER_CALLBACK DCCEXParser::filterCallback = 0; +FILTER_CALLBACK DCCEXParser::filterRMFTCallback = 0; AT_COMMAND_CALLBACK DCCEXParser::atCommandCallback = 0; void DCCEXParser::setFilter(FILTER_CALLBACK filter) { filterCallback = filter; } +void DCCEXParser::setRMFTFilter(FILTER_CALLBACK filter) +{ + filterRMFTCallback = filter; +} void DCCEXParser::setAtCommandCallback(AT_COMMAND_CALLBACK callback) { atCommandCallback = callback; @@ -245,6 +250,8 @@ void DCCEXParser::parse(Print *stream, byte *com, bool blocking) if (filterCallback) filterCallback(stream, opcode, params, p); + if (filterRMFTCallback && opcode!='\0') + filterRMFTCallback(stream, opcode, params, p); // Functions return from this switch if complete, break from switch implies error to send switch (opcode) diff --git a/DCCEXParser.h b/DCCEXParser.h index ec0286d..bef1199 100644 --- a/DCCEXParser.h +++ b/DCCEXParser.h @@ -30,6 +30,7 @@ struct DCCEXParser void parse(Print * stream, byte * command, bool blocking); void flush(); static void setFilter(FILTER_CALLBACK filter); + static void setRMFTFilter(FILTER_CALLBACK filter); static void setAtCommandCallback(AT_COMMAND_CALLBACK filter); static const int MAX_PARAMS=10; // Must not exceed this @@ -61,6 +62,7 @@ struct DCCEXParser static void callback_Vbit(int result); static void callback_Vbyte(int result); static FILTER_CALLBACK filterCallback; + static FILTER_CALLBACK filterRMFTCallback; static AT_COMMAND_CALLBACK atCommandCallback; static void funcmap(int cab, byte value, byte fstart, byte fstop);