Vincent (pan-) Coubard / MQTT

Dependencies:   FP MQTTPacket

Fork of MQTT by MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTmbed.h Source File

MQTTmbed.h

00001 #if !defined(MQTT_MBED_H)
00002 #define MQTT_MBED_H
00003 
00004 #include "mbed.h"
00005 
00006 class Countdown : private mbed::NonCopyable<Countdown>
00007 {
00008 public:
00009     Countdown() : t() 
00010     {
00011     }
00012 
00013     Countdown(int ms) : t() 
00014     {
00015         countdown_ms(ms);
00016     }
00017 
00018     bool expired()
00019     {
00020         return t.read_ms() >= interval_end_ms;
00021     }
00022 
00023     void countdown_ms(unsigned long ms)
00024     {
00025         t.stop();
00026         interval_end_ms = ms;
00027         t.reset();
00028         t.start();
00029     }
00030 
00031     void countdown(int seconds)
00032     {
00033         countdown_ms((unsigned long)seconds * 1000L);
00034     }
00035 
00036     int left_ms()
00037     {
00038         return interval_end_ms - t.read_ms();
00039     }
00040 
00041 private:
00042     Timer t;
00043     unsigned long interval_end_ms;
00044 };
00045 
00046 #endif