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

Light.cpp

Committer:
ansond
Date:
2014-02-28
Revision:
28:52b7ca6aacd6
Parent:
26:791d22d43cb4
Child:
29:9a99f076129a

File content as of revision 28:52b7ca6aacd6:

/* Copyright C2013 Doug Anson, MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
 * and associated documentation files the "Software", to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "Light.h"
 #include "MBEDEndpoint.h"
 
 // include the relevant action support
 #include "LightDimmerAction.h"
 #include "LightSwitchAction.h"
 
 // default constructor
 Light::Light(ErrorHandler *error_handler,Transport *transports[NUM_TRANSPORTS],int instance,void *endpoint) {
     this->m_error_handler = error_handler;
     this->m_resources = ((MBEDEndpoint *)endpoint)->initResourceFactory();
     this->m_endpoint = endpoint;
     this->m_ioc_id = 0;
     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);
     this->resources()->createResources(this->getName());
          
     // DEBUG
     this->logger()->log("Light name: %s", this->getName());     
 }
 
 // destructor
 Light::~Light() {   
    if (this->m_resources != NULL) delete this->m_resources;
    if (this->m_dimmer_action != NULL) delete this->m_dimmer_action;
    if (this->m_switch_action != NULL) delete this->m_switch_action;
 }
 
 // get the resource factory
 ResourceFactory *Light::getResourceFactory() { return this->m_resources; }
 
 // set the dimmer action
 void Light::setDimmerAction(void *dimmer_action) { this->m_dimmer_action = dimmer_action; }
 
 // set the switch actino
 void Light::setSwitchAction(void *switch_action) {this->m_switch_action = switch_action; }
 
 // get the dimmer action
 void *Light::getDimmerAction() { return this->m_dimmer_action; }
 
 // get the switch action
 void *Light::getSwitchAction() { return this->m_switch_action; }
 
 // get the requested transport
 Transport *Light::getTransport(int index) { return this->m_transports[index]; }
 
 // get the light name
 char *Light::getName() { return this->m_name; }
  
 // get the error handler
 ErrorHandler *Light::logger() { return this->m_error_handler; }
 
 // get the resources factory
 ResourceFactory *Light::resources() { return this->m_resources; }
 
 // turn ON (base class does nothing)
 void Light::on() { ; }
 
 // turn OFF (base class does nothing)
 void Light::off() { ; }
 
 // dim (base class does nothing)
 void Light::dim(int value) { ; }
 
 // set the IOC ID
 void Light::setIOCID(int ioc_id) { this->m_ioc_id = ioc_id; }
 
 // get the IOC ID
 int Light::getIOCID() { return this->m_ioc_id; }