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
Light.cpp
- Committer:
- ansond
- Date:
- 2014-02-28
- Revision:
- 32:56a11a9a35a2
- Parent:
- 29:9a99f076129a
- Child:
- 33:339eb862a4c4
File content as of revision 32:56a11a9a35a2:
/* 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()); // 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; // DEBUG if (PL_ENABLE) this->logger()->log("Light name: %s (Philips Light %d)",this->getName(),PL_LIGHT_ID); else 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; } // get the Philips light PhilipsLight *Light::pl() { return this->m_pl; } // 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 void Light::on() { if (PL_ENABLE && this->pl() != NULL) this->pl()->on(); } // turn OFF void Light::off() { if (PL_ENABLE && this->pl() != NULL) this->pl()->off(); } // dim void Light::dim(int value) { if (PL_ENABLE && this->pl() != NULL) this->pl()->dim(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; }