@@ -9,23 +9,33 @@ class Chip:
9
9
"""Represents a GPIO chip.
10
10
11
11
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.
13
16
14
17
consumer: A string for display by kernel utilities.
15
- Defaults to the program's name.
18
+ Defaults to the program name.
16
19
17
20
"""
18
21
_chip = None
19
22
20
- def __init__ (self , num = 0 , consumer = sys .argv [0 ]):
23
+ def __init__ (self , num = 0 , label = None , consumer = sys .argv [0 ]):
21
24
self ._num = num
25
+ self ._label = label
22
26
self ._consumer = consumer
23
27
24
28
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 )
26
33
27
34
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 )
29
39
if self ._chip == gpio .ffi .NULL :
30
40
raise OSError ("unable to open chip" )
31
41
return self
0 commit comments