Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Revision:
105:759dee018363
Parent:
101:8747b6612e32
Child:
115:4e13cc450568
diff -r 7a96a9a7cafb -r 759dee018363 Light.cpp
--- a/Light.cpp	Sun Mar 16 03:09:02 2014 +0000
+++ b/Light.cpp	Sun Mar 16 04:35:20 2014 +0000
@@ -53,6 +53,10 @@
      // Setup Philips Light if enabled
      if (PL_ENABLE) this->m_pl = new PhilipsLight(PL_LIGHT_ID,this->m_transports[HTTP_TRANSPORT],this->logger());
      else this->m_pl = NULL;
+     
+     // Setup External LED Light if enabled
+     if (EXT_LED_ENABLE) this->m_ext_led = new ExternalLEDLight(new PwmOut(EXT_LED_PIN),this->logger());
+     else this->m_ext_led = NULL;
           
      // DEBUG
      if (PL_ENABLE) this->logger()->log("Light name: %s (Philips Light %d)",this->getName(),PL_LIGHT_ID);   
@@ -68,6 +72,7 @@
     if (this->m_dimmer_action != NULL) delete this->m_dimmer_action;
     if (this->m_switch_action != NULL) delete this->m_switch_action;
     if (this->m_pl != NULL) delete this->m_pl;
+    if (this->m_ext_led != NULL) delete this->m_ext_led;
     this->stopBlinkingThread();
  }
  
@@ -83,6 +88,9 @@
  // get the Philips light
  PhilipsLight *Light::pl() { return this->m_pl; }
  
+ // get the External LED light
+ ExternalLEDLight *Light::extled() { return this->m_ext_led; }
+ 
  // set the dimmer action
  void Light::setDimmerAction(void *dimmer_action) { this->m_dimmer_action = dimmer_action; }
  
@@ -108,10 +116,20 @@
  ResourceFactory *Light::resources() { return this->m_resources; }
   
  // turn ON 
- void Light::on() { this->m_current_state = 1; this->manageBlinkingThread();  if (PL_ENABLE && this->pl() != NULL) this->pl()->on(); }
+ void Light::on() { 
+    this->m_current_state = 1; 
+    this->manageBlinkingThread();  
+    if (PL_ENABLE && this->pl() != NULL) this->pl()->on(); 
+    if (EXT_LED_ENABLE && this->extled() != NULL) this->extled()->on();
+ }
  
  // turn OFF 
- void Light::off() {  this->m_current_state = 0; this->manageBlinkingThread(); if (PL_ENABLE && this->pl() != NULL) this->pl()->off(); }
+ void Light::off() {  
+    this->m_current_state = 0; 
+    this->manageBlinkingThread(); 
+    if (PL_ENABLE && this->pl() != NULL) this->pl()->off(); 
+    if (EXT_LED_ENABLE && this->extled() != NULL) this->extled()->off();
+ }
  
  // initiate blinking
  void Light::blink() {
@@ -159,15 +177,20 @@
     this->m_is_blinking = true;
     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(); }
+    if (EXT_LED_ENABLE && this->extled() != NULL) { if (this->m_forward) this->extled()->on(); else this->extled()->off(); }
     wait_ms(LIGHT_BLINK_WAIT_MS);
     this->m_is_blinking = true;
     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(); }
+    if (EXT_LED_ENABLE && this->extled() != NULL) { if (this->m_forward) this->extled()->off(); else this->extled()->on(); }
     wait_ms(LIGHT_BLINK_WAIT_MS);
   }
   
  // dim 
- void Light::dim(int value) { if (PL_ENABLE && this->pl() != NULL) this->pl()->dim(value); }
+ void Light::dim(int value) { 
+    if (PL_ENABLE && this->pl() != NULL) this->pl()->dim(value); 
+    if (EXT_LED_ENABLE && this->extled() != NULL) this->extled()->dim(value);
+ }
  
  // set the IOC ID
  void Light::setIOCID(int ioc_id) { this->m_ioc_id = ioc_id; }