Hung Nguyen
/
CIS541-HW-MQTT
This is the codebase provided for CIS541 - Homework MQTT.
MQTTmbed.h@1:91e33a7fe0b5, 2017-10-07 (annotated)
- Committer:
- hungnguyenm
- Date:
- Sat Oct 07 14:52:56 2017 +0000
- Revision:
- 1:91e33a7fe0b5
Added HW6 codebase
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hungnguyenm | 1:91e33a7fe0b5 | 1 | // hot fix for NonCopyable error |
hungnguyenm | 1:91e33a7fe0b5 | 2 | // @Hung Nguyen |
hungnguyenm | 1:91e33a7fe0b5 | 3 | |
hungnguyenm | 1:91e33a7fe0b5 | 4 | #if !defined(MQTT_MBED_H) |
hungnguyenm | 1:91e33a7fe0b5 | 5 | #define MQTT_MBED_H |
hungnguyenm | 1:91e33a7fe0b5 | 6 | |
hungnguyenm | 1:91e33a7fe0b5 | 7 | #include "mbed.h" |
hungnguyenm | 1:91e33a7fe0b5 | 8 | |
hungnguyenm | 1:91e33a7fe0b5 | 9 | class Countdown |
hungnguyenm | 1:91e33a7fe0b5 | 10 | { |
hungnguyenm | 1:91e33a7fe0b5 | 11 | public: |
hungnguyenm | 1:91e33a7fe0b5 | 12 | Countdown() { |
hungnguyenm | 1:91e33a7fe0b5 | 13 | t = new Timer(); |
hungnguyenm | 1:91e33a7fe0b5 | 14 | } |
hungnguyenm | 1:91e33a7fe0b5 | 15 | |
hungnguyenm | 1:91e33a7fe0b5 | 16 | Countdown(int ms) { |
hungnguyenm | 1:91e33a7fe0b5 | 17 | t = new Timer(); |
hungnguyenm | 1:91e33a7fe0b5 | 18 | countdown_ms(ms); |
hungnguyenm | 1:91e33a7fe0b5 | 19 | } |
hungnguyenm | 1:91e33a7fe0b5 | 20 | |
hungnguyenm | 1:91e33a7fe0b5 | 21 | ~Countdown() { |
hungnguyenm | 1:91e33a7fe0b5 | 22 | delete t; |
hungnguyenm | 1:91e33a7fe0b5 | 23 | } |
hungnguyenm | 1:91e33a7fe0b5 | 24 | |
hungnguyenm | 1:91e33a7fe0b5 | 25 | |
hungnguyenm | 1:91e33a7fe0b5 | 26 | bool expired() { |
hungnguyenm | 1:91e33a7fe0b5 | 27 | return t->read_ms() >= interval_end_ms; |
hungnguyenm | 1:91e33a7fe0b5 | 28 | } |
hungnguyenm | 1:91e33a7fe0b5 | 29 | |
hungnguyenm | 1:91e33a7fe0b5 | 30 | void countdown_ms(unsigned long ms) { |
hungnguyenm | 1:91e33a7fe0b5 | 31 | t->stop(); |
hungnguyenm | 1:91e33a7fe0b5 | 32 | interval_end_ms = ms; |
hungnguyenm | 1:91e33a7fe0b5 | 33 | t->reset(); |
hungnguyenm | 1:91e33a7fe0b5 | 34 | t->start(); |
hungnguyenm | 1:91e33a7fe0b5 | 35 | } |
hungnguyenm | 1:91e33a7fe0b5 | 36 | |
hungnguyenm | 1:91e33a7fe0b5 | 37 | void countdown(int seconds) { |
hungnguyenm | 1:91e33a7fe0b5 | 38 | countdown_ms((unsigned long)seconds * 1000L); |
hungnguyenm | 1:91e33a7fe0b5 | 39 | } |
hungnguyenm | 1:91e33a7fe0b5 | 40 | |
hungnguyenm | 1:91e33a7fe0b5 | 41 | int left_ms() { |
hungnguyenm | 1:91e33a7fe0b5 | 42 | return interval_end_ms - t->read_ms(); |
hungnguyenm | 1:91e33a7fe0b5 | 43 | } |
hungnguyenm | 1:91e33a7fe0b5 | 44 | |
hungnguyenm | 1:91e33a7fe0b5 | 45 | private: |
hungnguyenm | 1:91e33a7fe0b5 | 46 | Timer* t; |
hungnguyenm | 1:91e33a7fe0b5 | 47 | unsigned long interval_end_ms; |
hungnguyenm | 1:91e33a7fe0b5 | 48 | }; |
hungnguyenm | 1:91e33a7fe0b5 | 49 | |
hungnguyenm | 1:91e33a7fe0b5 | 50 | #endif |