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

28 speed step prototype

This commit is contained in:
Harald Barth 2021-03-16 10:59:14 +01:00
parent 086336158f
commit 55cdbbbb66

21
DCC.cpp
View File

@ -80,9 +80,30 @@ 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);
#ifdef USE_28_STEP
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
code28 = (speed28+3)/2 + 16*(!(speed28 & 1)); // convert 1-28 to DCC 28 step speed code
}
// Construct command byte from:
// command speed direction
b[nB++] = 0b01000000 | code28 | (0b00100000 * (speedCode & 0x80));
#else
b[nB++] = SET_SPEED; // 128-step speed control byte
b[nB++] = speedCode; // for encoding see setThrottle
#endif
DCCWaveform::mainTrack.schedulePacket(b, nB, 0);
}