|
35 | 35 | #define RED_LED (LED3)
|
36 | 36 | #define GREEN_LED (LED1)
|
37 | 37 | #define BLUE_LED (LED2)
|
38 |
| -#define LED_ON (1) |
| 38 | +#define LED_ON (1) |
39 | 39 | #else // !TARGET_STM
|
40 | 40 | #define RED_LED (LED1)
|
41 | 41 | #define GREEN_LED (LED2)
|
42 |
| -#define BLUE_LED (LED3) |
43 |
| -#define LED_ON (0) |
| 42 | +#define BLUE_LED (LED3) |
| 43 | +#define LED_ON (0) |
44 | 44 | #endif // !TARGET_STM
|
45 | 45 | #define LED_OFF (!LED_ON)
|
46 | 46 |
|
| 47 | +#define BLINK_SIGNAL 0x1 |
| 48 | + |
47 | 49 | // Status indication
|
48 | 50 | DigitalOut red_led(RED_LED);
|
49 | 51 | DigitalOut green_led(GREEN_LED);
|
@@ -103,6 +105,7 @@ class LedResource {
|
103 | 105 | public:
|
104 | 106 | LedResource() {
|
105 | 107 | // create ObjectID with metadata tag of '3201', which is 'digital output'
|
| 108 | + blinky_thread.start(callback(this, &LedResource::do_blink)); |
106 | 109 | led_object = M2MInterfaceFactory::create_object("3201");
|
107 | 110 | M2MObjectInstance* led_inst = led_object->create_object_instance();
|
108 | 111 |
|
@@ -176,30 +179,33 @@ class LedResource {
|
176 | 179 | printf("Payload: %.*s\n", payload_length, payload);
|
177 | 180 | }
|
178 | 181 | // do_blink is called with the vector, and starting at -1
|
179 |
| - blinky_thread.start(callback(this, &LedResource::do_blink)); |
| 182 | + blinky_thread.signal_set(BLINK_SIGNAL); |
180 | 183 | }
|
181 | 184 |
|
182 | 185 | private:
|
183 | 186 | M2MObject* led_object;
|
184 | 187 | Thread blinky_thread;
|
185 | 188 | BlinkArgs *blink_args;
|
186 | 189 | void do_blink() {
|
187 |
| - for (;;) { |
188 |
| - // blink the LED |
189 |
| - red_led = !red_led; |
190 |
| - // up the position, if we reached the end of the vector |
191 |
| - if (blink_args->position >= blink_args->blink_pattern.size()) { |
192 |
| - // send delayed response after blink is done |
193 |
| - M2MObjectInstance* inst = led_object->object_instance(); |
194 |
| - M2MResource* led_res = inst->resource("5850"); |
195 |
| - led_res->send_delayed_post_response(); |
196 |
| - red_led = LED_OFF; |
197 |
| - status_ticker.attach_us(blinky, 250000); |
198 |
| - return; |
199 |
| - } |
200 |
| - // Wait requested time, then continue processing the blink pattern from next position. |
201 |
| - Thread::wait(blink_args->blink_pattern.at(blink_args->position)); |
202 |
| - blink_args->position++; |
| 190 | + for(;;) { |
| 191 | + blinky_thread.signal_wait(BLINK_SIGNAL); |
| 192 | + for (;;) { |
| 193 | + // blink the LED |
| 194 | + red_led = !red_led; |
| 195 | + // up the position, if we reached the end of the vector |
| 196 | + if (blink_args->position >= blink_args->blink_pattern.size()) { |
| 197 | + // send delayed response after blink is done |
| 198 | + M2MObjectInstance* inst = led_object->object_instance(); |
| 199 | + M2MResource* led_res = inst->resource("5850"); |
| 200 | + led_res->send_delayed_post_response(); |
| 201 | + red_led = LED_OFF; |
| 202 | + status_ticker.attach_us(blinky, 250000); |
| 203 | + break; |
| 204 | + } |
| 205 | + // Wait requested time, then continue prosessing the blink pattern from next position. |
| 206 | + Thread::wait(blink_args->blink_pattern.at(blink_args->position)); |
| 207 | + blink_args->position++; |
| 208 | + } |
203 | 209 | }
|
204 | 210 | }
|
205 | 211 | };
|
|
0 commit comments