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

Committer:
ansond
Date:
Fri Sep 26 05:16:07 2014 +0000
Revision:
192:54b758a8eaaa
Parent:
188:56fccf5f919b
updates to new logger name

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 144:e4d24c2c8f18 1 /* Copyright C2013 Doug Anson, MIT License
ansond 144:e4d24c2c8f18 2 *
ansond 144:e4d24c2c8f18 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 144:e4d24c2c8f18 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 144:e4d24c2c8f18 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 144:e4d24c2c8f18 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 144:e4d24c2c8f18 7 * furnished to do so, subject to the following conditions:
ansond 144:e4d24c2c8f18 8 *
ansond 144:e4d24c2c8f18 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 144:e4d24c2c8f18 10 * substantial portions of the Software.
ansond 144:e4d24c2c8f18 11 *
ansond 144:e4d24c2c8f18 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 144:e4d24c2c8f18 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 144:e4d24c2c8f18 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 144:e4d24c2c8f18 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 144:e4d24c2c8f18 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 144:e4d24c2c8f18 17 */
ansond 144:e4d24c2c8f18 18
ansond 144:e4d24c2c8f18 19 #include "CopCarLEDFlasher.h"
ansond 144:e4d24c2c8f18 20
ansond 144:e4d24c2c8f18 21 // default constructor
ansond 192:54b758a8eaaa 22 CopCarLEDFlasher::CopCarLEDFlasher(PwmOut *led1,PwmOut *led2,Logger *logger) : ExternalLEDLight(led1,logger) {
ansond 144:e4d24c2c8f18 23 this->m_led2 = led2;
ansond 146:8c05a119d9d4 24 this->m_toggle = false;
ansond 144:e4d24c2c8f18 25 }
ansond 144:e4d24c2c8f18 26
ansond 144:e4d24c2c8f18 27 // destructor
ansond 144:e4d24c2c8f18 28 CopCarLEDFlasher::~CopCarLEDFlasher() {
ansond 144:e4d24c2c8f18 29 if (this->m_led2 != NULL) delete this->m_led2;
ansond 144:e4d24c2c8f18 30 }
ansond 146:8c05a119d9d4 31
ansond 146:8c05a119d9d4 32 // turn the light on
ansond 146:8c05a119d9d4 33 void CopCarLEDFlasher::on() { this->m_state = 1; this->update(); }
ansond 146:8c05a119d9d4 34
ansond 146:8c05a119d9d4 35 // turn the light off
ansond 146:8c05a119d9d4 36 void CopCarLEDFlasher::off() { this->m_state = 0; this->update(); }
ansond 144:e4d24c2c8f18 37
ansond 144:e4d24c2c8f18 38 // set the light state
ansond 144:e4d24c2c8f18 39 void CopCarLEDFlasher::update() {
ansond 144:e4d24c2c8f18 40 // turn the light on or off
ansond 144:e4d24c2c8f18 41 if (this->m_state == 0) {
ansond 144:e4d24c2c8f18 42 *(this->m_led2) = 0;
ansond 146:8c05a119d9d4 43 *(this->m_led) = 0;
ansond 144:e4d24c2c8f18 44 }
ansond 188:56fccf5f919b 45 if (this->m_state == 1 || this->m_state == 2) {
ansond 146:8c05a119d9d4 46 if (this->m_toggle) {
ansond 146:8c05a119d9d4 47 *(this->m_led2) = 1;
ansond 146:8c05a119d9d4 48 *(this->m_led) = 0;
ansond 146:8c05a119d9d4 49 }
ansond 146:8c05a119d9d4 50 else {
ansond 146:8c05a119d9d4 51 *(this->m_led2) = 0;
ansond 146:8c05a119d9d4 52 *(this->m_led) = 1;
ansond 146:8c05a119d9d4 53 }
ansond 146:8c05a119d9d4 54 this->m_toggle = !this->m_toggle;
ansond 144:e4d24c2c8f18 55 }
ansond 144:e4d24c2c8f18 56 }