From f7861e5103307c813de8d42f8ab9a811514e5c0e Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 14 Nov 2021 20:37:24 +0100 Subject: [PATCH] show current from main on LDC every 2 sec --- DCCWaveform.cpp | 11 +++++++++-- GITHUB_SHA.h | 2 +- StringFormatter.cpp | 13 +++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index dd447ca..99a59a3 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -34,6 +34,8 @@ int DCCWaveform::progTripValue=0; volatile uint8_t DCCWaveform::numAckGaps=0; volatile uint8_t DCCWaveform::numAckSamples=0; uint8_t DCCWaveform::trailingEdgeCounter=0; +static unsigned long lastLCDCurrentDisplay=0; +#define LCD_SAMPLE_PERIOD 2000 // milliseconds void DCCWaveform::begin(MotorDriver * mainDriver, MotorDriver * progDriver) { mainTrack.motorDriver=mainDriver; @@ -119,8 +121,9 @@ void DCCWaveform::setPowerMode(POWERMODE mode) { void DCCWaveform::checkPowerOverload(bool ackManagerActive) { - if (millis() - lastSampleTaken < sampleDelay) return; - lastSampleTaken = millis(); + unsigned long now = millis(); + if (now - lastSampleTaken < sampleDelay) return; + lastSampleTaken = now; int tripValue= motorDriver->getRawCurrentTripValue(); if (!isMainTrack && !ackManagerActive && !progTrackSyncMain && !progTrackBoosted) tripValue=progTripValue; @@ -181,6 +184,10 @@ void DCCWaveform::checkPowerOverload(bool ackManagerActive) { default: sampleDelay = 999; // cant get here..meaningless statement to avoid compiler warning. } + if (isMainTrack && now - lastLCDCurrentDisplay > LCD_SAMPLE_PERIOD) { + lastLCDCurrentDisplay=now; + LCD(2,F("I= %dmA"), mainTrack.getCurrentmA()); + } } // For each state of the wave nextState=stateTransform[currentState] const WAVE_STATE DCCWaveform::stateTransform[]={ diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 674c2ef..551d1bd 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "ee5db61" +#define GITHUB_SHA "LDC-show-current 2021114-20:14" diff --git a/StringFormatter.cpp b/StringFormatter.cpp index a5c33cf..a0426fd 100644 --- a/StringFormatter.cpp +++ b/StringFormatter.cpp @@ -50,12 +50,13 @@ void StringFormatter::lcd(byte row, const FSH* input...) { va_list args; // Issue the LCD as a diag first - send(diagSerial,F("<* LCD%d:"),row); - va_start(args, input); - send2(diagSerial,input,args); - send(diagSerial,F(" *>\n")); - - if (!LCDDisplay::lcdDisplay) return; + if (!LCDDisplay::lcdDisplay) { + send(diagSerial,F("<* LCD%d:"),row); + va_start(args, input); + send2(diagSerial,input,args); + send(diagSerial,F(" *>\n")); + return; + } LCDDisplay::lcdDisplay->setRow(row); va_start(args, input); send2(LCDDisplay::lcdDisplay,input,args);