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: MBEDLight.cpp
- Revision:
- 90:0fed8d3e0b81
- Parent:
- 89:0af616fdea3b
- Child:
- 91:8732d54328ae
--- a/MBEDLight.cpp Wed Mar 12 23:55:06 2014 +0000 +++ b/MBEDLight.cpp Thu Mar 13 00:07:59 2014 +0000 @@ -23,6 +23,10 @@ // default constructor MBEDLight::MBEDLight(ErrorHandler *error_handler,Transport *transports[NUM_TRANSPORTS],int instance,void *endpoint) : Light(error_handler,transports,instance,endpoint) { + this->m_current_state = LIGHT_DEFAULT_STATE; + if (this->m_current_state == 1) this->on(); + if (this->m_current_state == 0) this->off(); + if (this->m_current_state == 2) this->blink(); } // destructor @@ -30,19 +34,22 @@ } // turn ON - void MBEDLight::on() { this->logger()->led2On(); this->logger()->led3On(); Light::on(); this->logger()->dimRGB(1.0); } + void MBEDLight::on() { this->logger()->led2On(); this->logger()->led3On(); Light::on(); this->logger()->dimRGB(1.0); this->m_current_state = 1; } // turn OFF - void MBEDLight::off() { this->logger()->led2Off(); this->logger()->led3Off(); Light::off(); this->logger()->dimRGB(1.0); } + void MBEDLight::off() { this->logger()->led2Off(); this->logger()->led3Off(); Light::off(); this->logger()->dimRGB(1.0); this->m_current_state = 0;} // Blink void MBEDLight::blink() { - for(int i=0;i<8;++i) { + int current_state = this->m_current_state; + for(int i=0;i<6;++i) { this->on(); wait_ms(500); this->off(); wait_ms(500); } + if (current_state == 1) this->on(); + if (current_state == 0) this->off(); } // dim