-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunLoopInterrupt.hpp
More file actions
126 lines (92 loc) · 3.33 KB
/
Copy pathRunLoopInterrupt.hpp
File metadata and controls
126 lines (92 loc) · 3.33 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* RunLoopInterrupt.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 RunLoopInterrupt_hpp
#define RunLoopInterrupt_hpp
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include "Arduino.h"
// Small hack to avoid naming conflict between class method end C function for
// attachInterrupt(...) and detachInterrupt(...).
extern void _attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode);
extern void _detachInterrupt(uint8_t interruptNum);
#endif
/*
Board Digital Pins Usable For Interrupts
Uno, Nano, Mini, other 328-based 2, 3
Mega, Mega2560, MegaADK 2, 3, 18, 19, 20, 21
Micro, Leonardo, other 32u4-based 0, 1, 2, 3, 7
Zero all digital pins, except 4
MKR1000 Rev.1 0, 1, 4, 5, 6, 7, 8, 9, A1, A2
Due all digital pins
101 all digital pins
*/
// Model
#include "RunLoopObject.hpp"
class RunLoopInterrupt;
/*!
* The class RunLoopHardwareinterruptDelegate is used to define delegation paradigm for interrupts.
*
* @ingroup Protocol
*/
class RunLoopInterruptDelegate
{
public:
/*! This method is called when an interrupt rise. */
virtual void interrupt(RunLoopInterrupt *sender) = 0;
};
/*!
* The class manages common interrupts behaviour.
*
* @ingroup Model
*/
class RunLoopInterrupt : public RunLoopObject
{
public:
#pragma mark -
#pragma mark Create and destroy
RunLoopInterrupt();
~RunLoopInterrupt();
#pragma mark -
#pragma mark Virtual methods for subclass overwrite
/*! Method executed each time delay is elapsed. User should overwrite this method when subclassing RunLoopTimer. */
virtual void interrupt() = 0;
#pragma mark -
#pragma mark Usuals
/*! Set delegate for asynchronous feedback. If not set, fire() method is call. */
void setInterruptDelegate(RunLoopInterruptDelegate *delegate);
/*! Get delegate for asynchronous feedback. */
inline RunLoopInterruptDelegate *interruptDelegate() {return _interruptDelegate;};
/*! Set call back function for C backward compatibility if needed. */
void attachInterrupt(void (*interrupt)(RunLoopInterrupt*));
/*! Unset call back function for C backward compatibility if needed. */
void detachInterrupt();
#pragma mark -
#pragma mark Internal use but needed as public for direct timer access in ISR
/*! Real loop replacing software loop. */
void hardwareLoop();
protected:
/*! Call back function for C backward compatibility if needed. */
void (*_interruptCallback)(RunLoopInterrupt*) = NULL;
private:
/*! Delegate for feedback. */
RunLoopInterruptDelegate *_interruptDelegate = NULL;
/*! Interrupt need to avoid software loop cause job will be redirected to hardwareLoop(). */
void loop() {};
};
#endif