File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,11 @@ int SmartServoClass::begin() {
180180 }
181181}
182182
183- void SmartServoClass::setPosition (uint8_t const id, float const angle, uint16_t const speed) {
183+ void SmartServoClass::setPosition (uint8_t const id, float const angle, uint16_t const speed)
184+ {
185+ if (!isValidAngle (angle))
186+ return ;
187+
184188 mutex.lock ();
185189 if (isValidId (id))
186190 {
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ class SmartServoClass
8989 static int constexpr MIN_MOTOR_ID = 1 ;
9090 static int constexpr MAX_MOTOR_ID = 6 ;
9191
92+ inline bool isValidAngle (float const angle) { return ((angle >= 0 .0f ) && (angle <= MAX_ANGLE)); }
9293 inline bool isValidId (int const id) const { return ((id >= MIN_MOTOR_ID) && (id <= MAX_MOTOR_ID)); }
9394 inline int idToArrayIndex (int const id) const { return (id - 1 ); }
9495
You can’t perform that action at this time.
0 commit comments