File tree Expand file tree Collapse file tree 3 files changed +6
-5
lines changed Expand file tree Collapse file tree 3 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ void BraccioClass::pingOff()
185185bool BraccioClass::connected (int const id)
186186{
187187 mbed::ScopedLock<rtos::Mutex> lock (_motors_connected_mtx);
188- return _is_motor_connected[id ];
188+ return _is_motor_connected[SmartServoClass::idToArrayIndex (id) ];
189189}
190190
191191MotorsWrapper BraccioClass::move (int const id)
@@ -323,7 +323,7 @@ bool BraccioClass::isPingAllowed()
323323void BraccioClass::setMotorConnectionStatus (int const id, bool const is_connected)
324324{
325325 mbed::ScopedLock<rtos::Mutex> lock (_motors_connected_mtx);
326- _is_motor_connected[id ] = is_connected;
326+ _is_motor_connected[SmartServoClass::idToArrayIndex (id) ] = is_connected;
327327}
328328
329329void BraccioClass::motorConnectedThreadFunc ()
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ class BraccioClass
114114 void display_thread_func ();
115115
116116 bool _is_ping_allowed;
117- bool _is_motor_connected[8 ];
117+ bool _is_motor_connected[SmartServoClass::NUM_MOTORS ];
118118 rtos::Mutex _motors_connected_mtx;
119119 rtos::Thread _motors_connected_thd;
120120 bool isPingAllowed ();
Original file line number Diff line number Diff line change @@ -74,18 +74,19 @@ class SmartServoClass
7474 static int constexpr BROADCAST = 0xFE ;
7575 static int constexpr MIN_MOTOR_ID = 1 ;
7676 static int constexpr MAX_MOTOR_ID = 6 ;
77+ static int constexpr NUM_MOTORS = 6 ;
7778 static float constexpr MAX_ANGLE = 315 .0f ;
7879
80+ static int idToArrayIndex (int const id) { return (id - 1 ); }
81+
7982private:
8083
81- static int constexpr NUM_MOTORS = 6 ;
8284 static int constexpr MAX_TX_PAYLOAD_LEN = (5 *NUM_MOTORS+4 );
8385 static int constexpr MAX_RX_PAYLOAD_LEN = 10 ;
8486 static int constexpr MAX_POSITION = 4000 ;
8587
8688 inline bool isValidAngle (float const angle) { return ((angle >= 0 .0f ) && (angle <= MAX_ANGLE)); }
8789 inline bool isValidId (int const id) const { return ((id >= MIN_MOTOR_ID) && (id <= MAX_MOTOR_ID)); }
88- inline int idToArrayIndex (int const id) const { return (id - 1 ); }
8990
9091 int calcChecksum ();
9192 void sendPacket ();
You can’t perform that action at this time.
0 commit comments