@@ -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