Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sysfs-gpio.h" // https://github.com/mvduin/sysfs-gpio
- #include <stdio.h>
- int main()
- {
- struct Gpio gpio = GPIO_INITIALIZER;
- gpio_open_input( &gpio, "/sys/class/gpio/gpio60", GPIO_EDGE_BOTH, GPIO_RDONLY );
- bool const invert = gpio_is_active_low( &gpio );
- bool level = gpio_read( &gpio ) ^ invert;
- printf( "%c ", level ? 'H' : 'L' ); // print initial level
- for(;;) {
- fflush( stdout );
- gpio_wait_event( &gpio, -1 );
- bool prev_level = level;
- level = gpio_read( &gpio ) ^ invert;
- printf( "%c ", prev_level ? 'F' : 'R' );
- // if an edge was detected but level didn't change then we must have had a second edge
- if( level == prev_level )
- printf( "%c ", prev_level ? 'R' : 'F' );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement