Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit 9cd57c8

Browse files
Fixed do_blink to use loop instead of recursive call. (#148)
* Fixed do_blink to use loop instead of recursive call.
1 parent ece732d commit 9cd57c8

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

main.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,23 @@ class LedResource {
208208
Thread blinky_thread;
209209
BlinkArgs *blink_args;
210210
void do_blink() {
211-
// blink the LED
212-
red_led = !red_led;
213-
// up the position, if we reached the end of the vector
214-
if (blink_args->position >= blink_args->blink_pattern.size()) {
215-
// send delayed response after blink is done
216-
M2MObjectInstance* inst = led_object->object_instance();
217-
M2MResource* led_res = inst->resource("5850");
218-
led_res->send_delayed_post_response();
219-
red_led = 1;
220-
status_ticker.attach_us(blinky, 250000);
221-
return;
211+
for (;;) {
212+
// blink the LED
213+
red_led = !red_led;
214+
// up the position, if we reached the end of the vector
215+
if (blink_args->position >= blink_args->blink_pattern.size()) {
216+
// send delayed response after blink is done
217+
M2MObjectInstance* inst = led_object->object_instance();
218+
M2MResource* led_res = inst->resource("5850");
219+
led_res->send_delayed_post_response();
220+
red_led = 1;
221+
status_ticker.attach_us(blinky, 250000);
222+
return;
223+
}
224+
// Wait requested time, then continue prosessing the blink pattern from next position.
225+
Thread::wait(blink_args->blink_pattern.at(blink_args->position));
226+
blink_args->position++;
222227
}
223-
// Invoke same function after `delay_ms` (upping position)
224-
Thread::wait(blink_args->blink_pattern.at(blink_args->position));
225-
blink_args->position++;
226-
do_blink();
227228
}
228229
};
229230

0 commit comments

Comments
 (0)