-
Notifications
You must be signed in to change notification settings - Fork 0
/
PPMint.cpp
55 lines (48 loc) · 1.06 KB
/
PPMint.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
/*
Author Ilya ilyxa Tyshchenko
Site: http://www.nest.org.ru/tag/Arduino
e-mail: arduino@nest.org.ru
*/
#include <PPMint.h>
//BEGIN
// only one instance allowed - some hack here
static PPMint *pclass = 0;
void ppmInterrupt() {// dummy function
if (pclass)
pclass->PPMinterrupt();
}
//END
PPMint::PPMint() {
} //PPMint
void PPMint::setup() {
realRaw[10]=0,0,0,0,0,0,0,0,0,0;
prevRealRaw[10]=0,0,0,0,0,0,0,0,0,0;
currentChannel=0;
lastms = 0;
sync = false;
pinMode(_PPM_PIN,INPUT);
pclass=this; //create an pointer to func
attachInterrupt(_PPM_INT,ppmInterrupt,RISING);
while(!sync) {
delay(100);
}
}
void PPMint::PPMinterrupt() { //here real work to come ;)
long nowms = micros();
diffms = nowms - lastms;
if(lastms>0) {
if(diffms>5000) {
sync = true;
currentChannel = 0;
}
else {
if(sync) {
if(diffms<=2000 && diffms>=1000) {
realRaw[currentChannel] = diffms;
}
currentChannel++;
}
}
}
lastms = nowms;
}//PPMinterrupt