1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 13:21:23 +01:00

Make last current available from API

Required for JMRI interface.
This commit is contained in:
Asbelos 2020-06-02 13:20:36 +01:00
parent 23f15131a8
commit 3a8c83afa6
2 changed files with 9 additions and 4 deletions

View File

@ -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;
}

View File

@ -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