Skip to content

Commit cac386f

Browse files
committed
Use only the maximum number of array elements necessary.
1 parent b3ddf4c commit cac386f

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/Braccio++.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void BraccioClass::pingOff()
185185
bool 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

191191
MotorsWrapper BraccioClass::move(int const id)
@@ -323,7 +323,7 @@ bool BraccioClass::isPingAllowed()
323323
void 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

329329
void BraccioClass::motorConnectedThreadFunc()

src/Braccio++.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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();

src/lib/motors/SmartServo.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
7982
private:
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 ();

0 commit comments

Comments
 (0)