1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-07-28 09:53:45 +02:00

merge 28speedsteps

This commit is contained in:
Harald Barth
2021-04-06 22:04:16 +02:00
3 changed files with 45 additions and 2 deletions

31
DCC.cpp
View File

@@ -46,6 +46,7 @@ const byte FN_GROUP_5=0x10;
FSH* DCC::shieldName=NULL;
byte DCC::joinRelay=UNUSED_PIN;
byte DCC::globalSpeedsteps=128;
void DCC::begin(const FSH * motorShieldName, MotorDriver * mainDriver, MotorDriver* progDriver) {
shieldName=(FSH *)motorShieldName;
@@ -82,8 +83,34 @@ void DCC::setThrottle2( uint16_t cab, byte speedCode) {
if (cab > 127)
b[nB++] = highByte(cab) | 0xC0; // convert train number into a two-byte address
b[nB++] = lowByte(cab);
b[nB++] = SET_SPEED; // 128-step speed control byte
b[nB++] = speedCode; // for encoding see setThrottle
if (globalSpeedsteps <= 28) {
uint8_t speed128 = speedCode & 0x7F;
uint8_t speed28;
uint8_t code28;
if (speed128 == 0 || speed128 == 1) { // stop or emergency stop
code28 = speed128;
} else {
speed28= (speed128*10+36)/46; // convert 2-127 to 1-28
/*
if (globalSpeedsteps <= 14) // Don't want to do 14 steps, to get F0 there is ugly
code28 = (speed28+3)/2 | (Value of F0); // convert 1-28 to DCC 14 step speed code
else
*/
code28 = (speed28+3)/2 | ( (speed28 & 1) ? 0 : 0b00010000 ); // convert 1-28 to DCC 28 step speed code
}
// Construct command byte from:
// command speed direction
b[nB++] = 0b01000000 | code28 | ((speedCode & 0x80) ? 0b00100000 : 0);
} else { // 128 speedsteps
b[nB++] = SET_SPEED; // 128-step speed control byte
b[nB++] = speedCode; // for encoding see setThrottle
}
DCCWaveform::mainTrack.schedulePacket(b, nB, 0);
}