Core Base Classes for the Light Endpoints
Dependents: mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more
Diff: Light.cpp
- Revision:
- 101:8747b6612e32
- Parent:
- 99:0fa83e641f75
- Child:
- 105:759dee018363
diff -r 41dfe7231da0 -r 8747b6612e32 Light.cpp --- a/Light.cpp Fri Mar 14 21:42:01 2014 +0000 +++ b/Light.cpp Fri Mar 14 21:47:58 2014 +0000 @@ -29,6 +29,7 @@ static void blinking_action(void const *args) { if (_instance != NULL) { Light *self = (Light *)_instance; + self->updateDirection(); while(true) self->blinkLight(); } } @@ -39,6 +40,7 @@ this->m_resources = ((MBEDEndpoint *)endpoint)->initResourceFactory(); this->m_endpoint = endpoint; this->m_ioc_id = 0; + this->m_forward = true; for(int i=0;i<NUM_TRANSPORTS;++i) this->m_transports[i] = transports[i]; memset(this->m_name,0,LIGHT_NAME_LEN+1); sprintf(this->m_name,LIGHT_NAME,instance); @@ -146,17 +148,21 @@ this->m_blinking_thread = NULL; } + // update our blinking sequencing to properly mesh with the lights current state + void Light::updateDirection() { + this->m_forward = true; + if (this->m_current_state == 0) this->m_forward = false; + } + // Blink void Light::blinkLight() { - bool forward = true; - if (this->m_current_state == 0) forward = false; this->m_is_blinking = true; - if (forward) this->on(); else this->off(); - if (PL_ENABLE && this->pl() != NULL) { if (forward) this->pl()->on(); else this->pl()->off(); } + if (this->m_forward) this->on(); else this->off(); + if (PL_ENABLE && this->pl() != NULL) { if (this->m_forward) this->pl()->on(); else this->pl()->off(); } wait_ms(LIGHT_BLINK_WAIT_MS); this->m_is_blinking = true; - if (forward) this->off(); else this->on(); - if (PL_ENABLE && this->pl() != NULL) { if (forward) this->pl()->off(); else this->pl()->on(); } + if (this->m_forward) this->off(); else this->on(); + if (PL_ENABLE && this->pl() != NULL) { if (this->m_forward) this->pl()->off(); else this->pl()->on(); } wait_ms(LIGHT_BLINK_WAIT_MS); }