AWind
ATimer.h
1 #pragma once
2 /*
3 AWind.h - Arduino window library support for Color TFT LCD Boards
4 Copyright (C)2016 Andrei Degtiarev. All right reserved
5 
6 
7 You can always find the latest version of the library at
8 https://github.com/AndreiDegtiarev/AWind
9 
10 
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the CC BY-NC-SA 3.0 license.
13 Please see the included documents for further information.
14 
15 Commercial use of this library requires you to buy a license that
16 will allow commercial use. This includes using the library,
17 modified or not, as a tool to sell products.
18 
19 The license applies to all part of the library including the
20 examples and tools supplied with the library.
21 */
22 #include <ITimerEventReceiver.h>
23 
28 class ATimer
29 {
30  ITimerEventReceiver *_timerEventReceiver;
31  uint32_t _msStart;
32  uint32_t _msInterval;
33  bool _isAutoreset;
34  bool _isEnabled;
35 public:
36  ATimer()
37  {
38  _isAutoreset = false;
39  _isEnabled = false;
40  _timerEventReceiver = NULL;
41  }
44  {
45  _timerEventReceiver = timerEventReceiver;
46  }
48  void SetAutoReset(bool isAutoreset)
49  {
50  _isAutoreset = isAutoreset;
51  }
53  void SetInterval(uint32_t milliseconds)
54  {
55  _msInterval = milliseconds;
56  }
58  bool IsEnabled()
59  {
60  return _isEnabled;
61  }
63  void Enable()
64  {
65  _isEnabled = true;
66  _msStart = millis();
67  }
69  void Reset()
70  {
71  _isEnabled = false;
72  }
74  uint32_t Elapsed()
75  {
76  return millis() - _msStart;
77  }
78  //Is called by AWind framework
79  void loop()
80  {
81  if (_isEnabled && Elapsed() >= _msInterval && _timerEventReceiver != NULL)
82  {
83  _timerEventReceiver->NotifyTimer(this);
84  if (_isAutoreset)
85  Enable();
86  else
87  Reset();
88  }
89 
90  }
91 };
Interface that provides screen touch notifications. If you want receive this notification in the targ...
Definition: ITimerEventReceiver.h:24
Definition: ATimer.h:28
bool IsEnabled()
Returns true if timer is active.
Definition: ATimer.h:58
void SetInterval(uint32_t milliseconds)
Set timer interval in milliseconds.
Definition: ATimer.h:53
void Enable()
Starts timer.
Definition: ATimer.h:63
void Reset()
Disabels timer.
Definition: ATimer.h:69
virtual void NotifyTimer(ATimer *timer)=0
Has to be implemented in target class.
uint32_t Elapsed()
Returns actual elapsed time.
Definition: ATimer.h:74
void RegisterTimerEventReceiver(ITimerEventReceiver *timerEventReceiver)
Registers event receiver.
Definition: ATimer.h:43
void SetAutoReset(bool isAutoreset)
Set whether timer is in autoreset modus.
Definition: ATimer.h:48