-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ir_encoder.cpp
71 lines (56 loc) · 1.61 KB
/
test_ir_encoder.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
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>
// globalCounter:
// Global variable to count interrupts
// Should be declared volatile to make sure the compiler doesn't cache it.
static volatile int globalCounter [4] ;
/*
* myInterrupt:
*********************************************************************************
*/
void myInterrupt0 (void) {
printf ("Inside interupt for pin 0") ;
++globalCounter [0] ; }
void myInterrupt1 (void) { ++globalCounter [1] ; }
void myInterrupt2 (void) { ++globalCounter [2] ; }
void myInterrupt3 (void) { ++globalCounter [3] ; }
/*
*********************************************************************************
* main
*********************************************************************************
*/
int main (void)
{
int gotOne, pin ;
int myCounter [4] ;
for (pin = 0 ; pin < 4 ; ++pin)
globalCounter [pin] = myCounter [pin] = 0 ;
wiringPiSetup () ;
wiringPiISR (0, INT_EDGE_FALLING, &myInterrupt0) ;
wiringPiISR (25, INT_EDGE_FALLING, &myInterrupt1) ;
wiringPiISR (2, INT_EDGE_FALLING, &myInterrupt2) ;
wiringPiISR (3, INT_EDGE_FALLING, &myInterrupt3) ;
for (;;)
{
gotOne = 0 ;
printf ("Waiting ... ") ; fflush (stdout) ;
for (;;)
{
for (pin = 0 ; pin < 4 ; ++pin)
{
if (globalCounter [pin] != myCounter [pin])
{
printf (" Int on pin %d: Counter: %5d\n", pin, globalCounter [pin]) ;
myCounter [pin] = globalCounter [pin] ;
++gotOne ;
}
}
if (gotOne != 0)
break ;
}
}
return 0 ;
}