From f6b5a47975941002659bc808946f806bdcad125d Mon Sep 17 00:00:00 2001 From: SteveT Date: Mon, 28 Sep 2020 19:07:27 -0400 Subject: [PATCH 01/15] add support for FireBox_Mk1, reduce heartbeat, separate eStop time --- DCC.h | 2 ++ WiThrottle.cpp | 27 ++++++++++++++------------- WiThrottle.h | 5 +++-- defines.h | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/DCC.h b/DCC.h index 0e8fcc6..580d8b7 100644 --- a/DCC.h +++ b/DCC.h @@ -156,6 +156,8 @@ private: #define ARDUINO_TYPE "MEGA" #elif defined(ARDUINO_ARCH_MEGAAVR) #define ARDUINO_TYPE "UNOWIFIR2" +#elif defined(ARDUINO_SAMD_ZERO) + #define ARDUINO_TYPE "FireBoxMK1" #else #error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH AN ARDUINO UNO, NANO 328, OR ARDUINO MEGA 1280/2560 #endif diff --git a/WiThrottle.cpp b/WiThrottle.cpp index f9c5a41..044b00b 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -46,6 +46,8 @@ #include "StringFormatter.h" #include "Turnouts.h" #include "DIAG.h" +#include "GITHUB_SHA.h" +#include "version.h" #define LOOPLOCOS(THROTTLECHAR, CAB) for (int loco=0;loco\n"), myLocos[loco].throttle, LorS(myLocos[loco].cab), myLocos[loco].cab); } } - if (Diag::WITHROTTLE) DIAG(F("WiThrottle(%d) Quit\n"), clientid); + if (Diag::WITHROTTLE) DIAG(F("%l WiThrottle(%d) Quit\n"),millis(),clientid); delete this; break; } @@ -343,19 +346,17 @@ void WiThrottle::loop() { } void WiThrottle::checkHeartbeat() { - // if 2 heartbeats missed... drop connection and eStop any locos still assigned to this client - if(heartBeatEnable && (millis()-heartBeat > HEARTBEAT_TIMEOUT*2000)) { - if (Diag::WITHROTTLE) DIAG(F("\n\nWiThrottle(%d) hearbeat missed, dropping connection\n\n"),clientid); + // if eStop time passed... eStop any locos still assigned to this client and then drop the connection + if(heartBeatEnable && (millis()-heartBeat > ESTOP_SECONDS*1000)) { + if (Diag::WITHROTTLE) DIAG(F("\n\n%l WiThrottle(%d) eStop(%ds) timeout, drop connection\n"), millis(), clientid, ESTOP_SECONDS); LOOPLOCOS('*', -1) { if (myLocos[loco].throttle!='\0') { - if (Diag::WITHROTTLE) DIAG(F(" eStopping cab %d\n"), myLocos[loco].cab); + if (Diag::WITHROTTLE) DIAG(F("%l eStopping cab %d\n"),millis(),myLocos[loco].cab); DCC::setThrottle(myLocos[loco].cab, 1, DCC::getThrottleDirection(myLocos[loco].cab)); // speed 1 is eStop } } delete this; - } else { - // TODO Check if anything has changed on my locos since last notified! - } + } } char WiThrottle::LorS(int cab) { diff --git a/WiThrottle.h b/WiThrottle.h index ad29ee5..c1b5bba 100644 --- a/WiThrottle.h +++ b/WiThrottle.h @@ -35,8 +35,9 @@ class WiThrottle { WiThrottle( int wifiClientId); ~WiThrottle(); - static const int MAX_MY_LOCO=10; //maximum number of locos assigned to a single client - static const int HEARTBEAT_TIMEOUT=2;// heartbeat at 2secs to provide messaging transport + static const int MAX_MY_LOCO=10; // maximum number of locos assigned to a single client + static const int HEARTBEAT_SECONDS=4; // heartbeat at 4secs to provide messaging transport + static const int ESTOP_SECONDS=8; // eStop if no incoming messages for more than 8secs static WiThrottle* firstThrottle; static int getInt(byte * cmd); static int getLocoId(byte * cmd); diff --git a/defines.h b/defines.h index 700687b..99b49bd 100644 --- a/defines.h +++ b/defines.h @@ -22,7 +22,7 @@ // // WIFI_ON: All prereqs for running with WIFI are met // -#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)) +#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO)) #define WIFI_ON #endif From 052178970b043cdbba626b34b822a4f0a03043c0 Mon Sep 17 00:00:00 2001 From: SteveT Date: Thu, 29 Oct 2020 12:47:44 -0400 Subject: [PATCH 02/15] make match master --- defines.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/defines.h b/defines.h index 99b49bd..8b59930 100644 --- a/defines.h +++ b/defines.h @@ -22,8 +22,11 @@ // // WIFI_ON: All prereqs for running with WIFI are met // + #if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO)) -#define WIFI_ON +#define WIFI_ON true +#else +#define WIFI_ON false #endif //////////////////////////////////////////////////////////////////////////////// @@ -31,15 +34,4 @@ // This defines the speed at which the Arduino will communicate with the ESP8266 module. // Currently only devices which can communicate at 115200 are supported. // -#define WIFI_SERIAL_LINK_SPEED 115200 - -//////////////////////////////////////////////////////////////////////////////// -// -// Figure out number of serial ports depending on hardware -// -#if (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)) -#define NUM_SERIAL 3 -#endif -#ifndef NUM_SERIAL -#define NUM_SERIAL 1 -#endif +#define WIFI_SERIAL_LINK_SPEED 115200 \ No newline at end of file From 9e0dcb6fc8ce3252b12b9d98642c965194ce6cb9 Mon Sep 17 00:00:00 2001 From: SteveT Date: Thu, 29 Oct 2020 12:52:10 -0400 Subject: [PATCH 03/15] make match master --- defines.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/defines.h b/defines.h index 8b59930..01757d7 100644 --- a/defines.h +++ b/defines.h @@ -22,7 +22,6 @@ // // WIFI_ON: All prereqs for running with WIFI are met // - #if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO)) #define WIFI_ON true #else @@ -34,4 +33,4 @@ // This defines the speed at which the Arduino will communicate with the ESP8266 module. // Currently only devices which can communicate at 115200 are supported. // -#define WIFI_SERIAL_LINK_SPEED 115200 \ No newline at end of file +#define WIFI_SERIAL_LINK_SPEED 115200 From 0d51294ea5817b0bf09504b79f9e1bf2010d2da6 Mon Sep 17 00:00:00 2001 From: SteveT Date: Thu, 29 Oct 2020 12:53:07 -0400 Subject: [PATCH 04/15] Update defines.h --- defines.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/defines.h b/defines.h index 01757d7..4a511c4 100644 --- a/defines.h +++ b/defines.h @@ -22,10 +22,12 @@ // // WIFI_ON: All prereqs for running with WIFI are met // + #if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_SAMD_ZERO)) #define WIFI_ON true #else #define WIFI_ON false + #endif //////////////////////////////////////////////////////////////////////////////// From ef95e98a44084499f4b2e63afdaeb3ef564f4333 Mon Sep 17 00:00:00 2001 From: SteveT Date: Fri, 11 Dec 2020 09:33:18 -0500 Subject: [PATCH 05/15] FIX: return WiThrottle speedstep, not DCC speedstep, in response to speed change request. Should close #104 --- WiThrottle.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 61f7f92..64cb2c1 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -262,10 +262,10 @@ void WiThrottle::locoAction(RingStream * stream, byte* aval, char throttleChar, switch (aval[0]) { case 'V': // Vspeed { - byte locospeed=WiTToDCCSpeed(getInt(aval+1)); + byte witSpeed=getInt(aval+1); LOOPLOCOS(throttleChar, cab) { - DCC::setThrottle(myLocos[loco].cab, locospeed, DCC::getThrottleDirection(myLocos[loco].cab)); - StringFormatter::send(stream,F("M%cA%c%d<;>V%d\n"), throttleChar, LorS(myLocos[loco].cab), myLocos[loco].cab, locospeed); + DCC::setThrottle(myLocos[loco].cab, WiTToDCCSpeed(witSpeed), DCC::getThrottleDirection(myLocos[loco].cab)); + StringFormatter::send(stream,F("M%cA%c%d<;>V%d\n"), throttleChar, LorS(myLocos[loco].cab), myLocos[loco].cab, witSpeed); } } break; From 47641a4b01398e65aa6be2dc4d3107ec350ca751 Mon Sep 17 00:00:00 2001 From: SteveT Date: Fri, 11 Dec 2020 13:29:55 -0500 Subject: [PATCH 06/15] use int, not byte for witSpeed --- WiThrottle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiThrottle.cpp b/WiThrottle.cpp index 64cb2c1..d9b9ec7 100644 --- a/WiThrottle.cpp +++ b/WiThrottle.cpp @@ -262,7 +262,7 @@ void WiThrottle::locoAction(RingStream * stream, byte* aval, char throttleChar, switch (aval[0]) { case 'V': // Vspeed { - byte witSpeed=getInt(aval+1); + int witSpeed=getInt(aval+1); LOOPLOCOS(throttleChar, cab) { DCC::setThrottle(myLocos[loco].cab, WiTToDCCSpeed(witSpeed), DCC::getThrottleDirection(myLocos[loco].cab)); StringFormatter::send(stream,F("M%cA%c%d<;>V%d\n"), throttleChar, LorS(myLocos[loco].cab), myLocos[loco].cab, witSpeed); From bc14cb176f03a280f51c838ae10fca2322bb8658 Mon Sep 17 00:00:00 2001 From: SteveT Date: Wed, 23 Dec 2020 20:01:11 -0500 Subject: [PATCH 07/15] add turnout, sensor and output states to 's'tatus message --- DCCEXParser.cpp | 10 ++++++---- Outputs.cpp | 6 ++++++ Outputs.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index e4949ce..0a78676 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -445,9 +445,11 @@ 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 + Output::printAll(stream); //send all Output states + Sensor::printAll(stream); //send all Sensor states // TODO Send stats of speed reminders table - // TODO send status of turnouts etc etc - return; + return; case 'E': // STORE EPROM EEStore::store(); @@ -589,7 +591,7 @@ bool DCCEXParser::parseT(Print *stream, int params, int p[]) { switch (params) { - case 0: // show all turnouts + case 0: // list all turnout states { bool gotOne = false; for (Turnout *tt = Turnout::firstTurnout; tt != NULL; tt = tt->nextTurnout) @@ -644,7 +646,7 @@ bool DCCEXParser::parseS(Print *stream, int params, int p[]) StringFormatter::send(stream, F("")); return true; - case 0: // lit sensor states + case 0: // list sensor states if (Sensor::firstSensor == NULL) return false; for (Sensor *tt = Sensor::firstSensor; tt != NULL; tt = tt->nextSensor) diff --git a/Outputs.cpp b/Outputs.cpp index 84290fe..b135d0f 100644 --- a/Outputs.cpp +++ b/Outputs.cpp @@ -83,7 +83,13 @@ the state of any outputs being monitored or controlled by a separate interface o #include "Outputs.h" #include "EEStore.h" +#include "StringFormatter.h" +// print all output states to stream +void Output::printAll(Print *stream){ + for (Output *tt = Output::firstOutput; tt != NULL; tt = tt->nextOutput) + StringFormatter::send(stream, F(""), tt->data.id, tt->data.oStatus); +} // Output::printAll void Output::activate(int s){ data.oStatus=(s>0); // if s>0, set status to active, else inactive diff --git a/Outputs.h b/Outputs.h index 891cd9b..319f704 100644 --- a/Outputs.h +++ b/Outputs.h @@ -39,6 +39,7 @@ class Output{ static Output *firstOutput; struct OutputData data; Output *nextOutput; + static void printAll(Print *); private: int num; // Chris has no idea what this is all about! From 7e7435eafa5523136ec3c0958e4a17c56f4ab87d Mon Sep 17 00:00:00 2001 From: SteveT Date: Mon, 28 Dec 2020 21:00:18 -0500 Subject: [PATCH 08/15] should send turnout definitions, not just states --- DCCEXParser.cpp | 11 ++++++----- StringFormatter.cpp | 4 ++-- Turnouts.cpp | 7 +++++++ Turnouts.h | 1 + 4 files changed, 16 insertions(+), 7 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/StringFormatter.cpp b/StringFormatter.cpp index a8ab5cf..c5813a0 100644 --- a/StringFormatter.cpp +++ b/StringFormatter.cpp @@ -34,8 +34,8 @@ #include "LCDDisplay.h" bool Diag::ACK=false; -bool Diag::CMD=false; -bool Diag::WIFI=false; +bool Diag::CMD=true; +bool Diag::WIFI=true; bool Diag::WITHROTTLE=false; bool Diag::ETHERNET=false; 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 98d6ff770913a4d1c58b8132ffbde8bd15393ac2 Mon Sep 17 00:00:00 2001 From: SteveT Date: Mon, 28 Dec 2020 21:02:04 -0500 Subject: [PATCH 09/15] undo inadvertent commit --- StringFormatter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/StringFormatter.cpp b/StringFormatter.cpp index c5813a0..a8ab5cf 100644 --- a/StringFormatter.cpp +++ b/StringFormatter.cpp @@ -34,8 +34,8 @@ #include "LCDDisplay.h" bool Diag::ACK=false; -bool Diag::CMD=true; -bool Diag::WIFI=true; +bool Diag::CMD=false; +bool Diag::WIFI=false; bool Diag::WITHROTTLE=false; bool Diag::ETHERNET=false; From e7ada19c97749ec3e9d0e69d2555aba2e12ad9d1 Mon Sep 17 00:00:00 2001 From: SteveT Date: Wed, 6 Jan 2021 16:05:31 -0500 Subject: [PATCH 10/15] send milliAmps and meter setup for new JMRI Meter function --- DCCEXParser.cpp | 5 ++++- DCCWaveform.h | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index c488fc1..fd1cea0 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -442,7 +442,10 @@ void DCCEXParser::parse(Print *stream, byte *com, bool blocking) return; case 'c': // READ CURRENT - StringFormatter::send(stream, F(""), DCCWaveform::mainTrack.get1024Current()); + // + StringFormatter::send(stream, F(""), DCCWaveform::mainTrack.getCurrentmA(), DCCWaveform::mainTrack.getMaxmA()); + // StringFormatter::send(stream, F(""), DCCWaveform::progTrack.getCurrentmA(), DCCWaveform::progTrack.getMaxmA()); + StringFormatter::send(stream, F(""), DCCWaveform::mainTrack.get1024Current()); //'a' message deprecated, remove once JMRI 4.22 is available return; case 'Q': // SENSORS diff --git a/DCCWaveform.h b/DCCWaveform.h index b51e79f..f01151b 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -58,9 +58,23 @@ class DCCWaveform { void checkPowerOverload(); int getLastCurrent(); inline int get1024Current() { - if (powerMode == POWERMODE::ON) - return (int)(lastCurrent*(long int)1024/motorDriver->getRawCurrentTripValue()); - return 0; + if (powerMode == POWERMODE::ON) + return (int)(lastCurrent*(long int)1024/motorDriver->getRawCurrentTripValue()); + return 0; + } + inline int getCurrentmA() { + if (powerMode == POWERMODE::ON) + return motorDriver->raw2mA(lastCurrent); + return 0; + } + inline int getMaxmA() { + if (maxmA == 0) { //only calculate this for first request, it doesn't change + maxmA = motorDriver->raw2mA(motorDriver->getRawCurrentTripValue()); + } + return maxmA; + } + inline int getRawCurrentTripValue() { + return motorDriver->getRawCurrentTripValue(); } void schedulePacket(const byte buffer[], byte byteCount, byte repeats); volatile bool packetPending; @@ -112,7 +126,7 @@ class DCCWaveform { byte pendingLength; byte pendingRepeats; int lastCurrent; - + int maxmA; // current sampling POWERMODE powerMode; From 7f27cfc9cb5540a346dd253dc96dc9ef9588d2ae Mon Sep 17 00:00:00 2001 From: SteveT Date: Wed, 6 Jan 2021 16:09:26 -0500 Subject: [PATCH 11/15] send milliAmps and meter setup for new JMRI Meter function --- DCCWaveform.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/DCCWaveform.h b/DCCWaveform.h index f01151b..50362e0 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -73,9 +73,6 @@ class DCCWaveform { } return maxmA; } - inline int getRawCurrentTripValue() { - return motorDriver->getRawCurrentTripValue(); - } void schedulePacket(const byte buffer[], byte byteCount, byte repeats); volatile bool packetPending; volatile byte sentResetsSincePacket; From da31e9cbc519f965366fa3e3ec342ab75b632a16 Mon Sep 17 00:00:00 2001 From: SteveT Date: Wed, 6 Jan 2021 16:13:58 -0500 Subject: [PATCH 12/15] send milliAmps and meter setup for new JMRI Meter function --- DCCWaveform.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/DCCWaveform.h b/DCCWaveform.h index 50362e0..f8b2536 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -58,20 +58,20 @@ class DCCWaveform { void checkPowerOverload(); int getLastCurrent(); inline int get1024Current() { - if (powerMode == POWERMODE::ON) - return (int)(lastCurrent*(long int)1024/motorDriver->getRawCurrentTripValue()); - return 0; + if (powerMode == POWERMODE::ON) + return (int)(lastCurrent*(long int)1024/motorDriver->getRawCurrentTripValue()); + return 0; } inline int getCurrentmA() { - if (powerMode == POWERMODE::ON) - return motorDriver->raw2mA(lastCurrent); - return 0; + if (powerMode == POWERMODE::ON) + return motorDriver->raw2mA(lastCurrent); + return 0; } inline int getMaxmA() { - if (maxmA == 0) { //only calculate this for first request, it doesn't change - maxmA = motorDriver->raw2mA(motorDriver->getRawCurrentTripValue()); - } - return maxmA; + if (maxmA == 0) { //only calculate this for first request, it doesn't change + maxmA = motorDriver->raw2mA(motorDriver->getRawCurrentTripValue()); + } + return maxmA; } void schedulePacket(const byte buffer[], byte byteCount, byte repeats); volatile bool packetPending; From f1116ffba4f5a444e09f24d68b0e118f49ddb922 Mon Sep 17 00:00:00 2001 From: SteveT Date: Wed, 6 Jan 2021 16:27:14 -0500 Subject: [PATCH 13/15] send milliAmps and meter setup for new JMRI Meter function --- DCCWaveform.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DCCWaveform.h b/DCCWaveform.h index f8b2536..3755979 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -63,13 +63,13 @@ class DCCWaveform { return 0; } inline int getCurrentmA() { - if (powerMode == POWERMODE::ON) - return motorDriver->raw2mA(lastCurrent); - return 0; + if (powerMode == POWERMODE::ON) + return motorDriver->raw2mA(lastCurrent); + return 0; } inline int getMaxmA() { if (maxmA == 0) { //only calculate this for first request, it doesn't change - maxmA = motorDriver->raw2mA(motorDriver->getRawCurrentTripValue()); + maxmA = motorDriver->raw2mA(motorDriver->getRawCurrentTripValue()); } return maxmA; } From de4bf42923a871fb006019d9aafdf02a73d1b986 Mon Sep 17 00:00:00 2001 From: SteveT Date: Mon, 18 Jan 2021 09:14:41 -0500 Subject: [PATCH 14/15] add warn/trip level to meter response provides support for separate max vs trip levels --- DCCEXParser.cpp | 8 ++++---- DCCWaveform.h | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index fd1cea0..3ecdb61 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -441,10 +441,10 @@ void DCCEXParser::parse(Print *stream, byte *com, bool blocking) } return; - case 'c': // READ CURRENT - // - StringFormatter::send(stream, F(""), DCCWaveform::mainTrack.getCurrentmA(), DCCWaveform::mainTrack.getMaxmA()); - // StringFormatter::send(stream, F(""), DCCWaveform::progTrack.getCurrentmA(), DCCWaveform::progTrack.getMaxmA()); + case 'c': // SEND METER RESPONSES + // + StringFormatter::send(stream, F(""), DCCWaveform::mainTrack.getCurrentmA(), + DCCWaveform::mainTrack.getMaxmA(), DCCWaveform::mainTrack.getTripmA()); StringFormatter::send(stream, F(""), DCCWaveform::mainTrack.get1024Current()); //'a' message deprecated, remove once JMRI 4.22 is available return; diff --git a/DCCWaveform.h b/DCCWaveform.h index 3755979..7908e02 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -69,10 +69,16 @@ class DCCWaveform { } inline int getMaxmA() { if (maxmA == 0) { //only calculate this for first request, it doesn't change - maxmA = motorDriver->raw2mA(motorDriver->getRawCurrentTripValue()); + maxmA = motorDriver->raw2mA(motorDriver->getRawCurrentTripValue()); //TODO: replace with actual max value or calc } return maxmA; } + inline int getTripmA() { + if (tripmA == 0) { //only calculate this for first request, it doesn't change + tripmA = motorDriver->raw2mA(motorDriver->getRawCurrentTripValue()); + } + return tripmA; + } void schedulePacket(const byte buffer[], byte byteCount, byte repeats); volatile bool packetPending; volatile byte sentResetsSincePacket; @@ -124,6 +130,7 @@ class DCCWaveform { byte pendingRepeats; int lastCurrent; int maxmA; + int tripmA; // current sampling POWERMODE powerMode; From 4e2bb445d18302701e5294b5c4d4867f089fb74a Mon Sep 17 00:00:00 2001 From: mstevetodd Date: Tue, 16 Feb 2021 01:26:09 +0000 Subject: [PATCH 15/15] Committing a SHA --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 096d2bb..5451ada 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "62d1f46" +#define GITHUB_SHA "ae6958b"