Skip to content

Commit 99242d9

Browse files
committed
Only lock actual writing to the servos.
1 parent 6e15737 commit 99242d9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib/motors/SmartServo.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,24 @@ void SmartServoClass::setTorque(uint8_t const id, bool const torque)
294294

295295
void SmartServoClass::setTime(uint16_t const time)
296296
{
297-
mbed::ScopedLock<rtos::Mutex> lock(_mtx);
298297
for (int i = MIN_MOTOR_ID; i <= MAX_MOTOR_ID; i++)
299298
_targetSpeed[idToArrayIndex(i)] = time;
299+
300+
mbed::ScopedLock<rtos::Mutex> lock(_mtx);
300301
writeWordCmd(BROADCAST, REG(SmartServoRegister::RUN_TIME_H), time);
301302
}
302303

303304
void SmartServoClass::setTime(uint8_t const id, uint16_t const time)
304305
{
306+
if (!isValidId(id))
307+
return;
308+
309+
if (id == BROADCAST)
310+
return;
311+
312+
_targetSpeed[idToArrayIndex(id)] = time;
313+
305314
mbed::ScopedLock<rtos::Mutex> lock(_mtx);
306-
if ((id >= MIN_MOTOR_ID) && (id <= MAX_MOTOR_ID)) _targetSpeed[idToArrayIndex(id)] = time;
307315
writeWordCmd(id, REG(SmartServoRegister::RUN_TIME_H), time);
308316
}
309317

0 commit comments

Comments
 (0)