diff --git a/DCCACK.cpp b/DCCACK.cpp index 517d513..9d33529 100644 --- a/DCCACK.cpp +++ b/DCCACK.cpp @@ -27,8 +27,8 @@ #include "DCCWaveform.h" #include "TrackManager.h" -unsigned int DCCACK::minAckPulseDuration = 2000; // micros -unsigned int DCCACK::maxAckPulseDuration = 20000; // micros +unsigned long DCCACK::minAckPulseDuration = 2000; // micros +unsigned long DCCACK::maxAckPulseDuration = 20000; // micros MotorDriver * DCCACK::progDriver=NULL; ackOp const * DCCACK::ackManagerProg; @@ -50,8 +50,8 @@ volatile uint8_t DCCACK::numAckSamples=0; uint8_t DCCACK::trailingEdgeCounter=0; - unsigned int DCCACK::ackPulseDuration; // micros - unsigned long DCCACK::ackPulseStart; // micros +unsigned long DCCACK::ackPulseDuration; // micros +unsigned long DCCACK::ackPulseStart; // micros volatile bool DCCACK::ackDetected; unsigned long DCCACK::ackCheckStart; // millis volatile bool DCCACK::ackPending; @@ -127,7 +127,7 @@ bool DCCACK::checkResets(uint8_t numResets) { void DCCACK::setAckBaseline() { int baseline=progDriver->getCurrentRaw(); ackThreshold= baseline + progDriver->mA2raw(ackLimitmA); - if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %uus and %uus"), + if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %lus and %lus"), baseline,progDriver->raw2mA(baseline), ackThreshold,progDriver->raw2mA(ackThreshold), minAckPulseDuration, maxAckPulseDuration); @@ -146,7 +146,7 @@ void DCCACK::setAckPending() { byte DCCACK::getAck() { if (ackPending) return (2); // still waiting - if (Diag::ACK) DIAG(F("%S after %dmS max=%d/%dmA pulse=%uuS samples=%d gaps=%d"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration, + if (Diag::ACK) DIAG(F("%S after %dmS max=%d/%dmA pulse=%luS samples=%d gaps=%d"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration, ackMaxCurrent,progDriver->raw2mA(ackMaxCurrent), ackPulseDuration, numAckSamples, numAckGaps); if (ackDetected) return (1); // Yes we had an ack return(0); // pending set off but not detected means no ACK. diff --git a/DCCACK.h b/DCCACK.h index fa03387..c50dbbd 100644 --- a/DCCACK.h +++ b/DCCACK.h @@ -79,10 +79,10 @@ class DCCACK { static inline void setAckLimit(int mA) { ackLimitmA = mA; } - static inline void setMinAckPulseDuration(unsigned int i) { + static inline void setMinAckPulseDuration(unsigned long i) { minAckPulseDuration = i; } - static inline void setMaxAckPulseDuration(unsigned int i) { + static inline void setMaxAckPulseDuration(unsigned long i) { maxAckPulseDuration = i; } @@ -126,11 +126,11 @@ class DCCACK { static unsigned long ackCheckStart; // millis static unsigned int ackCheckDuration; // millis - static unsigned int ackPulseDuration; // micros + static unsigned long ackPulseDuration; // micros static unsigned long ackPulseStart; // micros - static unsigned int minAckPulseDuration ; // micros - static unsigned int maxAckPulseDuration ; // micros + static unsigned long minAckPulseDuration ; // micros + static unsigned long maxAckPulseDuration ; // micros static MotorDriver* progDriver; static volatile uint8_t numAckGaps; static volatile uint8_t numAckSamples; diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 431093f..34117eb 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -1073,15 +1073,24 @@ bool DCCEXParser::parseC(Print *stream, int16_t params, int16_t p[]) { #ifndef DISABLE_PROG case "ACK"_hk: // if (params >= 3) { + long duration; if (p[1] == "LIMIT"_hk) { DCCACK::setAckLimit(p[2]); - LCD(1, F("Ack Limit=%dmA"), p[2]); // + LCD(1, F("Ack Limit=%dmA"), p[2]); // } else if (p[1] == "MIN"_hk) { - DCCACK::setMinAckPulseDuration(p[2]); - LCD(0, F("Ack Min=%uus"), p[2]); // + if (params == 4 && p[3] == "MS"_hk) + duration = p[2] * 1000L; + else + duration = p[2]; + DCCACK::setMinAckPulseDuration(duration); + LCD(0, F("Ack Min=%lus"), duration); // } else if (p[1] == "MAX"_hk) { - DCCACK::setMaxAckPulseDuration(p[2]); - LCD(0, F("Ack Max=%uus"), p[2]); // + if (params == 4 && p[3] == "MS"_hk) // + duration = p[2] * 1000L; + else + duration = p[2]; + DCCACK::setMaxAckPulseDuration(duration); + LCD(0, F("Ack Max=%lus"), duration); // } else if (p[1] == "RETRY"_hk) { if (p[2] >255) p[2]=3; LCD(0, F("Ack Retry=%d Sum=%d"), p[2], DCCACK::setAckRetry(p[2])); //