@@ -42,15 +42,27 @@ struct ThreadArgs {
42
42
volatile bool interruptsEnabled = true ;
43
43
static pthread_mutex_t intMutex = PTHREAD_MUTEX_INITIALIZER;
44
44
45
- static pthread_t *threadIds[64 ] = {NULL };
45
+ static pthread_t *threadIds[256 ] = {NULL };
46
46
47
47
// sysFds:
48
48
// Map a file descriptor from the /sys/class/gpio/gpioX/value
49
- static int sysFds[64 ] = {
49
+ static int sysFds[256 ] = {
50
50
-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
51
51
-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
52
52
-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
53
53
-1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
54
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
55
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
56
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
57
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
58
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
59
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
60
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
61
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
62
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
63
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
64
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
65
+ -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
54
66
};
55
67
56
68
/*
@@ -130,7 +142,7 @@ void attachInterrupt(uint8_t gpioPin, void (*func)(), uint8_t mode)
130
142
FILE *fd;
131
143
char fName [40 ];
132
144
char c;
133
- int count, i ;
145
+ int count;
134
146
135
147
if (threadIds[gpioPin] == NULL ) {
136
148
threadIds[gpioPin] = new pthread_t ;
@@ -190,15 +202,15 @@ void attachInterrupt(uint8_t gpioPin, void (*func)(), uint8_t mode)
190
202
191
203
if (sysFds[gpioPin] == -1 ) {
192
204
snprintf (fName , sizeof (fName ), " /sys/class/gpio/gpio%d/value" , gpioPin);
193
- if ((sysFds[gpioPin] = open (fName , O_RDWR )) < 0 ) {
205
+ if ((sysFds[gpioPin] = open (fName , O_RDONLY )) < 0 ) {
194
206
logError (" Error reading pin %d: %s\n " , gpioPin, strerror (errno));
195
207
exit (1 );
196
208
}
197
209
}
198
210
199
211
// Clear any initial pending interrupt
200
212
ioctl (sysFds[gpioPin], FIONREAD, &count);
201
- for (i = 0 ; i < count; ++i) {
213
+ for (int i = 0 ; i < count; ++i) {
202
214
if (read (sysFds[gpioPin], &c, 1 ) == -1 ) {
203
215
logError (" attachInterrupt: failed to read pin status: %s\n " , strerror (errno));
204
216
}
0 commit comments