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@28:52b7ca6aacd6, 2014-02-28 (annotated)
- Committer:
- ansond
- Date:
- Fri Feb 28 03:10:53 2014 +0000
- Revision:
- 28:52b7ca6aacd6
- Parent:
- 26:791d22d43cb4
- Child:
- 29:9a99f076129a
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:4c9bfcb3e759 | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 0:4c9bfcb3e759 | 2 | * |
ansond | 0:4c9bfcb3e759 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:4c9bfcb3e759 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:4c9bfcb3e759 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:4c9bfcb3e759 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:4c9bfcb3e759 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 0:4c9bfcb3e759 | 8 | * |
ansond | 0:4c9bfcb3e759 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:4c9bfcb3e759 | 10 | * substantial portions of the Software. |
ansond | 0:4c9bfcb3e759 | 11 | * |
ansond | 0:4c9bfcb3e759 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:4c9bfcb3e759 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:4c9bfcb3e759 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:4c9bfcb3e759 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:4c9bfcb3e759 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:4c9bfcb3e759 | 17 | */ |
ansond | 0:4c9bfcb3e759 | 18 | |
ansond | 0:4c9bfcb3e759 | 19 | #include "Light.h" |
ansond | 1:5d332fa199ce | 20 | #include "MBEDEndpoint.h" |
ansond | 0:4c9bfcb3e759 | 21 | |
ansond | 9:90fadae5489a | 22 | // include the relevant action support |
ansond | 9:90fadae5489a | 23 | #include "LightDimmerAction.h" |
ansond | 9:90fadae5489a | 24 | #include "LightSwitchAction.h" |
ansond | 9:90fadae5489a | 25 | |
ansond | 0:4c9bfcb3e759 | 26 | // default constructor |
ansond | 0:4c9bfcb3e759 | 27 | Light::Light(ErrorHandler *error_handler,Transport *transports[NUM_TRANSPORTS],int instance,void *endpoint) { |
ansond | 0:4c9bfcb3e759 | 28 | this->m_error_handler = error_handler; |
ansond | 1:5d332fa199ce | 29 | this->m_resources = ((MBEDEndpoint *)endpoint)->initResourceFactory(); |
ansond | 0:4c9bfcb3e759 | 30 | this->m_endpoint = endpoint; |
ansond | 28:52b7ca6aacd6 | 31 | this->m_ioc_id = 0; |
ansond | 20:f2dbbd852e08 | 32 | for(int i=0;i<NUM_TRANSPORTS;++i) this->m_transports[i] = transports[i]; |
ansond | 16:fda7dbb8b47a | 33 | memset(this->m_name,0,LIGHT_NAME_LEN+1); |
ansond | 0:4c9bfcb3e759 | 34 | sprintf(this->m_name,LIGHT_NAME,instance); |
ansond | 5:c1c4d511b589 | 35 | this->resources()->createResources(this->getName()); |
ansond | 9:90fadae5489a | 36 | |
ansond | 0:4c9bfcb3e759 | 37 | // DEBUG |
ansond | 16:fda7dbb8b47a | 38 | this->logger()->log("Light name: %s", this->getName()); |
ansond | 0:4c9bfcb3e759 | 39 | } |
ansond | 0:4c9bfcb3e759 | 40 | |
ansond | 9:90fadae5489a | 41 | // destructor |
ansond | 9:90fadae5489a | 42 | Light::~Light() { |
ansond | 9:90fadae5489a | 43 | if (this->m_resources != NULL) delete this->m_resources; |
ansond | 26:791d22d43cb4 | 44 | if (this->m_dimmer_action != NULL) delete this->m_dimmer_action; |
ansond | 26:791d22d43cb4 | 45 | if (this->m_switch_action != NULL) delete this->m_switch_action; |
ansond | 0:4c9bfcb3e759 | 46 | } |
ansond | 0:4c9bfcb3e759 | 47 | |
ansond | 21:cfdaee0a2b50 | 48 | // get the resource factory |
ansond | 21:cfdaee0a2b50 | 49 | ResourceFactory *Light::getResourceFactory() { return this->m_resources; } |
ansond | 21:cfdaee0a2b50 | 50 | |
ansond | 9:90fadae5489a | 51 | // set the dimmer action |
ansond | 9:90fadae5489a | 52 | void Light::setDimmerAction(void *dimmer_action) { this->m_dimmer_action = dimmer_action; } |
ansond | 9:90fadae5489a | 53 | |
ansond | 9:90fadae5489a | 54 | // set the switch actino |
ansond | 9:90fadae5489a | 55 | void Light::setSwitchAction(void *switch_action) {this->m_switch_action = switch_action; } |
ansond | 9:90fadae5489a | 56 | |
ansond | 9:90fadae5489a | 57 | // get the dimmer action |
ansond | 9:90fadae5489a | 58 | void *Light::getDimmerAction() { return this->m_dimmer_action; } |
ansond | 9:90fadae5489a | 59 | |
ansond | 9:90fadae5489a | 60 | // get the switch action |
ansond | 9:90fadae5489a | 61 | void *Light::getSwitchAction() { return this->m_switch_action; } |
ansond | 9:90fadae5489a | 62 | |
ansond | 0:4c9bfcb3e759 | 63 | // get the requested transport |
ansond | 0:4c9bfcb3e759 | 64 | Transport *Light::getTransport(int index) { return this->m_transports[index]; } |
ansond | 0:4c9bfcb3e759 | 65 | |
ansond | 0:4c9bfcb3e759 | 66 | // get the light name |
ansond | 0:4c9bfcb3e759 | 67 | char *Light::getName() { return this->m_name; } |
ansond | 1:5d332fa199ce | 68 | |
ansond | 0:4c9bfcb3e759 | 69 | // get the error handler |
ansond | 0:4c9bfcb3e759 | 70 | ErrorHandler *Light::logger() { return this->m_error_handler; } |
ansond | 0:4c9bfcb3e759 | 71 | |
ansond | 1:5d332fa199ce | 72 | // get the resources factory |
ansond | 1:5d332fa199ce | 73 | ResourceFactory *Light::resources() { return this->m_resources; } |
ansond | 1:5d332fa199ce | 74 | |
ansond | 9:90fadae5489a | 75 | // turn ON (base class does nothing) |
ansond | 9:90fadae5489a | 76 | void Light::on() { ; } |
ansond | 9:90fadae5489a | 77 | |
ansond | 9:90fadae5489a | 78 | // turn OFF (base class does nothing) |
ansond | 9:90fadae5489a | 79 | void Light::off() { ; } |
ansond | 9:90fadae5489a | 80 | |
ansond | 9:90fadae5489a | 81 | // dim (base class does nothing) |
ansond | 9:90fadae5489a | 82 | void Light::dim(int value) { ; } |
ansond | 9:90fadae5489a | 83 | |
ansond | 28:52b7ca6aacd6 | 84 | // set the IOC ID |
ansond | 28:52b7ca6aacd6 | 85 | void Light::setIOCID(int ioc_id) { this->m_ioc_id = ioc_id; } |
ansond | 28:52b7ca6aacd6 | 86 | |
ansond | 28:52b7ca6aacd6 | 87 | // get the IOC ID |
ansond | 28:52b7ca6aacd6 | 88 | int Light::getIOCID() { return this->m_ioc_id; } |
ansond | 28:52b7ca6aacd6 | 89 | |
ansond | 28:52b7ca6aacd6 | 90 | |
ansond | 0:4c9bfcb3e759 | 91 | |
ansond | 0:4c9bfcb3e759 | 92 |