|
I got fed up and took a look at this stuff. I fixed WiringOP to support interrupts and at least in my simple test - program it's working fine -- just make sure you don't have gpio-sunxi - module loaded! Grab the fix from https://github.com/WereCatf/WiringOP if you want to test. Here's a snippet that I tested it with (compile with gcc -o wpi wpi.c -lpthread -lwiringPi):
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <wiringPi.h>
- // Button connected to PG07, ie. WPi-pin 16
- #define BUTTON_PIN 16
- // the event counter
- volatile int eventCounter = 0;
- // -------------------------------------------------------------------------
- void myInterrupt(void) {
- eventCounter++;
- }
- // -------------------------------------------------------------------------
- int main(void) {
- // sets up the wiringPi library
- if (wiringPiSetup () < 0) {
- fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
- return 1;
- }
- // set Pin 17/0 generate an interrupt on high-to-low transitions
- // and attach myInterrupt() to the interrupt
- if ( wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0 ) {
- fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
- return 1;
- }
- // display counter value every second.
- while ( 1 ) {
- printf( "%d\n", eventCounter );
- eventCounter = 0;
- delay( 1000 ); // wait 1 second
- }
- return 0;
- }
Copy code |
|