From e7ada19c97749ec3e9d0e69d2555aba2e12ad9d1 Mon Sep 17 00:00:00 2001 From: SteveT Date: Wed, 6 Jan 2021 16:05:31 -0500 Subject: [PATCH] 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;