-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventFuse.h
79 lines (65 loc) · 2.69 KB
/
EventFuse.h
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
/*
* EventFuse.h - A simple fuse-based event callback library
* v0.4 - 2013-Dec-20
* - Converted to namespace.
* - added burn() to burn by one.
* - changed callback user data to int&
* - added cancel(FuseID)
* v0.3 - 2012-April-27
* - Minor update to burn(int) to out or range issue in repeatCount.
* This caused problems with INF_REPEAT fuses.
* v0.2 - 2009-July-20
* - Reworked interface and renamed some
* types to improve usability.
* v0.1 - 2009-June-16
* Derived from:
* Timer.h - A Real-time Timer Library for Arduino & Wiring
* Copyright (c) 2009 Daniel Bradberry. All right reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef EventFuseNs_h
#define EventFuseNs_h
#define INF_REPEAT -1
typedef unsigned char FuseID; // a fuse handle
namespace EventFuse {
#define MAX_FUSES 10
#define NULL_FUSE -1
typedef void (*eventFuseCallback_t)(FuseID, int&);
enum FuseState {
fsUnallocated, // fuse not in use
fsEnabled, // fuse is running
fsDisabled, // fuse is not running
fsBlocked, // fuse is blocked by callback
};
struct eventFuse_t {
FuseState fuseState; // current state of the fuse
int fuseLen; // current length of the fuse
int fuseInit; // internal, starting fuse length
unsigned int repeatCount; // number of repeats, INF_REPEAT for infinite
int userData; // available for user-defined data
eventFuseCallback_t callback; // callback to execute when fuse runs out
void cancel(){ fuseState = fsUnallocated; }
};
void init();
FuseID newFuse(int userData, int fuseLen, unsigned int repeatCount, eventFuseCallback_t fuseCallback);
FuseID newFuse(int fuseLen, unsigned int repeatCount, eventFuseCallback_t fuseCallback);
void resetFuse(FuseID fuse, int userData, int fuseLen, unsigned int repeatCount, eventFuseCallback_t fuseCallback);
void resetFuse(FuseID fuse, int fuseLen, unsigned int repeatCount, eventFuseCallback_t fuseCallback);
void burn(int len);
void burn();
extern eventFuse_t fuses[MAX_FUSES];
};
#endif