forked from Here-Be-Dragons/familamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
captouch.h
97 lines (81 loc) · 2.74 KB
/
captouch.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//============================================================
// Touch Sensing Demo on Spark Core
//
//============================================================
// Copyright (c) 2014 Tangibit Studios LLC. All rights reserved.
// Copyright (c) 2014 David Greaves <[email protected]>
//
// This program 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 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, see <http://www.gnu.org/licenses/>.
//
//============================================================
#ifndef CAPTOUCH_H
#define CAPTOUCH_H
// Polling times in [ms]
#define CAPTOUCH_POLL_TIME 20
#define CAPTOUCH_TOUCH_POOL 100
#define CAPTOUCH_JITTER_POOL 40
// Useful debugging output
#define CAPTOUCH_DEBUG 1
class CapTouch
{
public:
explicit CapTouch(int sensorPin, int driverPin);
// Touch events
enum Event {
NoEvent,
TouchEvent,
ReleaseEvent
};
enum State {
Touched,
NotTouched,
};
void setup();
void setPoll(int pollinterval) { m_pollTime = pollinterval; }
// In case the interrupts need to be disabled
void detachIntr();
void attachIntr();
bool intrIsAttached() { return m_intrIsAttached; }
// Get transition information
Event getEvent();
// Get state information
// State getState();
protected:
// Currently this is static until we can pass a lambda to the
// attachInterrupt() call
void touchSense();
long touchSampling();
Event touchEventCheck();
bool m_intrIsAttached;
int m_pollTime;
// touch sensor pins
int m_driverPin;
int m_sensorPin;
// reading and baseline
long m_tReading;
long m_tBaseline;
long m_tBaselineSum;
long m_tLastDelay;
long m_tJitterSum;
long m_tJitter;
// timestamps
unsigned long m_tS;
unsigned long m_lastUpdate;
// Debounce
unsigned long m_touchSenseLast;
unsigned long m_touchDebounceTimeLast;
unsigned long m_touchNow; // current debounced state
unsigned long m_touchLast; // last debounced state
};
#endif // CAPTOUCH_H