From 611838d60c8503dfe5c11e5b2c2e8f83d35da219 Mon Sep 17 00:00:00 2001 From: mstevetodd Date: Mon, 18 Jan 2021 17:46:41 -0500 Subject: [PATCH] add warn/trip level to meter response (#120) * send milliAmps and meter setup for new JMRI Meter function * 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;