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
LightSwitchAction.cpp@192:54b758a8eaaa, 2014-09-26 (annotated)
- Committer:
- ansond
- Date:
- Fri Sep 26 05:16:07 2014 +0000
- Revision:
- 192:54b758a8eaaa
- Parent:
- 87:e9d77e9f9eae
updates to new logger name
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 9:90fadae5489a | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 9:90fadae5489a | 2 | * |
ansond | 9:90fadae5489a | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 9:90fadae5489a | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 9:90fadae5489a | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 9:90fadae5489a | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 9:90fadae5489a | 7 | * furnished to do so, subject to the following conditions: |
ansond | 9:90fadae5489a | 8 | * |
ansond | 9:90fadae5489a | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 9:90fadae5489a | 10 | * substantial portions of the Software. |
ansond | 9:90fadae5489a | 11 | * |
ansond | 9:90fadae5489a | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 9:90fadae5489a | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 9:90fadae5489a | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 9:90fadae5489a | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 9:90fadae5489a | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 9:90fadae5489a | 17 | */ |
ansond | 9:90fadae5489a | 18 | |
ansond | 9:90fadae5489a | 19 | #include "LightSwitchAction.h" |
ansond | 9:90fadae5489a | 20 | |
ansond | 9:90fadae5489a | 21 | // default constructor |
ansond | 192:54b758a8eaaa | 22 | LightSwitchAction::LightSwitchAction(Logger *logger,Light *light) : Action(logger) { |
ansond | 9:90fadae5489a | 23 | this->m_light = light; |
ansond | 9:90fadae5489a | 24 | } |
ansond | 9:90fadae5489a | 25 | |
ansond | 9:90fadae5489a | 26 | // destructor |
ansond | 9:90fadae5489a | 27 | LightSwitchAction::~LightSwitchAction() { |
ansond | 9:90fadae5489a | 28 | } |
ansond | 9:90fadae5489a | 29 | |
ansond | 21:cfdaee0a2b50 | 30 | // Toggle the Light Switch |
ansond | 21:cfdaee0a2b50 | 31 | void LightSwitchAction::toggle() { |
ansond | 21:cfdaee0a2b50 | 32 | ResourceFactory *resource = this->light()->getResourceFactory(); |
ansond | 21:cfdaee0a2b50 | 33 | char *value = resource->getResourceValue(SWITCH_RESOURCE); |
ansond | 21:cfdaee0a2b50 | 34 | if (value != NULL && strcmp(value,"1") == 0) { |
ansond | 21:cfdaee0a2b50 | 35 | this->logger()->log("Turning Light: %s ON",this->light()->getName()); |
ansond | 21:cfdaee0a2b50 | 36 | this->on(); |
ansond | 21:cfdaee0a2b50 | 37 | } |
ansond | 87:e9d77e9f9eae | 38 | else if (value != NULL && strcmp(value,"2") == 0) { |
ansond | 87:e9d77e9f9eae | 39 | this->logger()->log("Blinking Light: %s...",this->light()->getName()); |
ansond | 87:e9d77e9f9eae | 40 | this->blink(); |
ansond | 87:e9d77e9f9eae | 41 | } |
ansond | 21:cfdaee0a2b50 | 42 | else { |
ansond | 21:cfdaee0a2b50 | 43 | this->logger()->log("Turning Light: %s OFF",this->light()->getName()); |
ansond | 21:cfdaee0a2b50 | 44 | this->off(); |
ansond | 21:cfdaee0a2b50 | 45 | } |
ansond | 21:cfdaee0a2b50 | 46 | } |
ansond | 21:cfdaee0a2b50 | 47 | |
ansond | 9:90fadae5489a | 48 | // Light turned ON |
ansond | 9:90fadae5489a | 49 | void LightSwitchAction::on() { this->light()->on(); } |
ansond | 9:90fadae5489a | 50 | |
ansond | 9:90fadae5489a | 51 | // Light turned OFF |
ansond | 9:90fadae5489a | 52 | void LightSwitchAction::off() { this->light()->off(); } |
ansond | 87:e9d77e9f9eae | 53 | |
ansond | 87:e9d77e9f9eae | 54 | // Blink light |
ansond | 87:e9d77e9f9eae | 55 | void LightSwitchAction::blink() { this->light()->blink(); } |
ansond | 9:90fadae5489a | 56 | |
ansond | 9:90fadae5489a | 57 | // get the light |
ansond | 9:90fadae5489a | 58 | Light *LightSwitchAction::light() { return this->m_light; } |