diff --git a/gpio/gpio.c b/gpio/gpio.c index 0f0dd06..c4d698e 100644 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -1338,7 +1338,7 @@ static void doVersion (char *argv []) } } - if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO + if (wiringPiUserLevelAccess()) // User level GPIO is GO printf (" * This Raspberry Pi supports user-level GPIO access.\n") ; else printf (" * Root or sudo required for GPIO access.\n") ; diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index d0bce4f..bbf1713 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -2553,6 +2553,19 @@ void wiringPiVersion (int *major, int *minor) } +int wiringPiUserLevelAccess(void) +{ + struct stat statBuf ; + const char* gpiomemModule = gpiomem_BCM; + + if (PI_MODEL_5 == RaspberryPiModel) { + gpiomemModule = gpiomem_RP1; + } + + return stat(gpiomemModule, &statBuf) == 0 ? 1 : 0; +} + + /* * wiringPiSetup: * Must be called once at the start of your program execution. diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index 462900e..94875b2 100644 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -206,6 +206,7 @@ extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ; extern int GPIOToSysFS(const int pin) ; extern void wiringPiVersion (int *major, int *minor) ; +extern int wiringPiUserLevelAccess (void) ; extern int wiringPiSetup (void) ; extern int wiringPiSetupSys (void) ; extern int wiringPiSetupGpio (void) ;