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() {
180
180
}
181
181
}
182
182
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
+
184
188
mutex.lock ();
185
189
if (isValidId (id))
186
190
{
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ class SmartServoClass
89
89
static int constexpr MIN_MOTOR_ID = 1 ;
90
90
static int constexpr MAX_MOTOR_ID = 6 ;
91
91
92
+ inline bool isValidAngle (float const angle) { return ((angle >= 0 .0f ) && (angle <= MAX_ANGLE)); }
92
93
inline bool isValidId (int const id) const { return ((id >= MIN_MOTOR_ID) && (id <= MAX_MOTOR_ID)); }
93
94
inline int idToArrayIndex (int const id) const { return (id - 1 ); }
94
95
You can’t perform that action at this time.
0 commit comments