/**************************************************************************** * * Copyright (c) 2006 Dave Hylands * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Alternatively, this software may be distributed under the terms of BSD * license. * * See README and COPYING for more details. * **************************************************************************** * * User mode app which monitors multiple gpio pins and notifies a user mode * app about the events. * ****************************************************************************/ /* ---- Include Files ---------------------------------------------------- */ #include #include #include "gpio-event-drv.h" /* ---- Public Variables ------------------------------------------------- */ /* ---- Private Constants and Types -------------------------------------- */ /* ---- Private Variables ------------------------------------------------ */ /* ---- Private Function Prototypes -------------------------------------- */ /* ---- Functions -------------------------------------------------------- */ /**************************************************************************** * * main * ***************************************************************************/ int main( int argc, char **argv ) { FILE *fs; GPIO_EventMonitor_t monitor; if (( fs = fopen( "/dev/gpio-event", "r" )) < 0 ) { perror( "Unable to open /dev/gpio-event" ); exit( 1 ); } ioctl( fileno( fs ), GPIO_EVENT_IOCTL_SET_READ_MODE, 1 ); monitor.onOff = 1; monitor.gpio = 58; monitor.edgeType = GPIO_EventRisingEdge; monitor.debounceMilliSec = 20; if ( ioctl( fileno( fs ), GPIO_EVENT_IOCTL_MONITOR_GPIO, &monitor ) != 0 ) { perror( "ioctl GPIO_EVENT_IOCTL_MONITOR_GPIO failed" ); exit( 1 ); } while ( 1 ) { GPIO_Event_t gpioEvent; int numBytes; if (( numBytes = fread( &gpioEvent, 1, sizeof( gpioEvent ), fs )) == sizeof( gpioEvent )) { printf( "GPIO pressed\n" ); } else { if ( numBytes > 0 ) { fprintf( stderr, "Read unexpected number of bytes: %d, expecting %d\n", numBytes, sizeof( gpioEvent )); } } } fclose( fs ); exit( 0 ); return 0; } // main