Skip to content

Commit

Permalink
Fix bring_gpio_interrupt_into_userspace on Debian, piface#29
Browse files Browse the repository at this point in the history
This introduces GPIO offset detection by checking the dir name starting with
gpiochip[0-9]* found in /sys/bus/gpio/devices/gpiochip0/../gpio/.

Thec change is tested and confirmed working on Debian Buster 10 and Raspbian 9.9,
on boht Raspberry Pi 3B and 3B+
  • Loading branch information
sibradzic committed Jul 8, 2019
1 parent 006bca1 commit b6418e5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pifacecommon/interrupts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import errno
from .core import get_bit_num
from os import listdir,path
import pifacecommon.mcp23s17


Expand All @@ -14,7 +15,15 @@
# IN_EVENT_DIR_OFF = INPUT_DIRECTION_OFF = 1
# IN_EVENT_DIR_BOTH = INPUT_DIRECTION_BOTH = None

GPIO_INTERRUPT_PIN = 25
GPIO_OFFSET = 0
GPIO_OFFSET_CHECK_PATH = '/sys/bus/gpio/devices/gpiochip0/../gpio'
if path.isdir(GPIO_OFFSET_CHECK_PATH):
gpio_device_dir = listdir(GPIO_OFFSET_CHECK_PATH)
if gpio_device_dir and gpio_device_dir[0].startswith('gpiochip'):
gpio_offset_str = gpio_device_dir[0].strip('gpiochip')
if gpio_offset_str.isnumeric():
GPIO_OFFSET = int(gpio_offset_str)
GPIO_INTERRUPT_PIN = GPIO_OFFSET + 25
GPIO_INTERRUPT_DEVICE = "/sys/class/gpio/gpio%d" % GPIO_INTERRUPT_PIN
GPIO_INTERRUPT_DEVICE_EDGE = '%s/edge' % GPIO_INTERRUPT_DEVICE
GPIO_INTERRUPT_DEVICE_VALUE = '%s/value' % GPIO_INTERRUPT_DEVICE
Expand Down

1 comment on commit b6418e5

@gmm9200
Copy link

@gmm9200 gmm9200 commented on b6418e5 Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this code in python2.7 I had the following error:

File "/usr/lib/python2.7/dist-packages/pifacecommon/interrupts.py", line 24, in
if gpio_offset_str.isnumeric():
AttributeError: 'str' object has no attribute 'isnumeric'

The solution is to change the line
if gpio_offset_str.isnumeric():
with

if gpio_offset_str.isdigit():

Please sign in to comment.