From fdc956576b3478291fe33ad0d072af77f3de5865 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 01:02:49 +0200 Subject: [PATCH 01/18] ESP32 rewrite PWM LEDC to use pin mux --- DCCTimer.h | 4 +++- DCCTimerESP.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++---- MotorDriver.cpp | 6 +++--- MotorDriver.h | 3 ++- TrackManager.cpp | 23 +++++++++++++++++++-- 5 files changed, 79 insertions(+), 11 deletions(-) diff --git a/DCCTimer.h b/DCCTimer.h index 5cf1026..984d6eb 100644 --- a/DCCTimer.h +++ b/DCCTimer.h @@ -66,7 +66,9 @@ class DCCTimer { static void ackRailcomTimer(); static void DCCEXanalogWriteFrequency(uint8_t pin, uint32_t frequency); static void DCCEXanalogWrite(uint8_t pin, int value); - + static void DCCEXledcDetachPin(uint8_t pin); + static void DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin); + static void DCCEXInrushControlOn(uint8_t pin); // Update low ram level. Allow for extra bytes to be specified // by estimation or inspection, that may be used by other // called subroutines. Must be called with interrupts disabled. diff --git a/DCCTimerESP.cpp b/DCCTimerESP.cpp index ae81c74..3e8d49e 100644 --- a/DCCTimerESP.cpp +++ b/DCCTimerESP.cpp @@ -78,6 +78,7 @@ int DCCTimer::freeMemory() { //////////////////////////////////////////////////////////////////////// #ifdef ARDUINO_ARCH_ESP32 +#include "DIAG.h" #include #include #include @@ -154,8 +155,10 @@ void DCCTimer::reset() { void DCCTimer::DCCEXanalogWriteFrequency(uint8_t pin, uint32_t f) { if (f >= 16) DCCTimer::DCCEXanalogWriteFrequencyInternal(pin, f); - else if (f == 7) +/* + else if (f == 7) // not used on ESP32 DCCTimer::DCCEXanalogWriteFrequencyInternal(pin, 62500); +*/ else if (f >= 4) DCCTimer::DCCEXanalogWriteFrequencyInternal(pin, 32000); else if (f >= 3) @@ -188,22 +191,65 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t frequency } } +void DCCTimer::DCCEXledcDetachPin(uint8_t pin) { + DIAG(F("Clear pin %d channel"), pin); + pin_to_channel[pin] = 0; + pinMatrixOutDetach(pin, false, false); +} + + +void DCCTimer::DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin) { + DIAG(F("Pin %d copied to %d channel %d"), frompin, topin, pin_to_channel[frompin]); + pin_to_channel[topin] = pin_to_channel[frompin]; + ledcAttachPin(topin, pin_to_channel[topin]); +} void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) { + // This allocates channels 15, 13, 11, .... + // so each channel gets its own timer. if (pin < SOC_GPIO_PIN_COUNT) { if (pin_to_channel[pin] == 0) { + int search_channel; + int n; if (!cnt_channel) { log_e("No more PWM channels available! All %u already used", LEDC_CHANNELS); return; } - pin_to_channel[pin] = --cnt_channel; - ledcSetup(cnt_channel, 1000, 8); - ledcAttachPin(pin, cnt_channel); + // search for free channels top down + for (search_channel=LEDC_CHANNELS-1; search_channel >=cnt_channel; search_channel -= 2) { + bool chanused = false; + for (n=0; n < SOC_GPIO_PIN_COUNT; n++) { + if (pin_to_channel[n] == search_channel) { // current search_channel used + chanused = true; + break; + } + } + if (chanused) + continue; + if (n == SOC_GPIO_PIN_COUNT) // current search_channel unused + break; + } + if (search_channel >= cnt_channel) { + pin_to_channel[pin] = search_channel; + DIAG(F("Pin %d assigned to search channel %d"), pin, search_channel); + } else { + pin_to_channel[pin] = --cnt_channel; // This sets 15, 13, ... + DIAG(F("Pin %d assigned to new channel %d"), pin, cnt_channel); + --cnt_channel; // Now we are at 14, 12, ... + } + ledcSetup(pin_to_channel[pin], 1000, 8); + ledcAttachPin(pin, pin_to_channel[pin]); } else { + //DIAG(F("Pin %d assigned to old channel %d"), pin, pin_to_channel[pin]); ledcAttachPin(pin, pin_to_channel[pin]); } ledcWrite(pin_to_channel[pin], value); } } +void DCCTimer::DCCEXInrushControlOn(uint8_t pin) { + ledcSetup(0, 62500, 8); + ledcAttachPin(pin, 0); + ledcWrite(0, 207); +} int ADCee::init(uint8_t pin) { pinMode(pin, ANALOG); diff --git a/MotorDriver.cpp b/MotorDriver.cpp index c233c22..afd8e6e 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -411,10 +411,10 @@ void MotorDriver::throttleInrush(bool on) { duty = 255-duty; #if defined(ARDUINO_ARCH_ESP32) if(on) { - DCCTimer::DCCEXanalogWrite(brakePin,duty); - DCCTimer::DCCEXanalogWriteFrequency(brakePin, 7); // 7 means max + DCCTimer::DCCEXInrushControlOn(brakePin); } else { - ledcDetachPin(brakePin); + ledcDetachPin(brakePin); // not DCCTimer::DCCEXledcDetachPin() as we have not + // registered the pin in the pin to channel array } #elif defined(ARDUINO_ARCH_STM32) if(on) { diff --git a/MotorDriver.h b/MotorDriver.h index 4491164..945e4ee 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -193,13 +193,14 @@ class MotorDriver { } }; inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); }; + inline byte getBrakePin() { return brakePin; }; void setDCSignal(byte speedByte, uint8_t frequency=0); void throttleInrush(bool on); inline void detachDCSignal() { #if defined(__arm__) pinMode(brakePin, OUTPUT); #elif defined(ARDUINO_ARCH_ESP32) - ledcDetachPin(brakePin); + DCCTimer::DCCEXledcDetachPin(brakePin); #else setDCSignal(128); #endif diff --git a/TrackManager.cpp b/TrackManager.cpp index 338b11c..21fe44a 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -252,13 +252,32 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr track[trackToSet]->makeProgTrack(false); // only the prog track knows it's type } track[trackToSet]->setMode(mode); - trackDCAddr[trackToSet]=dcAddr; // When a track is switched, we must clear any side effects of its previous // state, otherwise trains run away or just dont move. // This can be done BEFORE the PWM-Timer evaluation (methinks) - if (!(mode & TRACK_MODE_DC)) { + if (mode & TRACK_MODE_DC) { + if (trackDCAddr[trackToSet] != dcAddr) { + // if we change dcAddr, detach first old signal + track[trackToSet]->detachDCSignal(); +#ifdef ARDUINO_ARCH_ESP32 + int trackfound = -1; + FOR_EACH_TRACK(t) { + if ((track[t]->getMode() & TRACK_MODE_DC) && trackDCAddr[t] == dcAddr) { + trackfound = t; + break; + } + } + if (trackfound > -1) { + DCCTimer::DCCEXanalogCopyChannel(track[trackfound]->getBrakePin(), + track[trackToSet]->getBrakePin()); + } +#endif + } + // set future DC Addr; + trackDCAddr[trackToSet]=dcAddr; + } else { // DCC tracks need to have set the PWM to zero or they will not work. track[trackToSet]->detachDCSignal(); track[trackToSet]->setBrake(false); From 6d7d2325da786a53db11612508e31a7e4f0e9f33 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 01:10:10 +0200 Subject: [PATCH 02/18] ESP32 rewrite PWM LEDC inrush duty fix --- DCCTimer.h | 2 +- DCCTimerESP.cpp | 4 ++-- MotorDriver.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DCCTimer.h b/DCCTimer.h index 984d6eb..4ce8590 100644 --- a/DCCTimer.h +++ b/DCCTimer.h @@ -68,7 +68,7 @@ class DCCTimer { static void DCCEXanalogWrite(uint8_t pin, int value); static void DCCEXledcDetachPin(uint8_t pin); static void DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin); - static void DCCEXInrushControlOn(uint8_t pin); + static void DCCEXInrushControlOn(uint8_t pin, int duty); // Update low ram level. Allow for extra bytes to be specified // by estimation or inspection, that may be used by other // called subroutines. Must be called with interrupts disabled. diff --git a/DCCTimerESP.cpp b/DCCTimerESP.cpp index 3e8d49e..b651a49 100644 --- a/DCCTimerESP.cpp +++ b/DCCTimerESP.cpp @@ -245,10 +245,10 @@ void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) { ledcWrite(pin_to_channel[pin], value); } } -void DCCTimer::DCCEXInrushControlOn(uint8_t pin) { +void DCCTimer::DCCEXInrushControlOn(uint8_t pin, int duty) { ledcSetup(0, 62500, 8); ledcAttachPin(pin, 0); - ledcWrite(0, 207); + ledcWrite(0, duty); } int ADCee::init(uint8_t pin) { diff --git a/MotorDriver.cpp b/MotorDriver.cpp index afd8e6e..235f557 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -411,7 +411,7 @@ void MotorDriver::throttleInrush(bool on) { duty = 255-duty; #if defined(ARDUINO_ARCH_ESP32) if(on) { - DCCTimer::DCCEXInrushControlOn(brakePin); + DCCTimer::DCCEXInrushControlOn(brakePin, duty); } else { ledcDetachPin(brakePin); // not DCCTimer::DCCEXledcDetachPin() as we have not // registered the pin in the pin to channel array From 84b90ae75775f8ea22cc523bdbc663f1d508071e Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 01:11:12 +0200 Subject: [PATCH 03/18] Booster mode inrush throttle, too --- MotorDriver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 235f557..47c359e 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -404,7 +404,7 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/) void MotorDriver::throttleInrush(bool on) { if (brakePin == UNUSED_PIN) return; - if ( !(trackMode & (TRACK_MODE_MAIN | TRACK_MODE_PROG | TRACK_MODE_EXT))) + if ( !(trackMode & (TRACK_MODE_MAIN | TRACK_MODE_PROG | TRACK_MODE_EXT | TRACK_MODE_BOOST))) return; byte duty = on ? 207 : 0; // duty of 81% at 62500Hz this gives pauses of 3usec if (invertBrake) From cff407593713f09fdc6d701c3aba742dba49f786 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 01:12:08 +0200 Subject: [PATCH 04/18] version 5.2.43 --- GITHUB_SHA.h | 2 +- version.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 5d6ee02..821e344 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202404012205Z" +#define GITHUB_SHA "devel-202404042311Z" diff --git a/version.h b/version.h index 1f11713..58d0cb6 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,8 @@ #include "StringFormatter.h" -#define VERSION "5.2.42" +#define VERSION "5.2.43" +// 5.2.43 - ESP32 rewrite PWM LEDC to use pin mux // 5.2.42 - ESP32 Bugfix: Uninitialized stack variable // 5.2.41 - Update rotary encoder default address to 0x67 // 5.2.40 - Allow no shield From dc5f5e05b9530a8b950c6382042fd19c2dbea76c Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 14:05:12 +0200 Subject: [PATCH 05/18] ESP32 fix PWM LEDC inverted pin mode --- DCCTimer.h | 8 ++++--- DCCTimerESP.cpp | 58 +++++++++++++++++++++++++++++++++++++++-------- DCCTimerSTM32.cpp | 4 +++- MotorDriver.cpp | 14 ++++++------ MotorDriver.h | 2 +- TrackManager.cpp | 10 +++++--- 6 files changed, 71 insertions(+), 25 deletions(-) diff --git a/DCCTimer.h b/DCCTimer.h index 4ce8590..44c85f2 100644 --- a/DCCTimer.h +++ b/DCCTimer.h @@ -65,10 +65,12 @@ class DCCTimer { static void startRailcomTimer(byte brakePin); static void ackRailcomTimer(); static void DCCEXanalogWriteFrequency(uint8_t pin, uint32_t frequency); - static void DCCEXanalogWrite(uint8_t pin, int value); + static void DCCEXanalogWrite(uint8_t pin, int value, bool invert); static void DCCEXledcDetachPin(uint8_t pin); - static void DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin); - static void DCCEXInrushControlOn(uint8_t pin, int duty); + static void DCCEXanalogCopyChannel(int8_t frompin, int8_t topin); + static void DCCEXInrushControlOn(uint8_t pin, int duty, bool invert); + static void DCCEXledcAttachPin(uint8_t pin, int8_t channel, bool inverted); + // Update low ram level. Allow for extra bytes to be specified // by estimation or inspection, that may be used by other // called subroutines. Must be called with interrupts disabled. diff --git a/DCCTimerESP.cpp b/DCCTimerESP.cpp index b651a49..93711aa 100644 --- a/DCCTimerESP.cpp +++ b/DCCTimerESP.cpp @@ -197,13 +197,48 @@ void DCCTimer::DCCEXledcDetachPin(uint8_t pin) { pinMatrixOutDetach(pin, false, false); } +static byte LEDCToMux[] = { + LEDC_HS_SIG_OUT0_IDX, + LEDC_HS_SIG_OUT1_IDX, + LEDC_HS_SIG_OUT2_IDX, + LEDC_HS_SIG_OUT3_IDX, + LEDC_HS_SIG_OUT4_IDX, + LEDC_HS_SIG_OUT5_IDX, + LEDC_HS_SIG_OUT6_IDX, + LEDC_HS_SIG_OUT7_IDX, + LEDC_LS_SIG_OUT0_IDX, + LEDC_LS_SIG_OUT1_IDX, + LEDC_LS_SIG_OUT2_IDX, + LEDC_LS_SIG_OUT3_IDX, + LEDC_LS_SIG_OUT4_IDX, + LEDC_LS_SIG_OUT5_IDX, + LEDC_LS_SIG_OUT6_IDX, + LEDC_LS_SIG_OUT7_IDX, +}; -void DCCTimer::DCCEXanalogCopyChannel(uint8_t frompin, uint8_t topin) { - DIAG(F("Pin %d copied to %d channel %d"), frompin, topin, pin_to_channel[frompin]); - pin_to_channel[topin] = pin_to_channel[frompin]; - ledcAttachPin(topin, pin_to_channel[topin]); +void DCCTimer::DCCEXledcAttachPin(uint8_t pin, int8_t channel, bool inverted) { + DIAG(F("Attaching pin %d to channel %d %c"), pin, channel, inverted ? 'I' : ' '); + ledcAttachPin(pin, channel); + if (inverted) // we attach again but with inversion + gpio_matrix_out(pin, LEDCToMux[channel], inverted, 0); } -void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) { + +void DCCTimer::DCCEXanalogCopyChannel(int8_t frompin, int8_t topin) { + // arguments are signed depending on inversion of pins + DIAG(F("Pin %d copied to %d"), frompin, topin); + bool inverted = false; + if (frompin<0) + frompin = -frompin; + if (topin<0) { + inverted = true; + topin = -topin; + } + int channel = pin_to_channel[frompin]; // after abs(frompin) + pin_to_channel[topin] = channel; + DCCTimer::DCCEXledcAttachPin(topin, channel, inverted); +} + +void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value, bool invert) { // This allocates channels 15, 13, 11, .... // so each channel gets its own timer. if (pin < SOC_GPIO_PIN_COUNT) { @@ -237,17 +272,20 @@ void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) { --cnt_channel; // Now we are at 14, 12, ... } ledcSetup(pin_to_channel[pin], 1000, 8); - ledcAttachPin(pin, pin_to_channel[pin]); + DCCEXledcAttachPin(pin, pin_to_channel[pin], invert); } else { - //DIAG(F("Pin %d assigned to old channel %d"), pin, pin_to_channel[pin]); - ledcAttachPin(pin, pin_to_channel[pin]); + // This else is only here so we can enable diag + // Pin should be already attached to channel + // DIAG(F("Pin %d assigned to old channel %d"), pin, pin_to_channel[pin]); } ledcWrite(pin_to_channel[pin], value); } } -void DCCTimer::DCCEXInrushControlOn(uint8_t pin, int duty) { + +void DCCTimer::DCCEXInrushControlOn(uint8_t pin, int duty, bool inverted) { + // this uses hardcoded channel 0 ledcSetup(0, 62500, 8); - ledcAttachPin(pin, 0); + DCCEXledcAttachPin(pin, 0, inverted); ledcWrite(0, duty); } diff --git a/DCCTimerSTM32.cpp b/DCCTimerSTM32.cpp index 43c8ece..0c1d5d6 100644 --- a/DCCTimerSTM32.cpp +++ b/DCCTimerSTM32.cpp @@ -333,7 +333,9 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t frequency return; } -void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value) { +void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value, bool invert) { + if (invert) + value = 255-value; // Calculate percentage duty cycle from value given uint32_t duty_cycle = (value * 100 / 256) + 1; if (pin_timer[pin] != NULL) { diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 47c359e..1ab52d8 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -336,8 +336,6 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/) if (tSpeed <= 1) brake = 255; else if (tSpeed >= 127) brake = 0; else brake = 2 * (128-tSpeed); - if (invertBrake) - brake=255-brake; { // new block because of variable f #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_STM32) @@ -351,10 +349,10 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/) #endif //DIAG(F("Brake pin %d freqency %d"), brakePin, f); DCCTimer::DCCEXanalogWriteFrequency(brakePin, f); // set DC PWM frequency - DCCTimer::DCCEXanalogWrite(brakePin,brake); + DCCTimer::DCCEXanalogWrite(brakePin, brake, invertBrake); #else // all AVR here DCCTimer::DCCEXanalogWriteFrequency(brakePin, frequency); // frequency steps - analogWrite(brakePin,brake); + analogWrite(brakePin, invertBrake ? 255-brake : brake); #endif } @@ -407,16 +405,16 @@ void MotorDriver::throttleInrush(bool on) { if ( !(trackMode & (TRACK_MODE_MAIN | TRACK_MODE_PROG | TRACK_MODE_EXT | TRACK_MODE_BOOST))) return; byte duty = on ? 207 : 0; // duty of 81% at 62500Hz this gives pauses of 3usec - if (invertBrake) - duty = 255-duty; #if defined(ARDUINO_ARCH_ESP32) if(on) { - DCCTimer::DCCEXInrushControlOn(brakePin, duty); + DCCTimer::DCCEXInrushControlOn(brakePin, duty, invertBrake); } else { ledcDetachPin(brakePin); // not DCCTimer::DCCEXledcDetachPin() as we have not // registered the pin in the pin to channel array } #elif defined(ARDUINO_ARCH_STM32) + if (invertBrake) + duty = 255-duty; if(on) { DCCTimer::DCCEXanalogWriteFrequency(brakePin, 7); // 7 means max DCCTimer::DCCEXanalogWrite(brakePin,duty); @@ -424,6 +422,8 @@ void MotorDriver::throttleInrush(bool on) { pinMode(brakePin, OUTPUT); } #else // all AVR here + if (invertBrake) + duty = 255-duty; if(on){ DCCTimer::DCCEXanalogWriteFrequency(brakePin, 7); // 7 means max } diff --git a/MotorDriver.h b/MotorDriver.h index 945e4ee..a6ed1f6 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -193,7 +193,7 @@ class MotorDriver { } }; inline pinpair getSignalPin() { return pinpair(signalPin,signalPin2); }; - inline byte getBrakePin() { return brakePin; }; + inline int8_t getBrakePinSigned() { return invertBrake ? -brakePin : brakePin; }; void setDCSignal(byte speedByte, uint8_t frequency=0); void throttleInrush(bool on); inline void detachDCSignal() { diff --git a/TrackManager.cpp b/TrackManager.cpp index 21fe44a..06b6a18 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -264,14 +264,18 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr #ifdef ARDUINO_ARCH_ESP32 int trackfound = -1; FOR_EACH_TRACK(t) { - if ((track[t]->getMode() & TRACK_MODE_DC) && trackDCAddr[t] == dcAddr) { + //DIAG(F("Checking track %c mode %x dcAddr %d"), 'A'+t, track[t]->getMode(), trackDCAddr[t]); + if (t != trackToSet // not our track + && (track[t]->getMode() & TRACK_MODE_DC) // right mode + && trackDCAddr[t] == dcAddr) { // right addr + //DIAG(F("Found track %c"), 'A'+t); trackfound = t; break; } } if (trackfound > -1) { - DCCTimer::DCCEXanalogCopyChannel(track[trackfound]->getBrakePin(), - track[trackToSet]->getBrakePin()); + DCCTimer::DCCEXanalogCopyChannel(track[trackfound]->getBrakePinSigned(), + track[trackToSet]->getBrakePinSigned()); } #endif } From d367f5dc8174230057e880f93016581e4ecdef7a Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 14:06:36 +0200 Subject: [PATCH 06/18] version 5.2.44 --- GITHUB_SHA.h | 2 +- version.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 821e344..0bcb861 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202404042311Z" +#define GITHUB_SHA "devel-202404051206Z" diff --git a/version.h b/version.h index 58d0cb6..6f25b47 100644 --- a/version.h +++ b/version.h @@ -3,8 +3,9 @@ #include "StringFormatter.h" -#define VERSION "5.2.43" -// 5.2.43 - ESP32 rewrite PWM LEDC to use pin mux +#define VERSION "5.2.44" +// 5.2.44 - ESP32 fix PWM LEDC inverted pin mode +// ESP32 rewrite PWM LEDC to use pin mux // 5.2.42 - ESP32 Bugfix: Uninitialized stack variable // 5.2.41 - Update rotary encoder default address to 0x67 // 5.2.40 - Allow no shield From 7b77d4ce1e9d679cf703da37ac91221a9f57e54b Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 14:08:39 +0200 Subject: [PATCH 07/18] STM32 fix inverted pin mode --- MotorDriver.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 1ab52d8..8662ca1 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -413,11 +413,9 @@ void MotorDriver::throttleInrush(bool on) { // registered the pin in the pin to channel array } #elif defined(ARDUINO_ARCH_STM32) - if (invertBrake) - duty = 255-duty; if(on) { DCCTimer::DCCEXanalogWriteFrequency(brakePin, 7); // 7 means max - DCCTimer::DCCEXanalogWrite(brakePin,duty); + DCCTimer::DCCEXanalogWrite(brakePin,duty,invertBrake); } else { pinMode(brakePin, OUTPUT); } From f581d56bdce137c532607ee5d2368a24de88b4b9 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 20:30:26 +0200 Subject: [PATCH 08/18] ESP32 set frequency after DC speed --- MotorDriver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MotorDriver.cpp b/MotorDriver.cpp index 8662ca1..66d1b71 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -347,9 +347,9 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/) } } #endif - //DIAG(F("Brake pin %d freqency %d"), brakePin, f); - DCCTimer::DCCEXanalogWriteFrequency(brakePin, f); // set DC PWM frequency + //DIAG(F("Brake pin %d value %d freqency %d"), brakePin, brake, f); DCCTimer::DCCEXanalogWrite(brakePin, brake, invertBrake); + DCCTimer::DCCEXanalogWriteFrequency(brakePin, f); // set DC PWM frequency #else // all AVR here DCCTimer::DCCEXanalogWriteFrequency(brakePin, frequency); // frequency steps analogWrite(brakePin, invertBrake ? 255-brake : brake); From e4a3aa9f1e42afc248e75c88aba428d2c599c065 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 5 Apr 2024 20:31:05 +0200 Subject: [PATCH 09/18] tag --- GITHUB_SHA.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 0bcb861..5588243 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202404051206Z" +#define GITHUB_SHA "devel-202404051830Z" From 1a307eea3debf251107a78dd5ec7e0847fe850fb Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 6 Apr 2024 13:19:56 +0100 Subject: [PATCH 10/18] Extended consist and --- DCC.cpp | 43 ++++++++++++++++++++++++++++++++++++++++--- DCCACK.cpp | 17 +++++++++++++++++ DCCACK.h | 2 ++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index a8bc953..f2ab8c3 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -325,8 +325,8 @@ preamble -0- 1 0 A7 A6 A5 A4 A3 A2 -0- 0 ^A10 ^A9 ^A8 0 A1 A0 1 -0- .... Thus in byte packet form the format is 10AAAAAA, 0AAA0AA1, 000XXXXX -Die Adresse für den ersten erweiterten Zubehördecoder ist wie bei den einfachen -Zubehördecodern die Adresse 4 = 1000-0001 0111-0001 . Diese Adresse wird in +Die Adresse f�r den ersten erweiterten Zubeh�rdecoder ist wie bei den einfachen +Zubeh�rdecodern die Adresse 4 = 1000-0001 0111-0001 . Diese Adresse wird in Anwenderdialogen als Adresse 1 dargestellt. This means that the first address shown to the user as "1" is mapped @@ -500,6 +500,36 @@ const ackOp FLASH READ_CV_PROG[] = { const ackOp FLASH LOCO_ID_PROG[] = { BASELINE, + // first check cv20 for extended addressing + SETCV, (ackOp)20, // CV 19 is extended + SETBYTE, (ackOp)0, + VB, WACK, ITSKIP, // skip past extended section if cv20 is zero + // read cv20 and 19 and merge + STARTMERGE, // Setup to read cv 20 + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + VB, WACK, NAKSKIP, // bad read of cv20, assume its 0 + STASHLOCOID, // keep cv 20 until we have cv19 as well. + SETCV, (ackOp)19, + STARTMERGE, // Setup to read cv 19 + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + V0, WACK, MERGE, + VB, WACK, NAKFAIL, // cant recover if cv 19 unreadable + COMBINE1920, // Combile byte with stash and callback +// end of advanced 20,19 check + SKIPTARGET, SETCV, (ackOp)19, // CV 19 is consist setting SETBYTE, (ackOp)0, VB, WACK, ITSKIP, // ignore consist if cv19 is zero (no consist) @@ -566,6 +596,10 @@ const ackOp FLASH LOCO_ID_PROG[] = { const ackOp FLASH SHORT_LOCO_ID_PROG[] = { BASELINE, + // Clear consist CV 19,20 + SETCV,(ackOp)20, + SETBYTE, (ackOp)0, + WB,WACK, // ignore dedcoder without cv20 support SETCV,(ackOp)19, SETBYTE, (ackOp)0, WB,WACK, // ignore dedcoder without cv19 support @@ -583,7 +617,10 @@ const ackOp FLASH SHORT_LOCO_ID_PROG[] = { const ackOp FLASH LONG_LOCO_ID_PROG[] = { BASELINE, - // Clear consist CV 19 + // Clear consist CV 19,20 + SETCV,(ackOp)20, + SETBYTE, (ackOp)0, + WB,WACK, // ignore dedcoder without cv20 support SETCV,(ackOp)19, SETBYTE, (ackOp)0, WB,WACK, // ignore decoder without cv19 support diff --git a/DCCACK.cpp b/DCCACK.cpp index 8a074b4..517d513 100644 --- a/DCCACK.cpp +++ b/DCCACK.cpp @@ -314,6 +314,14 @@ void DCCACK::loop() { callback( LONG_ADDR_MARKER | ( ackManagerByte + ((ackManagerStash - 192) << 8))); return; + case COMBINE1920: + // ackManagerStash is cv20, ackManagerByte is CV 19 + // This will not be called if cv20==0 + ackManagerByte &= 0x7F; // ignore direction marker + ackManagerByte %=100; // take last 2 decimal digits + callback( ackManagerStash*100+ackManagerByte); + return; + case ITSKIP: if (!ackReceived) break; // SKIP opcodes until SKIPTARGET found @@ -322,6 +330,15 @@ void DCCACK::loop() { opcode=GETFLASH(ackManagerProg); } break; + + case NAKSKIP: + if (ackReceived) break; + // SKIP opcodes until SKIPTARGET found + while (opcode!=SKIPTARGET) { + ackManagerProg++; + opcode=GETFLASH(ackManagerProg); + } + break; case SKIPTARGET: break; default: diff --git a/DCCACK.h b/DCCACK.h index 7d39319..fa03387 100644 --- a/DCCACK.h +++ b/DCCACK.h @@ -56,6 +56,8 @@ enum ackOp : byte STASHLOCOID, // keeps current byte value for later COMBINELOCOID, // combines current value with stashed value and returns it ITSKIP, // skip to SKIPTARGET if ack true + NAKSKIP, // skip to SKIPTARGET if ack false + COMBINE1920, // combine cvs 19 and 20 and callback SKIPTARGET = 0xFF // jump to target }; From 38a9585a412a9ae1b492a031b2d785e3eab4e66f Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 6 Apr 2024 19:46:23 +0200 Subject: [PATCH 11/18] ESP32 Trackmanager reset cab number to 0 when track is not DC --- TrackManager.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/TrackManager.cpp b/TrackManager.cpp index 06b6a18..d66b999 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -38,8 +38,8 @@ if (track[t]->getMode()==findmode) \ track[t]->function; -MotorDriver * TrackManager::track[MAX_TRACKS]; -int16_t TrackManager::trackDCAddr[MAX_TRACKS]; +MotorDriver * TrackManager::track[MAX_TRACKS] = { NULL }; +int16_t TrackManager::trackDCAddr[MAX_TRACKS] = { 0 }; int8_t TrackManager::lastTrack=-1; bool TrackManager::progTrackSyncMain=false; @@ -251,7 +251,6 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr } else { track[trackToSet]->makeProgTrack(false); // only the prog track knows it's type } - track[trackToSet]->setMode(mode); // When a track is switched, we must clear any side effects of its previous // state, otherwise trains run away or just dont move. @@ -259,8 +258,13 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr // This can be done BEFORE the PWM-Timer evaluation (methinks) if (mode & TRACK_MODE_DC) { if (trackDCAddr[trackToSet] != dcAddr) { - // if we change dcAddr, detach first old signal - track[trackToSet]->detachDCSignal(); + // new or changed DC Addr, run the new setup + if (trackDCAddr[trackToSet] != 0) { + // if we change dcAddr and not only + // change from another mode, + // first detach old DC signal + track[trackToSet]->detachDCSignal(); + } #ifdef ARDUINO_ARCH_ESP32 int trackfound = -1; FOR_EACH_TRACK(t) { @@ -285,7 +289,9 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr // DCC tracks need to have set the PWM to zero or they will not work. track[trackToSet]->detachDCSignal(); track[trackToSet]->setBrake(false); + trackDCAddr[trackToSet]=0; // clear that an addr is set for DC as this is not a DC track } + track[trackToSet]->setMode(mode); // BOOST: // Leave it as is From 6b713bf57c95565879fb5cbe2552ffa71d9b8d00 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 6 Apr 2024 19:48:02 +0200 Subject: [PATCH 12/18] version 5.2.45 --- GITHUB_SHA.h | 2 +- version.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 5588243..a9ab348 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202404051830Z" +#define GITHUB_SHA "devel-202404061747Z" diff --git a/version.h b/version.h index 6f25b47..2af0a55 100644 --- a/version.h +++ b/version.h @@ -3,8 +3,9 @@ #include "StringFormatter.h" -#define VERSION "5.2.44" -// 5.2.44 - ESP32 fix PWM LEDC inverted pin mode +#define VERSION "5.2.45" +// 5.2.45 - ESP32 Trackmanager reset cab number to 0 when track is not DC +// ESP32 fix PWM LEDC inverted pin mode // ESP32 rewrite PWM LEDC to use pin mux // 5.2.42 - ESP32 Bugfix: Uninitialized stack variable // 5.2.41 - Update rotary encoder default address to 0x67 From f41f61dd5fc1adb8e0445f8fbfb4c3f8011d089a Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 6 Apr 2024 23:41:25 +0100 Subject: [PATCH 13/18] 10239) { //0x27FF according to standard + callback(-1); + return; + } + byte cv20; + byte cv19; + + if (id<=HIGHEST_SHORT_ADDR) { + cv19=id; + cv20=0; + } + else { + cv20=id/100; + cv19=id%100; + } + if (reverse) cv19|=0x80; + DCCACK::Setup((cv20<<8)|cv19, CONSIST_ID_PROG, callback); +} + void DCC::forgetLoco(int cab) { // removes any speed reminders for this loco setThrottle2(cab,1); // ESTOP this loco if still on track int reg=lookupSpeedTable(cab, false); diff --git a/DCC.h b/DCC.h index 4503227..4bc222c 100644 --- a/DCC.h +++ b/DCC.h @@ -85,7 +85,7 @@ public: static void getLocoId(ACK_CALLBACK callback); static void setLocoId(int id,ACK_CALLBACK callback); - + static void setConsistId(int id,bool reverse,ACK_CALLBACK callback); // Enhanced API functions static void forgetLoco(int cab); // removes any speed reminders for this loco static void forgetAllLocos(); // removes all speed reminders diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index fa4c9f8..6e41473 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -458,6 +458,9 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) DCC::setLocoId(p[0],callback_Wloco); else if (params == 4) // WRITE CV ON PROG DCC::writeCVByte(p[0], p[1], callback_W4); + else if ((params==2 | params==3 ) && p[0]=="CONSIST"_hk ) { + DCC::setConsistId(p[1],p[2]=="REVERSE"_hk,callback_Wconsist); + } else if (params == 2) // WRITE CV ON PROG DCC::writeCVByte(p[0], p[1], callback_W); else @@ -1347,3 +1350,11 @@ void DCCEXParser::callback_Wloco(int16_t result) StringFormatter::send(getAsyncReplyStream(), F("\n"), result); commitAsyncReplyStream(); } + +void DCCEXParser::callback_Wconsist(int16_t result) +{ + if (result==1) result=stashP[1]; // pick up original requested id from command + StringFormatter::send(getAsyncReplyStream(), F("\n"), + result, stashP[2]=="REVERSE"_hk ? F(" REVERSE") : F("")); + commitAsyncReplyStream(); +} diff --git a/DCCEXParser.h b/DCCEXParser.h index 3c3382c..d3b7851 100644 --- a/DCCEXParser.h +++ b/DCCEXParser.h @@ -71,6 +71,7 @@ struct DCCEXParser static void callback_R(int16_t result); static void callback_Rloco(int16_t result); static void callback_Wloco(int16_t result); + static void callback_Wconsist(int16_t result); static void callback_Vbit(int16_t result); static void callback_Vbyte(int16_t result); static FILTER_CALLBACK filterCallback; From 182479c07b4d0bc00ff4bbe2a1077284e3f32216 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Sat, 6 Apr 2024 23:49:26 +0100 Subject: [PATCH 14/18] Consist version. --- DCC.cpp | 2 +- DCCEXParser.cpp | 2 +- version.h | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index 2ed75f1..0aa623f 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -703,7 +703,7 @@ void DCC::setLocoId(int id,ACK_CALLBACK callback) { } void DCC::setConsistId(int id,bool reverse,ACK_CALLBACK callback) { - if (id<1 || id>10239) { //0x27FF according to standard + if (id<0 || id>10239) { //0x27FF according to standard callback(-1); return; } diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index 6e41473..a8180ec 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -458,7 +458,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) DCC::setLocoId(p[0],callback_Wloco); else if (params == 4) // WRITE CV ON PROG DCC::writeCVByte(p[0], p[1], callback_W4); - else if ((params==2 | params==3 ) && p[0]=="CONSIST"_hk ) { + else if ((params==2 || params==3 ) && p[0]=="CONSIST"_hk ) { DCC::setConsistId(p[1],p[2]=="REVERSE"_hk,callback_Wconsist); } else if (params == 2) // WRITE CV ON PROG diff --git a/version.h b/version.h index 2af0a55..a772201 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,9 @@ #include "StringFormatter.h" -#define VERSION "5.2.45" +#define VERSION "5.2.46" +// 5.2.46 - Support for extended consist CV20 in and +// - New cmd to handle long/short consist ids // 5.2.45 - ESP32 Trackmanager reset cab number to 0 when track is not DC // ESP32 fix PWM LEDC inverted pin mode // ESP32 rewrite PWM LEDC to use pin mux From 263c3d01e3fc841a0623a27c98d3b8615159c04d Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sun, 7 Apr 2024 09:26:32 +0200 Subject: [PATCH 15/18] DISABLE_DIAG by default for Uno and Nano --- config.example.h | 13 +++++++++++++ defines.h | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/config.example.h b/config.example.h index a2e08b2..3fc86c3 100644 --- a/config.example.h +++ b/config.example.h @@ -211,6 +211,19 @@ The configuration file for DCC-EX Command Station // #define DISABLE_VDPY // #define ENABLE_VDPY +///////////////////////////////////////////////////////////////////////////////////// +// DISABLE / ENABLE DIAG +// +// To diagose different errors, you can turn on differnet messages. This costs +// program memory which we do not have enough on the Uno and Nano, so it is +// by default DISABLED on those. If you think you can fit it (for example +// having disabled some of the features above) you can enable it with +// ENABLE_DIAG. You can even disable it on all other CPUs with +// DISABLE_DIAG +// +// #define DISABLE_DIAG +// #define ENABLE_DIAG + ///////////////////////////////////////////////////////////////////////////////////// // REDEFINE WHERE SHORT/LONG ADDR break is. According to NMRA the last short address // is 127 and the first long address is 128. There are manufacturers which have diff --git a/defines.h b/defines.h index 14dd1c5..2c3ee55 100644 --- a/defines.h +++ b/defines.h @@ -220,9 +220,15 @@ // #if defined(ARDUINO_AVR_NANO) || defined(ARDUINO_AVR_UNO) #define IO_NO_HAL // HAL too big whatever you disable otherwise + #ifndef ENABLE_VDPY #define DISABLE_VDPY #endif + +#ifndef ENABLE_DIAG +#define DISABLE_DIAG +#endif + #endif #if __has_include ( "myAutomation.h") From 5ea6feb11aac6854a903d7fa8cd0ecc3e1ebb330 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 9 Apr 2024 20:45:28 +0100 Subject: [PATCH 16/18] Squashed commit of the following: commit 8987d622e60fb27174203ce47b49462a01ecb61c Author: Asbelos Date: Tue Apr 9 20:44:47 2024 +0100 doc note commit 8f0a5c1ec0fde18dbb262311a1ef5ef79d571807 Author: Asbelos Date: Thu Apr 4 09:45:58 2024 +0100 Exrail notes commit 94083b9ab8a2322c39b7087c522730569194b732 Merge: 72ef199 02bf50b Author: Asbelos Date: Thu Apr 4 09:08:26 2024 +0100 Merge branch 'devel' into devel_chris commit 72ef199315d1c7717331864abb11730890fd3162 Author: Asbelos Date: Thu Apr 4 09:06:50 2024 +0100 TOGGLE_TURNOUT commit e69b777a2f62104dd8b74ba688b950fa92919d54 Author: Asbelos Date: Wed Apr 3 15:17:40 2024 +0100 BLINK command commit c7ed47400d5d89c0b8425ec12b1828e710fb23ec Author: Asbelos Date: Tue Apr 2 10:12:45 2024 +0100 FTOGGLE,XFTOGGLE commit 7a93cf7be856afd30f6976a483b1db4bfc4073a1 Author: Asbelos Date: Fri Mar 29 13:21:35 2024 +0000 EXRAIL STEALTH_GLOBAL --- DCCEXParser.cpp | 1 + EXRAIL2.cpp | 79 ++++++++++++++++++++++--- EXRAIL2.h | 18 +++++- EXRAIL2MacroReset.h | 11 ++++ EXRAIL2Parser.cpp | 21 +++++-- EXRAILMacros.h | 13 ++++ Release_Notes/EXRAIL additions.md | 38 ++++++++++++ Release_Notes/Exrail mods.txt | 98 +++++++++++++++++++++++++++++++ 8 files changed, 262 insertions(+), 17 deletions(-) create mode 100644 Release_Notes/EXRAIL additions.md create mode 100644 Release_Notes/Exrail mods.txt diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index a8180ec..b9ac3a9 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -800,6 +800,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream) break; #endif + case '/': // implemented in EXRAIL parser case 'L': // LCC interface implemented in EXRAIL parser break; // Will if not intercepted by EXRAIL diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index c9c6716..ef4387c 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -373,7 +373,7 @@ RMFT2::RMFT2(int progCtr) { speedo=0; forward=true; invert=false; - timeoutFlag=false; + blinkState=not_blink_task; stackDepth=0; onEventStartPosition=-1; // Not handling an ONxxx @@ -491,6 +491,23 @@ void RMFT2::loop() { void RMFT2::loop2() { if (delayTime!=0 && millis()-delayStart < delayTime) return; + // special stand alone blink task + if (compileFeatures & FEATURE_BLINK) { + if (blinkState==blink_low) { + IODevice::write(blinkPin,HIGH); + blinkState=blink_high; + delayMe(getOperand(1)); + return; + } + if (blinkState==blink_high) { + IODevice::write(blinkPin,LOW); + blinkState=blink_low; + delayMe(getOperand(2)); + return; + } + } + + // Normal progstep following tasks continue here. byte opcode = GET_OPCODE; int16_t operand = getOperand(0); @@ -511,6 +528,10 @@ void RMFT2::loop2() { Turnout::setClosed(operand, true); break; + case OPCODE_TOGGLE_TURNOUT: + Turnout::setClosed(operand, Turnout::isThrown(operand)); + break; + #ifndef IO_NO_HAL case OPCODE_ROTATE: uint8_t activity; @@ -560,39 +581,39 @@ void RMFT2::loop2() { break; case OPCODE_AT: - timeoutFlag=false; + blinkState=not_blink_task; if (readSensor(operand)) break; delayMe(50); return; case OPCODE_ATGTE: // wait for analog sensor>= value - timeoutFlag=false; + blinkState=not_blink_task; if (IODevice::readAnalogue(operand) >= (int)(getOperand(1))) break; delayMe(50); return; case OPCODE_ATLT: // wait for analog sensor < value - timeoutFlag=false; + blinkState=not_blink_task; if (IODevice::readAnalogue(operand) < (int)(getOperand(1))) break; delayMe(50); return; case OPCODE_ATTIMEOUT1: // ATTIMEOUT(vpin,timeout) part 1 timeoutStart=millis(); - timeoutFlag=false; + blinkState=not_blink_task; break; case OPCODE_ATTIMEOUT2: if (readSensor(operand)) break; // success without timeout if (millis()-timeoutStart > 100*getOperand(1)) { - timeoutFlag=true; + blinkState=at_timeout; break; // and drop through } delayMe(50); return; case OPCODE_IFTIMEOUT: // do next operand if timeout flag set - skipIf=!timeoutFlag; + skipIf=blinkState!=at_timeout; break; case OPCODE_AFTER: // waits for sensor to hit and then remain off for 0.5 seconds. (must come after an AT operation) @@ -624,13 +645,25 @@ void RMFT2::loop2() { break; case OPCODE_SET: + killBlinkOnVpin(operand); IODevice::write(operand,true); break; case OPCODE_RESET: + killBlinkOnVpin(operand); IODevice::write(operand,false); break; - + + case OPCODE_BLINK: + // Start a new task to blink this vpin + killBlinkOnVpin(operand); + { + auto newtask=new RMFT2(progCounter); + newtask->blinkPin=operand; + newtask->blinkState=blink_low; // will go high on first call + } + break; + case OPCODE_PAUSE: DCC::setThrottle(0,1,true); // pause all locos on the track pausingTask=this; @@ -815,6 +848,10 @@ void RMFT2::loop2() { case OPCODE_FOFF: if (loco) DCC::setFn(loco,operand,false); break; + + case OPCODE_FTOGGLE: + if (loco) DCC::changeFn(loco,operand); + break; case OPCODE_DRIVE: { @@ -830,6 +867,10 @@ void RMFT2::loop2() { case OPCODE_XFOFF: DCC::setFn(operand,getOperand(1),false); break; + + case OPCODE_XFTOGGLE: + DCC::changeFn(operand,getOperand(1)); + break; case OPCODE_DCCACTIVATE: { // operand is address<<3 | subaddr<<1 | active @@ -1167,16 +1208,19 @@ int16_t RMFT2::getSignalSlot(int16_t id) { if (redpin) { bool redval=(rag==SIGNAL_RED || rag==SIMAMBER); if (!aHigh) redval=!redval; + killBlinkOnVpin(redpin); IODevice::write(redpin,redval); } if (amberpin) { bool amberval=(rag==SIGNAL_AMBER); if (!aHigh) amberval=!amberval; + killBlinkOnVpin(amberpin); IODevice::write(amberpin,amberval); } if (greenpin) { bool greenval=(rag==SIGNAL_GREEN || rag==SIMAMBER); if (!aHigh) greenval=!greenval; + killBlinkOnVpin(greenpin); IODevice::write(greenpin,greenval); } } @@ -1264,6 +1308,25 @@ void RMFT2::powerEvent(int16_t track, bool overload) { } } +// This function is used when setting pins so that a SET or RESET +// will cause any blink task on that pin to terminate. +// It will be compiled out of existence if no BLINK feature is used. +void RMFT2::killBlinkOnVpin(VPIN pin) { + if (!(compileFeatures & FEATURE_BLINK)) return; + + RMFT2 * task=loopTask; + while(task) { + if ( + (task->blinkState==blink_high || task->blinkState==blink_low) + && task->blinkPin==pin) { + task->kill(); + return; + } + task=task->next; + if (task==loopTask) return; + } +} + void RMFT2::startNonRecursiveTask(const FSH* reason, int16_t id,int pc) { // Check we dont already have a task running this handler RMFT2 * task=loopTask; diff --git a/EXRAIL2.h b/EXRAIL2.h index f4cf320..7075f26 100644 --- a/EXRAIL2.h +++ b/EXRAIL2.h @@ -33,7 +33,7 @@ // or more OPCODE_PAD instructions with the subsequent parameters. This wastes a byte but makes // searching easier as a parameter can never be confused with an opcode. // -enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, +enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT, OPCODE_FWD,OPCODE_REV,OPCODE_SPEED,OPCODE_INVERT_DIRECTION, OPCODE_RESERVE,OPCODE_FREE, OPCODE_AT,OPCODE_AFTER, @@ -41,9 +41,11 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE, OPCODE_ATGTE,OPCODE_ATLT, OPCODE_ATTIMEOUT1,OPCODE_ATTIMEOUT2, OPCODE_LATCH,OPCODE_UNLATCH,OPCODE_SET,OPCODE_RESET, + OPCODE_BLINK, OPCODE_ENDIF,OPCODE_ELSE, OPCODE_DELAY,OPCODE_DELAYMINS,OPCODE_DELAYMS,OPCODE_RANDWAIT, OPCODE_FON,OPCODE_FOFF,OPCODE_XFON,OPCODE_XFOFF, + OPCODE_FTOGGLE,OPCODE_XFTOGGLE, OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER,OPCODE_DRIVE, OPCODE_SERVO,OPCODE_SIGNAL,OPCODE_TURNOUT,OPCODE_WAITFOR, OPCODE_PAD,OPCODE_FOLLOW,OPCODE_CALL,OPCODE_RETURN, @@ -98,12 +100,21 @@ enum thrunger: byte { thrunge_lcd, // Must be last!! }; + +enum BlinkState: byte { + not_blink_task, + blink_low, // blink task running with pin LOW + blink_high, // blink task running with pin high + at_timeout // ATTIMEOUT timed out flag + }; + // Flag bits for compile time features. static const byte FEATURE_SIGNAL= 0x80; static const byte FEATURE_LCC = 0x40; static const byte FEATURE_ROSTER= 0x20; static const byte FEATURE_ROUTESTATE= 0x10; static const byte FEATURE_STASH = 0x08; + static const byte FEATURE_BLINK = 0x04; // Flag bits for status of hardware and TPL @@ -192,6 +203,7 @@ private: static LookList* LookListLoader(OPCODE op1, OPCODE op2=OPCODE_ENDEXRAIL,OPCODE op3=OPCODE_ENDEXRAIL); static uint16_t getOperand(int progCounter,byte n); + static void killBlinkOnVpin(VPIN pin); static RMFT2 * loopTask; static RMFT2 * pausingTask; void delayMe(long millisecs); @@ -244,10 +256,10 @@ private: union { unsigned long waitAfter; // Used by OPCODE_AFTER unsigned long timeoutStart; // Used by OPCODE_ATTIMEOUT + VPIN blinkPin; // Used by blink tasks }; - bool timeoutFlag; byte taskId; - + BlinkState blinkState; // includes AT_TIMEOUT flag. uint16_t loco; bool forward; bool invert; diff --git a/EXRAIL2MacroReset.h b/EXRAIL2MacroReset.h index e94c657..ce242ea 100644 --- a/EXRAIL2MacroReset.h +++ b/EXRAIL2MacroReset.h @@ -38,6 +38,7 @@ #undef ATTIMEOUT #undef AUTOMATION #undef AUTOSTART +#undef BLINK #undef BROADCAST #undef CALL #undef CLEAR_STASH @@ -66,6 +67,7 @@ #undef FOLLOW #undef FON #undef FORGET +#undef FTOGGLE #undef FREE #undef FWD #undef GREEN @@ -164,8 +166,10 @@ #undef START #undef STASH #undef STEALTH +#undef STEALTH_GLOBAL #undef STOP #undef THROW +#undef TOGGLE_TURNOUT #undef TT_ADDPOSITION #undef TURNOUT #undef TURNOUTL @@ -180,6 +184,7 @@ #undef WITHROTTLE #undef XFOFF #undef XFON +#undef XFTOGGLE #ifndef RMFT2_UNDEF_ONLY #define ACTIVATE(addr,subaddr) @@ -196,6 +201,7 @@ #define ATTIMEOUT(sensor_id,timeout_ms) #define AUTOMATION(id,description) #define AUTOSTART +#define BLINK(vpin,onDuty,offDuty) #define BROADCAST(msg) #define CALL(route) #define CLEAR_STASH(id) @@ -225,6 +231,7 @@ #define FON(func) #define FORGET #define FREE(blockid) +#define FTOGGLE(func) #define FWD(speed) #define GREEN(signal_id) #define HAL(haltype,params...) @@ -322,8 +329,10 @@ #define START(route) #define STASH(id) #define STEALTH(code...) +#define STEALTH_GLOBAL(code...) #define STOP #define THROW(id) +#define TOGGLE_TURNOUT(id) #define TT_ADDPOSITION(turntable_id,position,value,angle,description...) #define TURNOUT(id,addr,subaddr,description...) #define TURNOUTL(id,addr,description...) @@ -338,4 +347,6 @@ #define WITHROTTLE(msg) #define XFOFF(cab,func) #define XFON(cab,func) +#define XFTOGGLE(cab,func) + #endif diff --git a/EXRAIL2Parser.cpp b/EXRAIL2Parser.cpp index 7969750..95375bb 100644 --- a/EXRAIL2Parser.cpp +++ b/EXRAIL2Parser.cpp @@ -36,7 +36,7 @@ void RMFT2::ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]) { (void)stream; // avoid compiler warning if we don't access this parameter - bool reject=false; + switch(opcode) { case 'D': @@ -47,8 +47,7 @@ void RMFT2::ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16 break; case '/': // New EXRAIL command - reject=!parseSlash(stream,paramCount,p); - opcode=0; + if (parseSlash(stream,paramCount,p)) opcode=0; break; case 'A': // @@ -106,9 +105,11 @@ void RMFT2::ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16 } if (paramCount==1) { // LCC event arrived from adapter int16_t eventid=p[0]; - reject=eventid<0 || eventid>=countLCCLookup; - if (!reject) startNonRecursiveTask(F("LCC"),eventid,onLCCLookup[eventid]); - opcode=0; + bool reject = eventid<0 || eventid>=countLCCLookup; + if (!reject) { + startNonRecursiveTask(F("LCC"),eventid,onLCCLookup[eventid]); + opcode=0; + } } break; @@ -182,12 +183,20 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) { StringFormatter::send(stream, F("<* EXRAIL STATUS")); RMFT2 * task=loopTask; while(task) { + if ((compileFeatures & FEATURE_BLINK) + && (task->blinkState==blink_high || task->blinkState==blink_low)) { + StringFormatter::send(stream,F("\nID=%d,PC=%d,BLINK=%d"), + (int)(task->taskId),task->progCounter,task->blinkPin + ); + } + else { StringFormatter::send(stream,F("\nID=%d,PC=%d,LOCO=%d%c,SPEED=%d%c"), (int)(task->taskId),task->progCounter,task->loco, task->invert?'I':' ', task->speedo, task->forward?'F':'R' ); + } task=task->next; if (task==loopTask) break; } diff --git a/EXRAILMacros.h b/EXRAILMacros.h index 5588811..7db52dc 100644 --- a/EXRAILMacros.h +++ b/EXRAILMacros.h @@ -145,6 +145,12 @@ static_assert(!hasdup(compileTimeSequenceList[0],1),"Duplicate SEQUENCE/ROUTE/AU #include "myAutomation.h" +// Pass 1g Implants STEALTH_GLOBAL in correct place +#include "EXRAIL2MacroReset.h" +#undef STEALTH_GLOBAL +#define STEALTH_GLOBAL(code...) code +#include "myAutomation.h" + // Pass 1h Implements HAL macro by creating exrailHalSetup function // Also allows creating EXTurntable object #include "EXRAIL2MacroReset.h" @@ -202,6 +208,8 @@ bool exrailHalSetup() { #define PICKUP_STASH(id) | FEATURE_STASH #undef STASH #define STASH(id) | FEATURE_STASH +#undef BLINK +#define BLINK(vpin,onDuty,offDuty) | FEATURE_BLINK const byte RMFT2::compileFeatures = 0 #include "myAutomation.h" @@ -451,6 +459,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; #define ATTIMEOUT(sensor_id,timeout) OPCODE_ATTIMEOUT1,0,0,OPCODE_ATTIMEOUT2,V(sensor_id),OPCODE_PAD,V(timeout/100L), #define AUTOMATION(id, description) OPCODE_AUTOMATION, V(id), #define AUTOSTART OPCODE_AUTOSTART,0,0, +#define BLINK(vpin,onDuty,offDuty) OPCODE_BLINK,V(vpin),OPCODE_PAD,V(onDuty),OPCODE_PAD,V(offDuty), #define BROADCAST(msg) PRINT(msg) #define CALL(route) OPCODE_CALL,V(route), #define CLEAR_STASH(id) OPCODE_CLEAR_STASH,V(id), @@ -484,6 +493,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; #define FON(func) OPCODE_FON,V(func), #define FORGET OPCODE_FORGET,0,0, #define FREE(blockid) OPCODE_FREE,V(blockid), +#define FTOGGLE(func) OPCODE_FTOGGLE,V(func), #define FWD(speed) OPCODE_FWD,V(speed), #define GREEN(signal_id) OPCODE_GREEN,V(signal_id), #define HAL(haltype,params...) @@ -518,6 +528,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; #define LCD(id,msg) PRINT(msg) #define SCREEN(display,id,msg) PRINT(msg) #define STEALTH(code...) PRINT(dummy) +#define STEALTH_GLOBAL(code...) #define LCN(msg) PRINT(msg) #define MESSAGE(msg) PRINT(msg) #define MOVETT(id,steps,activity) OPCODE_SERVO,V(id),OPCODE_PAD,V(steps),OPCODE_PAD,V(EXTurntable::activity),OPCODE_PAD,V(0), @@ -595,6 +606,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; #define STASH(id) OPCODE_STASH,V(id), #define STOP OPCODE_SPEED,V(0), #define THROW(id) OPCODE_THROW,V(id), +#define TOGGLE_TURNOUT(id) OPCODE_TOGGLE_TURNOUT,V(id), #ifndef IO_NO_HAL #define TT_ADDPOSITION(id,position,value,angle,description...) OPCODE_TTADDPOSITION,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(value),OPCODE_PAD,V(angle), #endif @@ -611,6 +623,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup]; #endif #define XFOFF(cab,func) OPCODE_XFOFF,V(cab),OPCODE_PAD,V(func), #define XFON(cab,func) OPCODE_XFON,V(cab),OPCODE_PAD,V(func), +#define XFTOGGLE(cab,func) OPCODE_XFTOGGLE,V(cab),OPCODE_PAD,V(func), // Build RouteCode const int StringMacroTracker2=__COUNTER__; diff --git a/Release_Notes/EXRAIL additions.md b/Release_Notes/EXRAIL additions.md new file mode 100644 index 0000000..690ff0a --- /dev/null +++ b/Release_Notes/EXRAIL additions.md @@ -0,0 +1,38 @@ + +BLINK(vpin, onMs,offMs) + +which will start a vpin blinking until such time as it is SET, RESET or set by a signal operation such as RED, AMBER, GREEN. + +BLINK returns immediately, the blinking is autonomous. + +This means a signal that always blinks amber could be done like this: +``` +SIGNAL(30,31,32) +ONAMBER(30) BLINK(31,500,500) DONE +``` +The RED or GREEN calls will turn off the amber blink automatically. + +Alternatively a signal that has normal AMBER and flashing AMBER could be like this: + +#define FLASHAMBER(signal) \ + AMBER(signal) \ + BLINK(signal+1,500,500) + + (Caution: this issumes that the amber pin is redpin+1) + + == + + FTOGGLE(function) + Toggles the current loco function (see FON and FOFF) + + XFTOGGLE(loco,function) + Toggles the function on given loco. (See XFON, XFOFF) + + TOGGLE_TURNOUT(id) + Toggles the turnout (see CLOSE, THROW) + + STEALTH_GLOBAL(code) + ADVANCED C++ users only. + Inserts code such as static variables and functions that + may be utilised by multiple STEALTH operations. + \ No newline at end of file diff --git a/Release_Notes/Exrail mods.txt b/Release_Notes/Exrail mods.txt new file mode 100644 index 0000000..68f57b7 --- /dev/null +++ b/Release_Notes/Exrail mods.txt @@ -0,0 +1,98 @@ + +BLINK(vpin, onMs,offMs) + +which will start a vpin blinking until such time as it is SET, RESET or set by a signal operation such as RED, AMBER, GREEN. + +BLINK returns immediately, the blinking is autonomous. + +This means a signal that always blinks amber could be done like this: + +SIGNAL(30,31,32) +ONAMBER(30) BLINK(31,500,500) DONE + +The RED or GREEN calls will turn off the amber blink automatically. + +Alternatively a signal that has normal AMBER and flashing AMBER could be like this: + +#define FLASHAMBER(signal) \ + AMBER(signal) \ + BLINK(signal+1,500,500) + + (Caution: this assumes that the amber pin is redpin+1) + + == + + FTOGGLE(function) + Toggles the current loco function (see FON and FOFF) + + XFTOGGLE(loco,function) + Toggles the function on given loco. (See XFON, XFOFF) + + TOGGLE_TURNOUT(id) + Toggles the turnout (see CLOSE, THROW) + + STEALTH_GLOBAL(code) + ADVANCED C++ users only. + Inserts code such as static variables and functions that + may be utilised by multiple STEALTH operations. + + +// 5.2.34 - Command fopr DCC Extended Accessories. +This command sends an extended accessory packet to the track, Normally used to set +a signal aspect. Aspect numbers are undefined as sdtandards except for 0 which is +always considered a stop. + +// - Exrail ASPECT(address,aspect) for above. + The ASPECT command sents an aspect to a DCC accessory using the same logic as + . + +// - EXRAIL DCCX_SIGNAL(Address,redAspect,amberAspect,greenAspect) + This defines a signal (with id same as dcc address) that can be operated + by the RED/AMBER/GREEN commands. In each case the command uses the signal + address to refer to the signal and the aspect chosen depends on the use of the RED + AMBER or GREEN command sent. Other aspects may be sent but will require the + direct use of the ASPECT command. + The IFRED/IFAMBER/IFGREEN and ONRED/ONAMBER/ONGREEN commands contunue to operate + as for any other signal type. It is important to be aware that use of the ASPECT + or commands will correctly set the IF flags and call the ON handlers if ASPECT + is used to set one of the three aspects defined in the DCCX_SIGNAL command. + Direct use of other aspects does not affect the signal flags. + ASPECT and can be used withput defining any signal if tyhe flag management or + ON event handlers are not required. + +// 5.2.33 - Exrail CONFIGURE_SERVO(vpin,pos1,pos2,profile) + This macro offsers a more convenient way of performing the HAL call in halSetup.h + In halSetup.h --- IODevice::configureServo(101,300,400,PCA9685::slow); + In myAutomation.h --- CONFIGURE_SERVO(101,300,400,slow) + +// 5.2.32 - Railcom Cutout (Initial trial Mega2560 only) + This cutout will only work on a Mega2560 with a single EX8874 motor shield + configured in the normal way with the main track brake pin on pin 9. + Turns on the cutout mechanism. + Tirns off the cutout. (This is the default) + ONLY to be used by developers used for waveform diagnostics. + (In DEBUG mode the main track idle packets are replaced with reset packets, This + makes it far easier to see the preambles and cutouts on a logic analyser or scope.) + +// 5.2.31 - Exrail JMRI_SENSOR(vpin [,count]) creates types. + This Macro causes the creation of JMRI type sensors in a way that is + simpler than repeating lines of commands. + JMRI_SENSOR(100) is equenvelant to + JMRI_SENSOR(100,16) will create type sensors for vpins 100-115. + +// 5.2.26 - Silently ignore overridden HAL defaults +// - include HAL_IGNORE_DEFAULTS macro in EXRAIL + The HAL_IGNORE_DEFAULTS command, anywhere in myAutomation.h will + prevent the startup code from trying the default I2C sensors/servos. +// 5.2.24 - Exrail macro asserts to catch +// : duplicate/missing automation/route/sequence/call ids +// : latches and reserves out of range +// : speeds out of range + Causes compiler time messages for EXRAIL issues that would normally + only be discovered by things going wrong at run time. +// 5.2.13 - EXRAIL STEALTH + Permits a certain level of C++ code to be embedded as a single step in + an exrail sequence. Serious engineers only. + +// 5.2.9 - EXRAIL STASH feature +// - Added ROUTE_DISABLED macro in EXRAIL From 8a5a832b1d5e2301073b1170b977346de15ecc14 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Tue, 9 Apr 2024 20:59:57 +0100 Subject: [PATCH 17/18] Reduced EXRAIL diag noise --- EXRAIL2.cpp | 16 ++++++------- Release_Notes/EXRAIL additions.md | 38 ------------------------------- version.h | 8 ++++++- 3 files changed, 15 insertions(+), 47 deletions(-) delete mode 100644 Release_Notes/EXRAIL additions.md diff --git a/EXRAIL2.cpp b/EXRAIL2.cpp index ef4387c..9293c96 100644 --- a/EXRAIL2.cpp +++ b/EXRAIL2.cpp @@ -176,7 +176,7 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) { /* static */ void RMFT2::begin() { - DIAG(F("EXRAIL RoutCode at =%P"),RouteCode); + //DIAG(F("EXRAIL RoutCode at =%P"),RouteCode); bool saved_diag=diag; diag=true; @@ -411,7 +411,7 @@ void RMFT2::createNewTask(int route, uint16_t cab) { void RMFT2::driveLoco(byte speed) { if (loco<=0) return; // Prevent broadcast! - if (diag) DIAG(F("EXRAIL drive %d %d %d"),loco,speed,forward^invert); + //if (diag) DIAG(F("EXRAIL drive %d %d %d"),loco,speed,forward^invert); /* TODO..... power on appropriate track if DC or main if dcc if (TrackManager::getMainPowerMode()==POWERMODE::OFF) { @@ -1066,7 +1066,7 @@ void RMFT2::loop2() { case OPCODE_ROUTE: case OPCODE_AUTOMATION: case OPCODE_SEQUENCE: - if (diag) DIAG(F("EXRAIL begin(%d)"),operand); + //if (diag) DIAG(F("EXRAIL begin(%d)"),operand); break; case OPCODE_AUTOSTART: // Handled only during begin process @@ -1146,7 +1146,7 @@ int16_t RMFT2::getSignalSlot(int16_t id) { /* static */ void RMFT2::doSignal(int16_t id,char rag) { if (!(compileFeatures & FEATURE_SIGNAL)) return; // dont compile code below - if (diag) DIAG(F(" doSignal %d %x"),id,rag); + //if (diag) DIAG(F(" doSignal %d %x"),id,rag); // Schedule any event handler for this signal change. // This will work even without a signal definition. @@ -1166,7 +1166,7 @@ int16_t RMFT2::getSignalSlot(int16_t id) { VPIN redpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+2); VPIN amberpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+4); VPIN greenpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+6); - if (diag) DIAG(F("signal %d %d %d %d %d"),sigid,id,redpin,amberpin,greenpin); + //if (diag) DIAG(F("signal %d %d %d %d %d"),sigid,id,redpin,amberpin,greenpin); VPIN sigtype=sigid & ~SIGNAL_ID_MASK; @@ -1174,7 +1174,7 @@ int16_t RMFT2::getSignalSlot(int16_t id) { // A servo signal, the pin numbers are actually servo positions // Note, setting a signal to a zero position has no effect. int16_t servopos= rag==SIGNAL_RED? redpin: (rag==SIGNAL_GREEN? greenpin : amberpin); - if (diag) DIAG(F("sigA %d %d"),id,servopos); + //if (diag) DIAG(F("sigA %d %d"),id,servopos); if (servopos!=0) IODevice::writeAnalogue(id,servopos,PCA9685::Bounce); return; } @@ -1292,7 +1292,7 @@ void RMFT2::rotateEvent(int16_t turntableId, bool change) { void RMFT2::clockEvent(int16_t clocktime, bool change) { // Hunt for an ONTIME for this time if (Diag::CMD) - DIAG(F("Looking for clock event at : %d"), clocktime); + DIAG(F("clockEvent at : %d"), clocktime); if (change) { onClockLookup->handleEvent(F("CLOCK"),clocktime); onClockLookup->handleEvent(F("CLOCK"),25*60+clocktime%60); @@ -1302,7 +1302,7 @@ void RMFT2::clockEvent(int16_t clocktime, bool change) { void RMFT2::powerEvent(int16_t track, bool overload) { // Hunt for an ONOVERLOAD for this item if (Diag::CMD) - DIAG(F("Looking for Power event on track : %c"), track); + DIAG(F("powerEvent : %c"), track); if (overload) { onOverloadLookup->handleEvent(F("POWER"),track); } diff --git a/Release_Notes/EXRAIL additions.md b/Release_Notes/EXRAIL additions.md deleted file mode 100644 index 690ff0a..0000000 --- a/Release_Notes/EXRAIL additions.md +++ /dev/null @@ -1,38 +0,0 @@ - -BLINK(vpin, onMs,offMs) - -which will start a vpin blinking until such time as it is SET, RESET or set by a signal operation such as RED, AMBER, GREEN. - -BLINK returns immediately, the blinking is autonomous. - -This means a signal that always blinks amber could be done like this: -``` -SIGNAL(30,31,32) -ONAMBER(30) BLINK(31,500,500) DONE -``` -The RED or GREEN calls will turn off the amber blink automatically. - -Alternatively a signal that has normal AMBER and flashing AMBER could be like this: - -#define FLASHAMBER(signal) \ - AMBER(signal) \ - BLINK(signal+1,500,500) - - (Caution: this issumes that the amber pin is redpin+1) - - == - - FTOGGLE(function) - Toggles the current loco function (see FON and FOFF) - - XFTOGGLE(loco,function) - Toggles the function on given loco. (See XFON, XFOFF) - - TOGGLE_TURNOUT(id) - Toggles the turnout (see CLOSE, THROW) - - STEALTH_GLOBAL(code) - ADVANCED C++ users only. - Inserts code such as static variables and functions that - may be utilised by multiple STEALTH operations. - \ No newline at end of file diff --git a/version.h b/version.h index a772201..3eaf199 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,13 @@ #include "StringFormatter.h" -#define VERSION "5.2.46" +#define VERSION "5.2.47" +// 5.2.47 - EXRAIL additions: +// STEALTH_GLOBAL +// BLINK +// TOGGLE_TURNOUT +// FTOGGLE, XFTOGGLE +// Reduced code-developmenmt DIAG noise // 5.2.46 - Support for extended consist CV20 in and // - New cmd to handle long/short consist ids // 5.2.45 - ESP32 Trackmanager reset cab number to 0 when track is not DC From 91e60b371667763135207e2ac5ea707f7558f8d7 Mon Sep 17 00:00:00 2001 From: pmantoine Date: Fri, 12 Apr 2024 17:25:00 +0800 Subject: [PATCH 18/18] HALDisplay bug fix --- IO_HALDisplay.h | 11 +++++++---- version.h | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/IO_HALDisplay.h b/IO_HALDisplay.h index f2ca3af..24ffde7 100644 --- a/IO_HALDisplay.h +++ b/IO_HALDisplay.h @@ -1,7 +1,9 @@ /* - * © 2023, Neil McKechnie. All rights reserved. + * © 2024, Paul Antoine + * © 2023, Neil McKechnie + * All rights reserved. * - * This file is part of DCC++EX API + * This file is part of DCC-EX API * * This is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -112,13 +114,14 @@ protected: // Fill buffer with spaces memset(_buffer, ' ', _numCols*_numRows); - _displayDriver->clearNative(); - // Add device to list of HAL devices (not necessary but allows // status to be displayed using and device to be // reinitialised using ). IODevice::addDevice(this); + // Moved after addDevice() to ensure I2CManager.begin() has been called fisrt + _displayDriver->clearNative(); + // Also add this display to list of display handlers DisplayInterface::addDisplay(displayNo); diff --git a/version.h b/version.h index 3eaf199..e871738 100644 --- a/version.h +++ b/version.h @@ -3,7 +3,8 @@ #include "StringFormatter.h" -#define VERSION "5.2.47" +#define VERSION "5.2.48" +// 5.2.48 - Bugfix: HALDisplay was generating I2C traffic prior to I2C being initialised // 5.2.47 - EXRAIL additions: // STEALTH_GLOBAL // BLINK