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
ExternalLEDLight.cpp@192:54b758a8eaaa, 2014-09-26 (annotated)
- Committer:
- ansond
- Date:
- Fri Sep 26 05:16:07 2014 +0000
- Revision:
- 192:54b758a8eaaa
- Parent:
- 144:e4d24c2c8f18
updates to new logger name
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 105:759dee018363 | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 105:759dee018363 | 2 | * |
ansond | 105:759dee018363 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 105:759dee018363 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 105:759dee018363 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 105:759dee018363 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 105:759dee018363 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 105:759dee018363 | 8 | * |
ansond | 105:759dee018363 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 105:759dee018363 | 10 | * substantial portions of the Software. |
ansond | 105:759dee018363 | 11 | * |
ansond | 105:759dee018363 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 105:759dee018363 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 105:759dee018363 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 105:759dee018363 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 105:759dee018363 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 105:759dee018363 | 17 | */ |
ansond | 105:759dee018363 | 18 | |
ansond | 105:759dee018363 | 19 | #include "ExternalLEDLight.h" |
ansond | 143:1388cb37c27e | 20 | |
ansond | 144:e4d24c2c8f18 | 21 | //#ifdef COPCAR_PERSONALITY |
ansond | 144:e4d24c2c8f18 | 22 | // PwmOut _ext_led_extra_pwm(EXT_LED_PIN_COPCAR); |
ansond | 144:e4d24c2c8f18 | 23 | //#endif |
ansond | 105:759dee018363 | 24 | |
ansond | 105:759dee018363 | 25 | // default constructor |
ansond | 192:54b758a8eaaa | 26 | ExternalLEDLight::ExternalLEDLight(PwmOut *led,Logger *logger) : BaseClass(logger,NULL) { |
ansond | 105:759dee018363 | 27 | this->m_led = led; |
ansond | 105:759dee018363 | 28 | this->m_dimming = false; |
ansond | 142:b7a75144b0f1 | 29 | sscanf(LIGHT_DEFAULT_STATE,"%d",&this->m_state); |
ansond | 105:759dee018363 | 30 | sscanf(LIGHT_DIM_STATE,"%f",&this->m_dim); |
ansond | 105:759dee018363 | 31 | } |
ansond | 105:759dee018363 | 32 | |
ansond | 105:759dee018363 | 33 | // destructor |
ansond | 105:759dee018363 | 34 | ExternalLEDLight::~ExternalLEDLight() { |
ansond | 144:e4d24c2c8f18 | 35 | if (this->m_led != NULL) delete this->m_led; |
ansond | 105:759dee018363 | 36 | } |
ansond | 105:759dee018363 | 37 | |
ansond | 105:759dee018363 | 38 | // turn the light on |
ansond | 105:759dee018363 | 39 | void ExternalLEDLight::on() { this->m_state = 1; this->m_dimming = false; this->update(); } |
ansond | 105:759dee018363 | 40 | |
ansond | 105:759dee018363 | 41 | // turn the light off |
ansond | 105:759dee018363 | 42 | void ExternalLEDLight::off() { this->m_state = 0; this->m_dimming = false; this->update(); } |
ansond | 105:759dee018363 | 43 | |
ansond | 105:759dee018363 | 44 | // dim the light (dim is between 0 and 100) |
ansond | 105:759dee018363 | 45 | void ExternalLEDLight::dim(int dim) { this->m_dim = (float)(dim/100.0); this->m_dimming = true; this->update(); } |
ansond | 105:759dee018363 | 46 | |
ansond | 105:759dee018363 | 47 | // set the light state |
ansond | 105:759dee018363 | 48 | void ExternalLEDLight::update() { |
ansond | 105:759dee018363 | 49 | if (this->m_dimming) { |
ansond | 105:759dee018363 | 50 | // dim the light |
ansond | 105:759dee018363 | 51 | *(this->m_led) = this->m_dim; |
ansond | 105:759dee018363 | 52 | } |
ansond | 105:759dee018363 | 53 | else { |
ansond | 105:759dee018363 | 54 | // turn the light on or off |
ansond | 108:673b2f43dfe7 | 55 | if (this->m_state == 0) { |
ansond | 108:673b2f43dfe7 | 56 | // just turn the LED off |
ansond | 108:673b2f43dfe7 | 57 | *(this->m_led) = 0; |
ansond | 144:e4d24c2c8f18 | 58 | //#ifdef COPCAR_PERSONALITY |
ansond | 144:e4d24c2c8f18 | 59 | // _ext_led_extra_pwm = 0; |
ansond | 144:e4d24c2c8f18 | 60 | //#endif |
ansond | 108:673b2f43dfe7 | 61 | } |
ansond | 107:db7af0f306fa | 62 | else { |
ansond | 108:673b2f43dfe7 | 63 | // turn the LED on - but re-adjust for the current dim setting: |
ansond | 108:673b2f43dfe7 | 64 | // - if the dimming is set to 0, then lets go ahead and make the light full bright... |
ansond | 108:673b2f43dfe7 | 65 | // - otherwise we wont see the transition change. |
ansond | 143:1388cb37c27e | 66 | if (this->m_dim == 0.0) { |
ansond | 107:db7af0f306fa | 67 | *(this->m_led) = 1; |
ansond | 144:e4d24c2c8f18 | 68 | //#ifdef COPCAR_PERSONALITY |
ansond | 144:e4d24c2c8f18 | 69 | // _ext_led_extra_pwm = 1; |
ansond | 144:e4d24c2c8f18 | 70 | //#endif |
ansond | 143:1388cb37c27e | 71 | } |
ansond | 143:1388cb37c27e | 72 | else { |
ansond | 108:673b2f43dfe7 | 73 | *(this->m_led) = this->m_dim; |
ansond | 143:1388cb37c27e | 74 | } |
ansond | 107:db7af0f306fa | 75 | } |
ansond | 105:759dee018363 | 76 | } |
ansond | 135:7f3f963cd159 | 77 | } |