cc
MQTTmbed.h@50:3a01977eeebc, 2022-06-10 (annotated)
- Committer:
- badri_rym
- Date:
- Fri Jun 10 12:51:45 2022 +0000
- Revision:
- 50:3a01977eeebc
- Parent:
- 49:c66fdbb9eb83
cc
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: |
mapellil | 49:c66fdbb9eb83 | 9 | Countdown() { |
mapellil | 49:c66fdbb9eb83 | 10 | t = new Timer(); |
mapellil | 49:c66fdbb9eb83 | 11 | if (t == NULL) printf ("Countdown newfail\n\r"); |
icraggs | 29:833386b16f3e | 12 | } |
icraggs | 29:833386b16f3e | 13 | |
mapellil | 49:c66fdbb9eb83 | 14 | Countdown(int ms) { |
mapellil | 49:c66fdbb9eb83 | 15 | t = new Timer(); |
mapellil | 49:c66fdbb9eb83 | 16 | if (t == NULL) printf ("Countdown newfail\n\r"); |
icraggs | 29:833386b16f3e | 17 | countdown_ms(ms); |
icraggs | 29:833386b16f3e | 18 | } |
icraggs | 29:833386b16f3e | 19 | |
mapellil | 49:c66fdbb9eb83 | 20 | ~Countdown() { |
mapellil | 49:c66fdbb9eb83 | 21 | delete t; |
mapellil | 49:c66fdbb9eb83 | 22 | } |
icraggs | 29:833386b16f3e | 23 | |
mapellil | 49:c66fdbb9eb83 | 24 | bool expired() { |
mapellil | 49:c66fdbb9eb83 | 25 | return t->read_ms() >= interval_end_ms; |
icraggs | 29:833386b16f3e | 26 | } |
icraggs | 29:833386b16f3e | 27 | |
mapellil | 49:c66fdbb9eb83 | 28 | void countdown_ms(unsigned long ms) { |
mapellil | 49:c66fdbb9eb83 | 29 | t->stop(); |
icraggs | 29:833386b16f3e | 30 | interval_end_ms = ms; |
mapellil | 49:c66fdbb9eb83 | 31 | t->reset(); |
mapellil | 49:c66fdbb9eb83 | 32 | t->start(); |
icraggs | 29:833386b16f3e | 33 | } |
icraggs | 29:833386b16f3e | 34 | |
mapellil | 49:c66fdbb9eb83 | 35 | void countdown(int seconds) { |
icraggs | 43:21da1f744243 | 36 | countdown_ms((unsigned long)seconds * 1000L); |
icraggs | 29:833386b16f3e | 37 | } |
icraggs | 29:833386b16f3e | 38 | |
mapellil | 49:c66fdbb9eb83 | 39 | int left_ms() { |
mapellil | 49:c66fdbb9eb83 | 40 | return interval_end_ms - t->read_ms(); |
icraggs | 29:833386b16f3e | 41 | } |
icraggs | 29:833386b16f3e | 42 | |
icraggs | 29:833386b16f3e | 43 | private: |
mapellil | 49:c66fdbb9eb83 | 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 |