-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunLoopHardwareTimer5.hpp
More file actions
78 lines (63 loc) · 2.37 KB
/
Copy pathRunLoopHardwareTimer5.hpp
File metadata and controls
78 lines (63 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* RunLoopHardwareTimer5.hpp
*
* Copyright (c) 2017 by Sebastien MARCHAND (Web:www.marscaper.com, Email:sebastien@marscaper.com)
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RunLoopHardwareTimer5_hpp
#define RunLoopHardwareTimer5_hpp
// Timer only available with Arduino Mega
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// Model
#include "RunLoopObject.hpp"
#include "RunLoopHardwareTimer.hpp"
/*!
* The class manages the hardware Timer5 (16bits) available with the <b>Arduino Mega only</b>.
* Hardware timers are much more accurate so we can use micro seconds delay.
*
* There is three ways to use this class:
* - Create a sublcass, inherit from RunLoopHardwareTimer0 and overwrite fire().
* - Instantiate a RunLoopHardwareTimer0 object and use a delegate which conforms to RunLoopTimerDelegate protocol.
* - Use attachInterrupt() to set a simple C function as call back.
*
* @ingroup Model
*/
class RunLoopHardwareTimer5 : public RunLoopHardwareTimer
{
public:
#pragma mark -
#pragma mark Create and destroy
RunLoopHardwareTimer5();
~RunLoopHardwareTimer5();
#pragma mark -
#pragma mark Usuals
#if RUN_LOOP_FULL || RUN_LOOP_INHERITANCE
/*! Method executed each time delay is elapsed if delegate is not set. Subclasses need to overwrite this method. */
virtual void fire() {};
#endif
/*! Set delay in milliseconds. */
void setDelay(unsigned long delay);
/*! Set delay in microseconds. */
void setMicroDelay(unsigned long delay);
/*! Start or stop the loop. */
void setIdle(bool state);
/*! Global structure used internally by timers to store parameters. */
inline TimerPreset timerPresetForMicroDelay(unsigned long delay);
void setTimerPreset(TimerPreset *timer);
TimerPreset* timerPreset();
};
#endif
#endif