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.
Dependencies: C12832 EthernetInterface MMA7660 MQTT USBDevice mbed-rtos mbed
Fork of HelloMQTT by
LinuxMQTT.h
00001 #if !defined(LINUXMQTT_H) 00002 #define LINUXMQTT_H 00003 00004 class Countdown 00005 { 00006 public: 00007 Countdown() 00008 { 00009 00010 } 00011 00012 Countdown(int ms) 00013 { 00014 countdown_ms(ms); 00015 } 00016 00017 00018 bool expired() 00019 { 00020 struct timeval now, res; 00021 gettimeofday(&now, NULL); 00022 timersub(&end_time, &now, &res); 00023 //printf("left %d ms\n", (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000); 00024 //if (res.tv_sec > 0 || res.tv_usec > 0) 00025 // printf("expired %d %d\n", res.tv_sec, res.tv_usec); 00026 return res.tv_sec < 0 || (res.tv_sec == 0 && res.tv_usec <= 0); 00027 } 00028 00029 00030 void countdown_ms(int ms) 00031 { 00032 struct timeval now; 00033 gettimeofday(&now, NULL); 00034 struct timeval interval = {ms / 1000, (ms % 1000) * 1000}; 00035 //printf("interval %d %d\n", interval.tv_sec, interval.tv_usec); 00036 timeradd(&now, &interval, &end_time); 00037 } 00038 00039 00040 void countdown(int seconds) 00041 { 00042 struct timeval now; 00043 gettimeofday(&now, NULL); 00044 struct timeval interval = {seconds, 0}; 00045 timeradd(&now, &interval, &end_time); 00046 } 00047 00048 00049 int left_ms() 00050 { 00051 struct timeval now, res; 00052 gettimeofday(&now, NULL); 00053 timersub(&end_time, &now, &res); 00054 //printf("left %d ms\n", (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000); 00055 return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000; 00056 } 00057 00058 private: 00059 00060 struct timeval end_time; 00061 }; 00062 00063 00064 #endif
Generated on Sun Jul 17 2022 11:40:56 by
1.7.2
