Skip to content

Commit 6e00d45

Browse files
committed
Define ID to array index function for better convenience.
1 parent e2f96f2 commit 6e00d45

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/lib/motors/SmartServo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ void SmartServoClass::synchronize() {
219219

220220
for (int i = MIN_MOTOR_ID; i <= MAX_MOTOR_ID; i++) {
221221
_txPacket.payload[index++] = i;
222-
_txPacket.payload[index++] = _targetPosition[i-1] >>8;
223-
_txPacket.payload[index++] = _targetPosition[i-1];
224-
_txPacket.payload[index++] = _targetSpeed[i-1]>>8;
225-
_txPacket.payload[index++] = _targetSpeed[i-1];
222+
_txPacket.payload[index++] = _targetPosition[idToArrayIndex(i)] >>8;
223+
_txPacket.payload[index++] = _targetPosition[idToArrayIndex(i)];
224+
_txPacket.payload[index++] = _targetSpeed[idToArrayIndex(i)]>>8;
225+
_txPacket.payload[index++] = _targetSpeed[idToArrayIndex(i)];
226226
}
227227
sendPacket();
228228
mutex.unlock();

src/lib/motors/SmartServo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class SmartServoClass
8989
static int constexpr MAX_MOTOR_ID = 6;
9090

9191
inline bool isValidId(int const id) const { return ((id >= MIN_MOTOR_ID) && (id <= MAX_MOTOR_ID)); }
92+
inline int idToArrayIndex(int const id) const { return (id - 1); }
9293

9394
int calcChecksum ();
9495
void sendPacket ();

0 commit comments

Comments
 (0)