File tree 2 files changed +12
-2
lines changed
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):
31
31
# Signal no result could be obtained, but the caller can retry.
32
32
return (None , None )
33
33
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.' )
35
37
elif result != common .DHT_SUCCESS :
36
38
# Some kind of error occured.
37
39
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;
37
37
38
38
int pi_mmio_init (void ) {
39
39
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
+ }
41
49
if (fd == -1 ) {
42
50
// Error opening /dev/gpiomem.
43
51
return MMIO_ERROR_DEVMEM ;
You can’t perform that action at this time.
0 commit comments