File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,9 @@ def read(sensor, pin):
3131 # Signal no result could be obtained, but the caller can retry.
3232 return (None , None )
3333 elif result == common .DHT_ERROR_GPIO :
34- raise RuntimeError ('Error accessing GPIO.' )
34+ raise RuntimeError (
35+ 'Error accessing GPIO. If `/dev/gpiomem` does not exist '
36+ 'run this program as root or sudo.' )
3537 elif result != common .DHT_SUCCESS :
3638 # Some kind of error occured.
3739 raise RuntimeError ('Error calling DHT test driver read: {0}' .format (result ))
Original file line number Diff line number Diff line change @@ -37,7 +37,15 @@ volatile uint32_t* pi_mmio_gpio = NULL;
3737
3838int pi_mmio_init (void ) {
3939 if (pi_mmio_gpio == NULL ) {
40- int fd = open ("/dev/gpiomem" , O_RDWR | O_SYNC );
40+ int fd ;
41+
42+ // On older kernels user readable /dev/gpiomem might not exists.
43+ // Falls back to root-only /dev/mem.
44+ if ( access ( "/dev/gpiomem" , F_OK ) != -1 ) {
45+ fd = open ("/dev/gpiomem" , O_RDWR | O_SYNC );
46+ } else {
47+ fd = open ("/dev/mem" , O_RDWR | O_SYNC );
48+ }
4149 if (fd == -1 ) {
4250 // Error opening /dev/gpiomem.
4351 return MMIO_ERROR_DEVMEM ;
You can’t perform that action at this time.
0 commit comments