1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 17:46:14 +01:00

make usePWM per track (trackPWM) 2nd half

This commit is contained in:
Harald Barth 2022-06-07 08:09:20 +02:00
parent ff96ed1157
commit 4e177cf744
2 changed files with 9 additions and 6 deletions

View File

@ -2,6 +2,7 @@
* © 2021 Mike S * © 2021 Mike S
* © 2021 Fred Decker * © 2021 Fred Decker
* © 2020 Chris Harlow * © 2020 Chris Harlow
* © 2022 Harald Barth
* All rights reserved. * All rights reserved.
* *
* This file is part of Asbelos DCC API * This file is part of Asbelos DCC API
@ -87,7 +88,7 @@ class MotorDriver {
virtual void setPower( POWERMODE mode); virtual void setPower( POWERMODE mode);
virtual POWERMODE getPower() { return powerMode;} virtual POWERMODE getPower() { return powerMode;}
__attribute__((always_inline)) inline void setSignal( bool high) { __attribute__((always_inline)) inline void setSignal( bool high) {
if (usePWM) { if (trackPWM) {
DCCTimer::setPWM(signalPin,high); DCCTimer::setPWM(signalPin,high);
} }
else { else {

View File

@ -190,25 +190,27 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
// capable tracks is now DC or DCX. // capable tracks is now DC or DCX.
if (trackMode[t]==TRACK_MODE_DC || trackMode[t]==TRACK_MODE_DCX) { if (trackMode[t]==TRACK_MODE_DC || trackMode[t]==TRACK_MODE_DCX) {
if (track[t]->isPWMCapable()) { if (track[t]->isPWMCapable()) {
canDo=false; canDo=false; // this track is capable but can not run PWM
break; break; // in this mode, so abort and prevent globally below
} else { } else {
track[t]->trackPWM=false; track[t]->trackPWM=false; // this track sure can not run with PWM
DIAG(F("Track %c trackPWM 0 (not capable)"), t+'A'); DIAG(F("Track %c trackPWM 0 (not capable)"), t+'A');
} }
} else if (trackMode[t]==TRACK_MODE_MAIN || trackMode[t]==TRACK_MODE_PROG) { } else if (trackMode[t]==TRACK_MODE_MAIN || trackMode[t]==TRACK_MODE_PROG) {
track[t]->trackPWM = track[t]->isPWMCapable(); track[t]->trackPWM = track[t]->isPWMCapable(); // trackPWM is still a guess here
DIAG(F("Track %c trackPWM %d"), t+'A', track[t]->trackPWM); DIAG(F("Track %c trackPWM %d"), t+'A', track[t]->trackPWM);
canDo &= track[t]->trackPWM; canDo &= track[t]->trackPWM;
} }
} }
if (!canDo) { if (!canDo) {
DCCTimer::clearPWM(); // if we discover that HA mode was globally impossible
// we must adjust the trackPWM capabilities
FOR_EACH_TRACK(t) { FOR_EACH_TRACK(t) {
track[t]->trackPWM=false; track[t]->trackPWM=false;
DIAG(F("Track %c trackPWM 0 (global override)"), t+'A'); DIAG(F("Track %c trackPWM 0 (global override)"), t+'A');
} }
DCCTimer::clearPWM(); // has to be AFTER trackPWM changes because if trackPWM==true this is undone for that track
} }
if (MotorDriver::usePWM != canDo) if (MotorDriver::usePWM != canDo)
DIAG(F("HA mode changed from %d to %d"), MotorDriver::usePWM, canDo); DIAG(F("HA mode changed from %d to %d"), MotorDriver::usePWM, canDo);