Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MQTT by
MQTTmbed.h@51:5042d7e56f7e, 2017-09-25 (annotated)
- Committer:
- icraggs
- Date:
- Mon Sep 25 11:00:18 2017 +0000
- Revision:
- 51:5042d7e56f7e
- Parent:
- 43:21da1f744243
- Child:
- 52:3f9919941b86
Change Timer initialization in Countdown class to avoid copy constructor
Who changed what in which revision?
| User | Revision | Line number | New 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 | 51:5042d7e56f7e | 9 | Countdown() : t() |
| icraggs | 29:833386b16f3e | 10 | { |
| icraggs | 51:5042d7e56f7e | 11 | |
| icraggs | 29:833386b16f3e | 12 | } |
| icraggs | 29:833386b16f3e | 13 | |
| icraggs | 51:5042d7e56f7e | 14 | Countdown(int ms) : t() |
| icraggs | 29:833386b16f3e | 15 | { |
| icraggs | 29:833386b16f3e | 16 | countdown_ms(ms); |
| icraggs | 29:833386b16f3e | 17 | } |
| icraggs | 29:833386b16f3e | 18 | |
| icraggs | 29:833386b16f3e | 19 | |
| icraggs | 29:833386b16f3e | 20 | bool expired() |
| icraggs | 29:833386b16f3e | 21 | { |
| icraggs | 29:833386b16f3e | 22 | return t.read_ms() >= interval_end_ms; |
| icraggs | 29:833386b16f3e | 23 | } |
| icraggs | 29:833386b16f3e | 24 | |
| icraggs | 43:21da1f744243 | 25 | void countdown_ms(unsigned long ms) |
| icraggs | 29:833386b16f3e | 26 | { |
| icraggs | 29:833386b16f3e | 27 | t.stop(); |
| icraggs | 29:833386b16f3e | 28 | interval_end_ms = ms; |
| icraggs | 29:833386b16f3e | 29 | t.reset(); |
| icraggs | 29:833386b16f3e | 30 | t.start(); |
| icraggs | 29:833386b16f3e | 31 | } |
| icraggs | 29:833386b16f3e | 32 | |
| icraggs | 29:833386b16f3e | 33 | void countdown(int seconds) |
| icraggs | 29:833386b16f3e | 34 | { |
| icraggs | 43:21da1f744243 | 35 | countdown_ms((unsigned long)seconds * 1000L); |
| icraggs | 29:833386b16f3e | 36 | } |
| icraggs | 29:833386b16f3e | 37 | |
| icraggs | 29:833386b16f3e | 38 | int left_ms() |
| icraggs | 29:833386b16f3e | 39 | { |
| icraggs | 29:833386b16f3e | 40 | return interval_end_ms - t.read_ms(); |
| icraggs | 29:833386b16f3e | 41 | } |
| icraggs | 29:833386b16f3e | 42 | |
| icraggs | 29:833386b16f3e | 43 | private: |
| icraggs | 29:833386b16f3e | 44 | Timer t; |
| icraggs | 43:21da1f744243 | 45 | unsigned long interval_end_ms; |
| icraggs | 29:833386b16f3e | 46 | }; |
| icraggs | 29:833386b16f3e | 47 | |
| icraggs | 29:833386b16f3e | 48 | #endif |
