The Cayenne MQTT mbed Library provides functions to easily connect to the Cayenne IoT project builder.
Dependents: Cayenne-ESP8266Interface Cayenne-WIZnet_Library Cayenne-WIZnetInterface Cayenne-X-NUCLEO-IDW01M1 ... more
MQTTTimer.h
00001 /* 00002 The MIT License(MIT) 00003 00004 Cayenne MQTT Client Library 00005 Copyright (c) 2016 myDevices 00006 00007 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 00008 documentation files(the "Software"), to deal in the Software without restriction, including without limitation 00009 the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, 00010 and to permit persons to whom the Software is furnished to do so, subject to the following conditions : 00011 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 00012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 00013 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR 00014 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00015 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00016 */ 00017 00018 #ifndef _MQTTTIMER_h 00019 #define _MQTTTIMER_h 00020 00021 #include "mbed.h" 00022 00023 /** 00024 * Timer class for use with MQTTClient. 00025 */ 00026 class MQTTTimer : private Timer 00027 { 00028 public: 00029 /** 00030 * Construct a timer. 00031 */ 00032 MQTTTimer() : interval_end_ms(0) {}; 00033 00034 /** 00035 * Construct a timer and start it. 00036 * @param[in] milliseconds Number of milliseconds to count down. 00037 */ 00038 MQTTTimer(int milliseconds) { 00039 countdown_ms(milliseconds); 00040 } 00041 00042 /** 00043 * Start countdown. 00044 * @param[in] milliseconds Number of milliseconds to count down. 00045 */ 00046 void countdown_ms(int milliseconds) { 00047 interval_end_ms = milliseconds; 00048 reset(); 00049 start(); 00050 } 00051 00052 /** 00053 * Start countdown. 00054 * @param[in] seconds Number of seconds to count down. 00055 */ 00056 void countdown(int seconds) { 00057 countdown_ms(seconds * 1000); 00058 } 00059 00060 /** 00061 * Get the number of milliseconds left in countdown. 00062 * @return Number of milliseconds left. 00063 */ 00064 int left_ms() { 00065 return interval_end_ms - read_ms(); 00066 } 00067 00068 /** 00069 * The countdown timer has expired. 00070 * @return true if countdown has expired, false otherwise. 00071 */ 00072 bool expired() { 00073 return (interval_end_ms > 0L) && (read_ms() >= interval_end_ms); 00074 } 00075 00076 private: 00077 unsigned long interval_end_ms; 00078 }; 00079 00080 #endif
Generated on Wed Jul 13 2022 15:49:28 by 1.7.2