USE YHTANG AWS ACCOUNT TO TEST MQTT

Dependencies:   MQTTPacket FP

Dependents:   NuMaker-mbed-AWS-IoT-example

Committer:
Jan Jongboom
Date:
Thu Sep 07 09:53:04 2017 +0100
Revision:
48:187c6d4d7812
Parent:
47:f313853d22a6
Child:
50:c37c8236e84a
Countdown - free Timer when destructing object

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
icraggs 29:833386b16f3e 6 class Countdown
icraggs 29:833386b16f3e 7 {
icraggs 29:833386b16f3e 8 public:
icraggs 29:833386b16f3e 9 Countdown()
icraggs 29:833386b16f3e 10 {
Jan Jongboom 48:187c6d4d7812 11 t = new Timer();
icraggs 29:833386b16f3e 12 }
Jan Jongboom 48:187c6d4d7812 13
icraggs 29:833386b16f3e 14 Countdown(int ms)
icraggs 29:833386b16f3e 15 {
RobMeades 47:f313853d22a6 16 t = new Timer();
Jan Jongboom 48:187c6d4d7812 17 countdown_ms(ms);
icraggs 29:833386b16f3e 18 }
Jan Jongboom 48:187c6d4d7812 19
Jan Jongboom 48:187c6d4d7812 20 ~Countdown()
Jan Jongboom 48:187c6d4d7812 21 {
Jan Jongboom 48:187c6d4d7812 22 delete t;
Jan Jongboom 48:187c6d4d7812 23 }
Jan Jongboom 48:187c6d4d7812 24
icraggs 29:833386b16f3e 25 bool expired()
icraggs 29:833386b16f3e 26 {
RobMeades 47:f313853d22a6 27 return t->read_ms() >= interval_end_ms;
icraggs 29:833386b16f3e 28 }
Jan Jongboom 48:187c6d4d7812 29
Jan Jongboom 48:187c6d4d7812 30 void countdown_ms(unsigned long ms)
icraggs 29:833386b16f3e 31 {
RobMeades 47:f313853d22a6 32 t->stop();
icraggs 29:833386b16f3e 33 interval_end_ms = ms;
RobMeades 47:f313853d22a6 34 t->reset();
RobMeades 47:f313853d22a6 35 t->start();
icraggs 29:833386b16f3e 36 }
Jan Jongboom 48:187c6d4d7812 37
icraggs 29:833386b16f3e 38 void countdown(int seconds)
icraggs 29:833386b16f3e 39 {
icraggs 43:21da1f744243 40 countdown_ms((unsigned long)seconds * 1000L);
icraggs 29:833386b16f3e 41 }
Jan Jongboom 48:187c6d4d7812 42
icraggs 29:833386b16f3e 43 int left_ms()
icraggs 29:833386b16f3e 44 {
RobMeades 47:f313853d22a6 45 return interval_end_ms - t->read_ms();
icraggs 29:833386b16f3e 46 }
Jan Jongboom 48:187c6d4d7812 47
icraggs 29:833386b16f3e 48 private:
RobMeades 47:f313853d22a6 49 Timer *t;
Jan Jongboom 48:187c6d4d7812 50 unsigned long interval_end_ms;
icraggs 29:833386b16f3e 51 };
icraggs 29:833386b16f3e 52
icraggs 29:833386b16f3e 53 #endif