1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-22 23:56:13 +01:00

pwmSpeed() as access method instead of public pointer

This commit is contained in:
Harald Barth 2021-09-04 09:05:01 +02:00
parent 66cf6d632b
commit 414e109f9d
2 changed files with 26 additions and 14 deletions

16
DCC.cpp
View File

@ -58,11 +58,11 @@ void DCC::begin(const FSH * motorShieldName, MotorDriver * mainDriver, MotorDriv
DCCWaveform::begin(mainDriver,progDriver);
#ifdef DCdistrict
DCCWaveform::mainTrack.motorDriver->setBrake(255);
DCCWaveform::mainTrack.pwmSpeed(0);
#else
DCCWaveform::mainTrack.motorDriver->setBrake(0);
DCCWaveform::mainTrack.pwmSpeed(255);
#endif
DCCWaveform::progTrack.motorDriver->setBrake(0);
DCCWaveform::progTrack.pwmSpeed(255);
}
@ -77,15 +77,7 @@ void DCC::setJoinRelayPin(byte joinRelayPin) {
void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
#ifdef DCdistrict
if (cab == DCdistrict) {
uint8_t brake;
if (tSpeed <= 1)
brake = 255;
else if (tSpeed >= 126)
brake = 0;
else
brake = 2 * (127-tSpeed);
DCCWaveform::mainTrack.motorDriver->setSignal(tDirection);
DCCWaveform::mainTrack.motorDriver->setBrake(brake);
DCCWaveform::mainTrack.pwmSpeed(tSpeed, tDirection);
}
#else
#error fooar

View File

@ -107,7 +107,27 @@ class DCCWaveform {
inline void setMaxAckPulseDuration(unsigned int i) {
maxAckPulseDuration = i;
}
MotorDriver* motorDriver;
#ifdef DCdistrict
inline void pwmSpeed(uint8_t tSpeed) {
// DCC Speed with 0,1 stop and speed steps 2 to 127
uint8_t brake;
if (!motorDriver)
return;
if (tSpeed <= 1)
brake = 255;
else if (tSpeed >= 127)
brake = 0;
else
brake = 2 * (128-tSpeed);
motorDriver->setBrake(brake);
}
inline void pwmSpeed(uint8_t tSpeed, bool tDirection) {
if (!motorDriver)
return;
pwmSpeed(tSpeed);
motorDriver->setSignal(tDirection);
}
#endif
private:
@ -122,7 +142,7 @@ class DCCWaveform {
void checkAck();
bool isMainTrack;
// MotorDriver* motorDriver;
MotorDriver* motorDriver;
// Transmission controller
byte transmitPacket[MAX_PACKET_SIZE+1]; // +1 for checksum
byte transmitLength;