Skip to content

Commit 71c16ba

Browse files
committed
* Allow (and prefer) the GPIO chip label instead of its number.
1 parent 09403ad commit 71c16ba

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
trio-gpio (0.2.1-1) unstable; urgency=medium
2+
3+
* Allow (and prefer) the GPIO chip label instead of its number.
4+
5+
-- Matthias Urlichs <[email protected]> Mon, 11 Jun 2018 04:48:44 +0200
6+
17
trio-gpio (0.1.1-2) unstable; urgency=medium
28

39
* Cleanup 2

trio_gpio/gpio.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,33 @@ class Chip:
99
"""Represents a GPIO chip.
1010
1111
Arguments:
12-
num: Chip number. Defaults to zero.
12+
label: Chip label. Run "gpiodetect" to list GPIO chip labels.
13+
14+
num: Chip number. Deprecated. Defaults to zero.
15+
Only used if you don't use a label.
1316
1417
consumer: A string for display by kernel utilities.
15-
Defaults to the program's name.
18+
Defaults to the program name.
1619
1720
"""
1821
_chip = None
1922

20-
def __init__(self, num=0, consumer=sys.argv[0]):
23+
def __init__(self, num=0, label=None, consumer=sys.argv[0]):
2124
self._num = num
25+
self._label = label
2226
self._consumer = consumer
2327

2428
def __repr__(self):
25-
return "%s(%s)" % (self.__class__.__name, self._num)
29+
if self._label is None:
30+
return "%s(%d)" % (self.__class__.__name, self._num)
31+
else:
32+
return "%s(%s)" % (self.__class__.__name, self._label)
2633

2734
def __enter__(self):
28-
self._chip = gpio.lib.gpiod_chip_open_by_number(self._num)
35+
if self._label is None:
36+
self._chip = gpio.lib.gpiod_chip_open_by_number(self._num)
37+
else:
38+
self._chip = gpio.lib.gpiod_chip_open_by_label(self._label)
2939
if self._chip == gpio.ffi.NULL:
3040
raise OSError("unable to open chip")
3141
return self

0 commit comments

Comments
 (0)