Jack Hansdampf / mbed-mqtt-GSOE1

Dependents:   ESP8266MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Timer.h Source File

Timer.h

00001 /**************************************************************************************
00002  * Copyright (c) 2016, Tomoaki Yamaguchi
00003  *
00004  * All rights reserved. This program and the accompanying materials
00005  * are made available under the terms of the Eclipse Public License v1.0
00006  * and Eclipse Distribution License v1.0 which accompany this distribution.
00007  *
00008  * The Eclipse Public License is available at
00009  *    http://www.eclipse.org/legal/epl-v10.html
00010  * and the Eclipse Distribution License is available at
00011  *   http://www.eclipse.org/org/documents/edl-v10.php.
00012  *
00013  * Contributors:
00014  *    Tomoaki Yamaguchi - initial API and implementation 
00015  **************************************************************************************/
00016 #ifndef MQTTSNGATEWAY_SRC_LINUX_TIMER_H_
00017 #define MQTTSNGATEWAY_SRC_LINUX_TIMER_H_
00018 
00019 #include <stdint.h>
00020 #include <sys/time.h>
00021 #include "MQTTSNGWDefines.h"
00022 
00023 namespace MQTTSNGW
00024 {
00025 /*==========================================================
00026  *           Light Indicators
00027  ===========================================================*/
00028 #define MAX_GPIO                27    // GPIO02 - GPIO27
00029 #define LIGHT_INDICATOR_GREEN   23    // RPi connector 16
00030 #define LIGHT_INDICATOR_RED     24    // RPi connector 18
00031 #define LIGHT_INDICATOR_BLUE    25    // RPi connector 22
00032 
00033 /*============================================
00034  Timer
00035  ============================================*/
00036 class Timer
00037 {
00038 public:
00039     Timer(void);
00040     ~Timer(void);
00041     void start(uint32_t msecs = 0);
00042     bool isTimeup(void);
00043     bool isTimeup(uint32_t msecs);
00044     void stop();
00045 
00046 private:
00047     struct timeval _startTime;
00048     uint32_t _millis;
00049 };
00050 
00051 /*=====================================
00052  Class LightIndicator
00053  =====================================*/
00054 class LightIndicator
00055 {
00056 public:
00057     LightIndicator();
00058     ~LightIndicator();
00059     void greenLight(bool on);
00060     void blueLight(bool on);
00061     void redLight(bool on);
00062     void allLightOff(void);
00063 
00064 private:
00065     void init();
00066     int  lit(int gpioNo, const char* onoff);
00067     void pinMode(int gpioNo);
00068     bool _greenStatus;
00069     int _gpio[MAX_GPIO + 1];
00070 };
00071 
00072 }
00073 
00074 #endif /* MQTTSNGATEWAY_SRC_LINUX_TIMER_H_ */