-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAtTouch.h
executable file
·147 lines (122 loc) · 3.84 KB
/
AtTouch.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/************************************************************************************
*
* Name : AtTouch
* Author : Noah Shibley, Michael Grant NoMi Design nomidesign.net
* Date : July 18th 2011
* Version : 0.1
* Notes : Arduino Library for use with the AT42QT1070 Q-touch chip via i2c
*
* Copyright (c) 2011 NoMi Design All right reserved.
*
* This file is part of AtTouch.
*
* AtTouch 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.
*
* AtTouch 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 AtTouch. If not, see <http://www.gnu.org/licenses/>.
*
***********************************************************************************/
#ifndef AtTouch_H
#define AtTouch_H
//#define SERIAL_DEBUG //do you want status messages printed to serial?
#define WIRE //are you going to use the arduino default WIRE library or the improved I2C library?
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#ifdef WIRE
#include <Wire.h>
#else
#include <I2C.h>
#endif
extern "C" void bttnPressISR(void) __attribute__ ((signal));
class AtTouch {
public:
friend void bttnPressISR(void); //make friend so bttnPressISR can access private var keyhit
AtTouch();
/***********************************************************
*
* begin
*
* init the AtTouch class
*
***********************************************************/
void begin(int interruptPin,boolean disableAutoCal=true);
/***********************************************************
*
* readActiveKey
*
* request the touch chip the value of the active key
*
***********************************************************/
int readActiveKey();
/***********************************************************
*
* hit
*
* return whether hit is true or false
*
***********************************************************/
boolean hit();
/***********************************************************
*
* setRefreshSpeed
*
* during press and hold, restrict how often per sec hold returns true
*
***********************************************************/
void setRefreshSpeed(int intervalMilSec);
/***********************************************************
*
* getStartTime
*
* get the time that the key was pressed
*
***********************************************************/
unsigned long getStartTime();
/***********************************************************
*
* getKey
*
* get the key number that was pressed
*
***********************************************************/
int getKey();
/***********************************************************
*
* update
*
* read the key value that was pressed
*
***********************************************************/
void update();
/***********************************************************
*
* hold
*
* return the hold status.
*
***********************************************************/
boolean hold();
private:
int readActiveAddress();
byte _changePin;
byte _interruptVal;
volatile boolean keyHit;
static AtTouch* pAtTouch; //ptr to AtTouch class for the ISR
byte activeKey_; //the current key num pressed
volatile boolean holdDown_; //is the button held down, or just pressed
volatile unsigned long startTime; //the press and hold startTime
unsigned int updateTime; //for setting the pace of hold updates
unsigned int holdRefreshInterval;
};
#endif