diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 789af0c..7068036 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -73,7 +73,6 @@ void DCCWaveform::setPowerMode(POWERMODE mode) { void DCCWaveform::checkPowerOverload() { if (millis() < nextSampleDue) return; - int current; int delay; switch (powerMode) { @@ -82,11 +81,11 @@ void DCCWaveform::checkPowerOverload() { break; case POWERMODE::ON: // Check current - current = Hardware::getCurrentMilliamps(isMainTrack); - if (current < POWER_SAMPLE_MAX) delay = POWER_SAMPLE_ON_WAIT; + lastCurrent = Hardware::getCurrentMilliamps(isMainTrack); + if (lastCurrent < POWER_SAMPLE_MAX) delay = POWER_SAMPLE_ON_WAIT; else { setPowerMode(POWERMODE::OVERLOAD); - DIAG(F("\n*** %s TRACK POWER OVERLOAD current=%d max=%d ***\n"), isMainTrack ? "MAIN" : "PROG", current, POWER_SAMPLE_MAX); + DIAG(F("\n*** %s TRACK POWER OVERLOAD current=%d max=%d ***\n"), isMainTrack ? "MAIN" : "PROG", lastCurrent, POWER_SAMPLE_MAX); delay = POWER_SAMPLE_OVERLOAD_WAIT; } break; @@ -245,3 +244,7 @@ bool DCCWaveform::schedulePacketWithAck(const byte buffer[], byte byteCount, byt DIAG(F("ack=%d max=%d, up=%d"), result, maxCurrent, upsamples); return result; } + +int DCCWaveform::getLastCurrent() { + return lastCurrent; +} diff --git a/DCCWaveform.h b/DCCWaveform.h index 9cfca89..5b9234d 100644 --- a/DCCWaveform.h +++ b/DCCWaveform.h @@ -44,6 +44,7 @@ class DCCWaveform { void setPowerMode(POWERMODE); POWERMODE getPowerMode(); void checkPowerOverload(); + int getLastCurrent(); void schedulePacket(const byte buffer[], byte byteCount, byte repeats); bool schedulePacketWithAck(const byte buffer[], byte byteCount, byte repeats); volatile bool packetPending; @@ -72,6 +73,7 @@ class DCCWaveform { byte pendingPacket[MAX_PACKET_SIZE]; byte pendingLength; byte pendingRepeats; + int lastCurrent; // current sampling