From c1993fba8741d9ace4f47364ed22729a2562fbc5 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Wed, 10 Aug 2022 00:14:28 +0200 Subject: [PATCH] make DC mode portable to ESP32 --- MotorDriver.h | 13 ++++++++++++- MotorDrivers.h | 4 ++-- TrackManager.cpp | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/MotorDriver.h b/MotorDriver.h index 2138a40..7a155ae 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -136,16 +136,27 @@ class MotorDriver { }; inline byte getSignalPin() { return signalPin; }; virtual void setDCSignal(byte speedByte); + inline void detachDCSignal() { +#ifndef ARDUINO_ARCH_ESP32 + setDCSignal(128); +#else + ledcDetachPin(brakePin); +#endif + }; virtual int getCurrentRaw(); virtual int getCurrentRawInInterrupt(); virtual unsigned int raw2mA( int raw); virtual unsigned int mA2raw( unsigned int mA); inline bool brakeCanPWM() { +#ifdef ARDUINO_ARCH_ESP32 + return true; +#else #ifdef digitalPinToTimer return ((brakePin!=UNUSED_PIN) && (digitalPinToTimer(brakePin))); #else return (brakePin<14 && brakePin >1); -#endif +#endif //digitalPinToTimer +#endif //ESP32 } inline int getRawCurrentTripValue() { return rawCurrentTripValue; diff --git a/MotorDrivers.h b/MotorDrivers.h index 2f51b4a..3e3464b 100644 --- a/MotorDrivers.h +++ b/MotorDrivers.h @@ -56,8 +56,8 @@ new MotorDriver(11, 13, UNUSED_PIN, 8, A1, 1.95, 2000, UNUSED_PIN) #elif defined(ARDUINO_ARCH_ESP32) #define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \ - new MotorDriver(25/* 3*/, 19/*12*/, UNUSED_PIN, UNUSED_PIN, 36/*A4*/, 0.57, 2000, UNUSED_PIN), \ - new MotorDriver(23/*11*/, 18/*13*/, UNUSED_PIN, UNUSED_PIN, 39/*A5*/, 0.57, 2000, UNUSED_PIN) + new MotorDriver(25/* 3*/, 19/*12*/, UNUSED_PIN, 13/*9*/, 36/*A4*/, 0.57, 2000, UNUSED_PIN), \ + new MotorDriver(23/*11*/, 18/*13*/, UNUSED_PIN, 12/*8*/, 39/*A5*/, 0.57, 2000, UNUSED_PIN) #else #define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \ new MotorDriver(3, 12, UNUSED_PIN, 9, A0, 2.99, 2000, UNUSED_PIN), \ diff --git a/TrackManager.cpp b/TrackManager.cpp index 6c4da7b..772ddc5 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -170,7 +170,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr else { // DCC tracks need to have set the PWM to zero or they will not work. // 128 is speed=0 and dir=0 and then loosen brake. - track[trackToSet]->setDCSignal(128); + track[trackToSet]->detachDCSignal(); track[trackToSet]->setBrake(false); }