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.
MQTTmbed.h
00001 /******************************************************************************* 00002 * Copyright (c) 2014, 2017 IBM Corp. 00003 * 00004 * All rights reserved. This program and the accompanying materials 00005 * are made available under the terms of the Eclipse Public License v1.0 00006 * and Eclipse Distribution License v1.0 which accompany this distribution. 00007 * 00008 * The Eclipse Public License is available at 00009 * http://www.eclipse.org/legal/epl-v10.html 00010 * and the Eclipse Distribution License is available at 00011 * http://www.eclipse.org/org/documents/edl-v10.php. 00012 * 00013 * Contributors: 00014 * Ian Craggs - initial API and implementation and/or initial documentation 00015 * Ian Craggs - change Timer member initialization to avoid copy constructor 00016 *******************************************************************************/ 00017 00018 #if !defined(MQTT_MBED_H) 00019 #define MQTT_MBED_H 00020 00021 #include "mbed.h" 00022 00023 class Countdown 00024 { 00025 public: 00026 Countdown() : t() 00027 { 00028 00029 } 00030 00031 Countdown(int ms) : t() 00032 { 00033 countdown_ms(ms); 00034 } 00035 00036 00037 bool expired() 00038 { 00039 return t.read_ms() >= interval_end_ms; 00040 } 00041 00042 void countdown_ms(unsigned long ms) 00043 { 00044 t.stop(); 00045 interval_end_ms = ms; 00046 t.reset(); 00047 t.start(); 00048 } 00049 00050 void countdown(int seconds) 00051 { 00052 countdown_ms((unsigned long)seconds * 1000L); 00053 } 00054 00055 int left_ms() 00056 { 00057 return interval_end_ms - t.read_ms(); 00058 } 00059 00060 private: 00061 Timer t; 00062 unsigned long interval_end_ms; 00063 }; 00064 00065 #endif
Generated on Wed Jul 13 2022 10:46:02 by
1.7.2