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

function bits to freqency step #2

This commit is contained in:
Harald Barth
2023-12-30 22:09:01 +01:00
parent adb8b56c92
commit 67387d2dc3
5 changed files with 20 additions and 8 deletions

12
DCC.cpp
View File

@@ -138,7 +138,7 @@ void DCC::setFunctionInternal(int cab, byte byte1, byte byte2, byte count) {
// returns speed steps 0 to 127 (1 == emergency stop)
// or -1 on "loco not found"
int8_t DCC::getThrottleSpeed(int cab) {
static int8_t DCC::getThrottleSpeed(int cab) {
int reg=lookupSpeedTable(cab);
if (reg<0) return -1;
return speedTable[reg].speedCode & 0x7F;
@@ -146,13 +146,21 @@ int8_t DCC::getThrottleSpeed(int cab) {
// returns speed code byte
// or 128 (speed 0, dir forward) on "loco not found".
uint8_t DCC::getThrottleSpeedByte(int cab) {
static uint8_t DCC::getThrottleSpeedByte(int cab) {
int reg=lookupSpeedTable(cab);
if (reg<0)
return 128;
return speedTable[reg].speedCode;
}
// returns -1 for fault, 0 to 3 for frequency
static int8_t DCC::getThrottleFrequency(int cab) {
int reg=lookupSpeedTable(cab);
if (reg<0)
return -1;
return (int8_t)(speedTable[reg].functions >>29); // shift out first 29 bits so we have the "frequency bits" left
}
// returns direction on loco
// or true/forward on "loco not found"
bool DCC::getThrottleDirection(int cab) {