mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 13:21:23 +01:00
DC power fix
This commit is contained in:
parent
f9e36e6693
commit
ece342f037
@ -97,10 +97,6 @@ bool MotorDriver::isPWMCapable() {
|
|||||||
void MotorDriver::setPower(POWERMODE mode) {
|
void MotorDriver::setPower(POWERMODE mode) {
|
||||||
bool on=mode==POWERMODE::ON;
|
bool on=mode==POWERMODE::ON;
|
||||||
if (on) {
|
if (on) {
|
||||||
// toggle brake before turning power on - resets overcurrent error
|
|
||||||
// on the Pololu board if brake is wired to ^D2.
|
|
||||||
setBrake(true);
|
|
||||||
setBrake(false);
|
|
||||||
IODevice::write(powerPin,HIGH);
|
IODevice::write(powerPin,HIGH);
|
||||||
}
|
}
|
||||||
else IODevice::write(powerPin,LOW);
|
else IODevice::write(powerPin,LOW);
|
||||||
|
@ -134,17 +134,8 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
|||||||
// DC tracks need to be given speed of the throttle for that cab address
|
// DC tracks need to be given speed of the throttle for that cab address
|
||||||
// otherwise will not match other tracks on same cab.
|
// otherwise will not match other tracks on same cab.
|
||||||
// This also needs to allow for inverted DCX
|
// This also needs to allow for inverted DCX
|
||||||
|
applyDCSpeed(trackToSet);
|
||||||
|
|
||||||
int16_t speed1=DCC::getThrottleSpeed(dcAddr);
|
|
||||||
byte speedByte;
|
|
||||||
if (speed1<0) speedByte=0;
|
|
||||||
else {
|
|
||||||
speedByte=speed1;
|
|
||||||
bool direction=DCC::getThrottleDirection(dcAddr);
|
|
||||||
if (mode==TRACK_MODE_DCX) direction=!direction;
|
|
||||||
if (direction) speedByte|=0x80;
|
|
||||||
}
|
|
||||||
track[trackToSet]->setDCSignal(speedByte);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// DCC tracks need to have the brake set off or they will not work.
|
// DCC tracks need to have the brake set off or they will not work.
|
||||||
@ -168,6 +159,20 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackManager::applyDCSpeed(byte t) {
|
||||||
|
|
||||||
|
int16_t speed1=DCC::getThrottleSpeed(trackDCAddr[t]);
|
||||||
|
byte speedByte;
|
||||||
|
if (speed1<0) speedByte=0;
|
||||||
|
else {
|
||||||
|
speedByte=speed1;
|
||||||
|
bool direction=DCC::getThrottleDirection(trackDCAddr[t]);
|
||||||
|
if (trackMode[t]==TRACK_MODE_DCX) direction=!direction;
|
||||||
|
if (direction) speedByte|=0x80;
|
||||||
|
}
|
||||||
|
track[t]->setDCSignal(speedByte);
|
||||||
|
}
|
||||||
|
|
||||||
bool TrackManager::parseJ(Print *stream, int16_t params, int16_t p[])
|
bool TrackManager::parseJ(Print *stream, int16_t params, int16_t p[])
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -241,17 +246,37 @@ MotorDriver * TrackManager::getProgDriver() {
|
|||||||
if (trackMode[t]==TRACK_MODE_PROG) return track[t];
|
if (trackMode[t]==TRACK_MODE_PROG) return track[t];
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackManager::setPower2(bool setProg,POWERMODE mode) {
|
void TrackManager::setPower2(bool setProg,POWERMODE mode) {
|
||||||
if (setProg) {
|
if (!setProg) mainPowerGuess=mode;
|
||||||
APPLY_BY_MODE(TRACK_MODE_PROG,setPower(mode))
|
FOR_EACH_TRACK(t) {
|
||||||
}
|
MotorDriver * driver=track[t];
|
||||||
else {
|
if (!driver) continue;
|
||||||
mainPowerGuess=mode;
|
switch (trackMode[t]) {
|
||||||
FOR_EACH_TRACK(t)
|
case TRACK_MODE_MAIN:
|
||||||
if (track[t]
|
if (setProg) break;
|
||||||
&& trackMode[t]!=TRACK_MODE_OFF
|
// toggle brake before turning power on - resets overcurrent error
|
||||||
&& trackMode[t]!=TRACK_MODE_PROG
|
// on the Pololu board if brake is wired to ^D2.
|
||||||
) track[t]->setPower(mode);
|
driver->setBrake(true);
|
||||||
|
driver->setBrake(false); // DCC runs with brake off
|
||||||
|
driver->setPower(mode);
|
||||||
|
break;
|
||||||
|
case TRACK_MODE_DC:
|
||||||
|
case TRACK_MODE_DCX:
|
||||||
|
if (setProg) break;
|
||||||
|
driver->setBrake(true); // DC starts with brake on
|
||||||
|
applyDCSpeed(t); // speed match DCC throttles
|
||||||
|
driver->setPower(mode);
|
||||||
|
break;
|
||||||
|
case TRACK_MODE_PROG:
|
||||||
|
if (!setProg) break;
|
||||||
|
driver->setBrake(true);
|
||||||
|
driver->setBrake(false);
|
||||||
|
driver->setPower(mode);
|
||||||
|
break;
|
||||||
|
case TRACK_MODE_OFF:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ class TrackManager {
|
|||||||
static byte lastTrack;
|
static byte lastTrack;
|
||||||
static byte nextCycleTrack;
|
static byte nextCycleTrack;
|
||||||
static POWERMODE mainPowerGuess;
|
static POWERMODE mainPowerGuess;
|
||||||
|
static void applyDCSpeed(byte t);
|
||||||
|
|
||||||
static MotorDriver* track[MAX_TRACKS];
|
static MotorDriver* track[MAX_TRACKS];
|
||||||
static TRACK_MODE trackMode[MAX_TRACKS];
|
static TRACK_MODE trackMode[MAX_TRACKS];
|
||||||
|
Loading…
Reference in New Issue
Block a user