MQTT fork

Dependencies:   FP MQTTPacket

Fork of MQTT by MQTT

Committer:
vcoubard
Date:
Thu Sep 07 11:18:53 2017 +0000
Revision:
50:558985f7f210
Parent:
48:187c6d4d7812
Revert Countdown changes and fix invalid use (copy assignment/copy construction) of it in client .

Who changed what in which revision?

UserRevisionLine numberNew contents of line
icraggs 29:833386b16f3e 1 #if !defined(MQTT_MBED_H)
icraggs 29:833386b16f3e 2 #define MQTT_MBED_H
icraggs 29:833386b16f3e 3
icraggs 29:833386b16f3e 4 #include "mbed.h"
icraggs 29:833386b16f3e 5
vcoubard 50:558985f7f210 6 class Countdown : private mbed::NonCopyable<Countdown>
icraggs 29:833386b16f3e 7 {
icraggs 29:833386b16f3e 8 public:
vcoubard 50:558985f7f210 9 Countdown() : t()
icraggs 29:833386b16f3e 10 {
icraggs 29:833386b16f3e 11 }
Jan Jongboom 48:187c6d4d7812 12
vcoubard 50:558985f7f210 13 Countdown(int ms) : t()
icraggs 29:833386b16f3e 14 {
Jan Jongboom 48:187c6d4d7812 15 countdown_ms(ms);
icraggs 29:833386b16f3e 16 }
Jan Jongboom 48:187c6d4d7812 17
icraggs 29:833386b16f3e 18 bool expired()
icraggs 29:833386b16f3e 19 {
vcoubard 50:558985f7f210 20 return t.read_ms() >= interval_end_ms;
icraggs 29:833386b16f3e 21 }
Jan Jongboom 48:187c6d4d7812 22
Jan Jongboom 48:187c6d4d7812 23 void countdown_ms(unsigned long ms)
icraggs 29:833386b16f3e 24 {
vcoubard 50:558985f7f210 25 t.stop();
icraggs 29:833386b16f3e 26 interval_end_ms = ms;
vcoubard 50:558985f7f210 27 t.reset();
vcoubard 50:558985f7f210 28 t.start();
icraggs 29:833386b16f3e 29 }
Jan Jongboom 48:187c6d4d7812 30
icraggs 29:833386b16f3e 31 void countdown(int seconds)
icraggs 29:833386b16f3e 32 {
icraggs 43:21da1f744243 33 countdown_ms((unsigned long)seconds * 1000L);
icraggs 29:833386b16f3e 34 }
Jan Jongboom 48:187c6d4d7812 35
icraggs 29:833386b16f3e 36 int left_ms()
icraggs 29:833386b16f3e 37 {
vcoubard 50:558985f7f210 38 return interval_end_ms - t.read_ms();
icraggs 29:833386b16f3e 39 }
Jan Jongboom 48:187c6d4d7812 40
icraggs 29:833386b16f3e 41 private:
vcoubard 50:558985f7f210 42 Timer t;
Jan Jongboom 48:187c6d4d7812 43 unsigned long interval_end_ms;
icraggs 29:833386b16f3e 44 };
icraggs 29:833386b16f3e 45
icraggs 29:833386b16f3e 46 #endif