Skip to content

Commit f3dde9c

Browse files
committed
DCC:setThrottle can return bool for success (loco found or created) or not
1 parent 216e4b9 commit f3dde9c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

DCC.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ byte DCC::getMomentum(LocoSlot * slot) {
9797
return (slot->getMomentumD() == MOMENTUM_USE_DEFAULT) ? defaultMomentumD : slot->getMomentumD();
9898
}
9999

100-
void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
100+
bool DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
101101
if (tSpeed==1) {
102102
if (cab==0) {
103103
estopAll(); // ESTOP broadcast fix
104-
return;
104+
return true;
105105
}
106106
}
107107
byte speedCode = (tSpeed & 0x7F) + tDirection * 128;
108108
auto slot=LocoSlot::getSlot(cab, true);
109-
if (!slot) return; // speed table full, can not do anything
109+
if (!slot) return false; // speed table full, can not do anything
110110
if (slot->getTargetSpeed()==speedCode) // speed has been reached
111-
return;
111+
return true;
112112
slot->setTargetSpeed(speedCode);
113113
byte momentum=getMomentum(slot);
114114
if (momentum && tSpeed!=1) { // not ESTOP
@@ -121,6 +121,7 @@ void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) {
121121
TrackManager::setDCSignal(cab,speedCode); // in case this is a dcc track on this addr
122122
}
123123
CommandDistributor::broadcastLoco(slot);
124+
return true;
124125
}
125126

126127
void DCC::setThrottle2( uint16_t cab, byte speedCode) {
@@ -1208,4 +1209,4 @@ void DCC::clearBlock(uint16_t blockid) {
12081209
}
12091210
}
12101211
#endif
1211-
}
1212+
}

DCC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DCC
5050
static void loop();
5151

5252
// Public DCC API functions
53-
static void setThrottle(uint16_t cab, uint8_t tSpeed, bool tDirection);
53+
static bool setThrottle(uint16_t cab, uint8_t tSpeed, bool tDirection);
5454
static void estopAll();
5555
static int8_t getThrottleSpeed(int cab);
5656
static uint8_t getThrottleSpeedByte(int cab);

DCCEXParser.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,14 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
376376
if (cab > 10239 || cab < 0)
377377
break; // beyond DCC range
378378

379-
DCC::setThrottle(cab, tspeed, direction);
380-
if (params == 4) // send obsolete format T response
379+
if (DCC::setThrottle(cab, tspeed, direction)) {
380+
if (params == 4) // send obsolete format T response
381381
StringFormatter::send(stream, F("<T %d %d %d>\n"), p[0], p[2], p[3]);
382-
// speed change will be broadcast anyway in new <l > format
383-
return;
382+
// speed change will be broadcast anyway in new <l > format
383+
return;
384+
} else {
385+
break; // setThrottle() failed means slot table was full.
386+
}
384387
}
385388
case 'f': // FUNCTION <f CAB BYTE1 [BYTE2]>
386389
if (parsef(stream, params, p))

0 commit comments

Comments
 (0)