Skip to content

Commit 9d5bd76

Browse files
committed
Extend API of begin to disable waiting for all motors to be connected.
1 parent 41e920c commit 9d5bd76

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/Braccio++.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ BraccioClass::BraccioClass()
9393
* PUBLIC MEMBER FUNCTIONS
9494
**************************************************************************************/
9595

96-
bool BraccioClass::begin(voidFuncPtr custom_menu)
96+
bool BraccioClass::begin(voidFuncPtr custom_menu, bool const wait_for_all_motor_connected)
9797
{
9898
static int constexpr RS485_RX_PIN = 1;
9999

@@ -140,13 +140,16 @@ bool BraccioClass::begin(voidFuncPtr custom_menu)
140140

141141
_motors_connected_thd.start(mbed::callback(this, &BraccioClass::motorConnectedThreadFunc));
142142

143-
/* Wait for all motors to be actually connected. */
144-
for (int id = SmartServoClass::MIN_MOTOR_ID; id <= SmartServoClass::MAX_MOTOR_ID; id++)
143+
if (wait_for_all_motor_connected)
145144
{
146-
auto const start = millis();
147-
auto isTimeout = [start]() -> bool { return ((millis() - start) > 5000); };
148-
for(; !isTimeout() && !connected(id); delay(100)) { }
149-
if (isTimeout()) return false;
145+
/* Wait for all motors to be actually connected. */
146+
for (int id = SmartServoClass::MIN_MOTOR_ID; id <= SmartServoClass::MAX_MOTOR_ID; id++)
147+
{
148+
auto const start = millis();
149+
auto isTimeout = [start]() -> bool { return ((millis() - start) > 5000); };
150+
for(; !isTimeout() && !connected(id); delay(100)) { }
151+
if (isTimeout()) return false;
152+
}
150153
}
151154

152155
return true;

src/Braccio++.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class BraccioClass
6565
BraccioClass();
6666

6767
inline bool begin() { return begin(nullptr); }
68-
bool begin(voidFuncPtr custom_menu);
69-
68+
bool begin(voidFuncPtr custom_menu, bool const wait_for_all_motor_connected = true);
7069

7170
void pingOn();
7271
void pingOff();

0 commit comments

Comments
 (0)