@@ -42,15 +42,27 @@ struct ThreadArgs {
4242volatile bool interruptsEnabled = true ;
4343static pthread_mutex_t intMutex = PTHREAD_MUTEX_INITIALIZER;
4444
45- static pthread_t *threadIds[64 ] = {NULL };
45+ static pthread_t *threadIds[256 ] = {NULL };
4646
4747// sysFds:
4848// Map a file descriptor from the /sys/class/gpio/gpioX/value
49- static int sysFds[64 ] = {
49+ static int sysFds[256 ] = {
5050 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
5151 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
5252 -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 ,
5353 -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 ,
5466 };
5567
5668/*
@@ -130,7 +142,7 @@ void attachInterrupt(uint8_t gpioPin, void (*func)(), uint8_t mode)
130142 FILE *fd;
131143 char fName [40 ];
132144 char c;
133- int count, i ;
145+ int count;
134146
135147 if (threadIds[gpioPin] == NULL ) {
136148 threadIds[gpioPin] = new pthread_t ;
@@ -190,15 +202,15 @@ void attachInterrupt(uint8_t gpioPin, void (*func)(), uint8_t mode)
190202
191203 if (sysFds[gpioPin] == -1 ) {
192204 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 ) {
194206 logError (" Error reading pin %d: %s\n " , gpioPin, strerror (errno));
195207 exit (1 );
196208 }
197209 }
198210
199211 // Clear any initial pending interrupt
200212 ioctl (sysFds[gpioPin], FIONREAD, &count);
201- for (i = 0 ; i < count; ++i) {
213+ for (int i = 0 ; i < count; ++i) {
202214 if (read (sysFds[gpioPin], &c, 1 ) == -1 ) {
203215 logError (" attachInterrupt: failed to read pin status: %s\n " , strerror (errno));
204216 }
0 commit comments