-
Notifications
You must be signed in to change notification settings - Fork 0
/
xindaIR.cpp
150 lines (111 loc) · 2.46 KB
/
xindaIR.cpp
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
/*
Code to interpret XindaIR control signals.
*/
#include "Arduino.h"
#include "xindaIR.h"
volatile unsigned char timeWriteIndicator = 0;
volatile unsigned long timeArray[stackArraySize];
xindaIR::xindaIR(unsigned char pin)
{
pinMode(pin, INPUT);
_pin = pin ;
}
void xindaIR::readIRstack() {
while (timeWriteIndicator!=(_timeReadIndicator)) {
_timeDifference=timeArray[(_timeReadIndicator+1)%stackArraySize]-timeArray[_timeReadIndicator];
if (abs(_timeDifference)<7000) {
(_timeDecoder(_timeDifference));
}
_timeReadIndicator=(_timeReadIndicator+1)%stackArraySize;
}
}
byte xindaIR::_timeDecoder(unsigned int sigLength) {
if ((minShortSig<sigLength)&&(maxShortSig>sigLength)) {
_msg=_msg<<1;
return 0;
}
if ((minLongSig<sigLength)&&(maxLongSig>sigLength)) {
_msg=_msg<<1;
_msg++;
if (((bitCheck&_msg)==bitCheck)&&((zeroCheck&~_msg)==zeroCheck)) {
Serial.println(_msg,HEX);
isButtonPressed = true;
}
return 1;
}
if ((minButtonPress<sigLength)&&(maxButtonPress>sigLength)) {
return 2;
isRepeat++;
}
if ((minSigStart<sigLength)&&(maxSigStart>sigLength)) {
_msg=0;
isRepeat=0;
return 3;
}
return 7;
}
void xindaIR::xindaIR_Setup() {
attachInterrupt(digitalPinToInterrupt(_pin), interruptForOpticalSignal, RISING);
}
void interruptForOpticalSignal() {
timeWriteIndicator=(timeWriteIndicator+1)%stackArraySize;
timeArray[timeWriteIndicator]=micros();
}
char xindaIR::getIRmsg() {
switch (_msg) {
case button_UP:
return 88;
break;
case button_DOWN:
return 22;
break;
case button_LEFT:
return 44;
break;
case button_RIGHT:
return 66;
break;
case button_OK:
return 55;
break;
case button_0:
return 0;
break;
case button_1:
return 1;
break;
case button_2:
return 2;
break;
case button_3:
return 3;
break;
case button_4:
return 4;
break;
case button_5:
return 5;
break;
case button_6:
return 6;
break;
case button_7:
return 7;
break;
case button_8:
return 8;
break;
case button_9:
return 9;
break;
case button_STAR:
return 11;
break;
case button_HASH:
return 33;
break;
default:
return 99;
break;
}
}