• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2014 IBM Corp.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    http://www.eclipse.org/legal/epl-v10.html
10  * and the Eclipse Distribution License is available at
11  *   http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  *    Ian Craggs - initial API and implementation and/or initial documentation
15  *******************************************************************************/
16 
17 #if !defined(COUNTDOWN_H)
18 #define COUNTDOWN_H
19 
20 class Countdown
21 {
22 public:
Countdown()23     Countdown()
24     {
25 		interval_end_ms = 0L;
26     }
27 
Countdown(int ms)28     Countdown(int ms)
29     {
30         countdown_ms(ms);
31     }
32 
expired()33     bool expired()
34     {
35         return (interval_end_ms > 0L) && (millis() >= interval_end_ms);
36     }
37 
countdown_ms(unsigned long ms)38     void countdown_ms(unsigned long ms)
39     {
40         interval_end_ms = millis() + ms;
41     }
42 
countdown(int seconds)43     void countdown(int seconds)
44     {
45         countdown_ms((unsigned long)seconds * 1000L);
46     }
47 
left_ms()48     int left_ms()
49     {
50         return interval_end_ms - millis();
51     }
52 
53 private:
54     unsigned long interval_end_ms;
55 };
56 
57 #endif
58