mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
clean up getThrottleSpeed functions
This commit is contained in:
parent
06e7ad5c53
commit
016bc37b53
15
DCC.cpp
15
DCC.cpp
|
@ -137,12 +137,25 @@ void DCC::setFunctionInternal(int cab, byte byte1, byte byte2) {
|
|||
DCCWaveform::mainTrack.schedulePacket(b, nB, 0);
|
||||
}
|
||||
|
||||
uint8_t DCC::getThrottleSpeed(int cab) {
|
||||
// returns speed steps 0 to 127 (1 == emergency stop)
|
||||
// or -1 on "loco not found"
|
||||
int8_t DCC::getThrottleSpeed(int cab) {
|
||||
int reg=lookupSpeedTable(cab);
|
||||
if (reg<0) return -1;
|
||||
return speedTable[reg].speedCode & 0x7F;
|
||||
}
|
||||
|
||||
// returns speed code byte
|
||||
// or 128 (speed 0, dir forward) on "loco not found".
|
||||
uint8_t DCC::getThrottleSpeedByte(int cab) {
|
||||
int reg=lookupSpeedTable(cab);
|
||||
if (reg<0)
|
||||
return 128;
|
||||
return speedTable[reg].speedCode;
|
||||
}
|
||||
|
||||
// returns direction on loco
|
||||
// or true/forward on "loco not found"
|
||||
bool DCC::getThrottleDirection(int cab) {
|
||||
int reg=lookupSpeedTable(cab);
|
||||
if (reg<0) return true;
|
||||
|
|
3
DCC.h
3
DCC.h
|
@ -56,7 +56,8 @@ public:
|
|||
|
||||
// Public DCC API functions
|
||||
static void setThrottle(uint16_t cab, uint8_t tSpeed, bool tDirection);
|
||||
static uint8_t getThrottleSpeed(int cab);
|
||||
static int8_t getThrottleSpeed(int cab);
|
||||
static uint8_t getThrottleSpeedByte(int cab);
|
||||
static bool getThrottleDirection(int cab);
|
||||
static void writeCVByteMain(int cab, int cv, byte bValue);
|
||||
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
|
||||
|
|
|
@ -1 +1 @@
|
|||
#define GITHUB_SHA "TM-PORTX-20220525"
|
||||
#define GITHUB_SHA "TM-PORTX-20220605"
|
||||
|
|
|
@ -209,17 +209,10 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
|||
}
|
||||
|
||||
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);
|
||||
uint8_t speedByte=DCC::getThrottleSpeedByte(trackDCAddr[t]);
|
||||
if (trackMode[t]==TRACK_MODE_DCX)
|
||||
speedByte = (speedByte & 0xF7) | ~(speedByte & 0x80); // Reverse highest bit
|
||||
track[t]->setDCSignal(speedByte);
|
||||
}
|
||||
|
||||
bool TrackManager::parseJ(Print *stream, int16_t params, int16_t p[])
|
||||
|
|
|
@ -421,7 +421,10 @@ void WiThrottle::locoAction(RingStream * stream, byte* aval, char throttleChar,
|
|||
bool forward=aval[1]!='0';
|
||||
LOOPLOCOS(throttleChar, cab) {
|
||||
mostRecentCab=myLocos[loco].cab;
|
||||
DCC::setThrottle(myLocos[loco].cab, DCC::getThrottleSpeed(myLocos[loco].cab), forward);
|
||||
int8_t speed = DCC::getThrottleSpeed(myLocos[loco].cab);
|
||||
if (speed < 0) //can not find any speed for this cab
|
||||
speed = 0;
|
||||
DCC::setThrottle(myLocos[loco].cab, speed, forward);
|
||||
// setThrottle will cause a broadcast so notification will be sent
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user