print('{} [{}] ({} lines)'.format(chip.name(),
chip.label(),
chip.num_lines()))
+ chip.close()
line = gpiod.find_line(sys.argv[1])
print('{} {}'.format(line.owner().name(), line.offset()))
+line.owner().close()
if len(sys.argv) < 3:
raise TypeError('usage: gpioget.py <gpiochip> <offset1> <offset2> ...')
-chip = gpiod.Chip(sys.argv[1])
-
-offsets = []
-for off in sys.argv[2:]:
- offsets.append(int(off))
-
-lines = chip.get_lines(offsets)
-lines.request(consumer=sys.argv[0], type=gpiod.LINE_REQ_DIR_IN)
-vals = lines.get_values()
-
-for val in vals:
- print(val, end=' ')
-print()
+with gpiod.Chip(sys.argv[1]) as chip:
+ offsets = []
+ for off in sys.argv[2:]:
+ offsets.append(int(off))
+
+ lines = chip.get_lines(offsets)
+ lines.request(consumer=sys.argv[0], type=gpiod.LINE_REQ_DIR_IN)
+ vals = lines.get_values()
+
+ for val in vals:
+ print(val, end=' ')
+ print()
'unused' if consumer is None else consumer,
'input' if direction == gpiod.Line.DIRECTION_INPUT else 'output',
'active-low' if active_state == gpiod.Line.ACTIVE_LOW else 'active-high'))
+
+ chip.close()
if len(sys.argv) < 3:
raise TypeError('usage: gpiomon.py <gpiochip> <offset1> <offset2> ...')
-chip = gpiod.Chip(sys.argv[1])
-
-offsets = []
-for off in sys.argv[2:]:
- offsets.append(int(off))
-
-lines = chip.get_lines(offsets)
-lines.request(consumer=sys.argv[0], type=gpiod.LINE_REQ_EV_BOTH_EDGES)
-
-try:
- while True:
- ev_lines = lines.event_wait(sec=1)
- if ev_lines:
- for line in ev_lines:
- event = line.event_read()
- print_event(event)
-except KeyboardInterrupt:
- sys.exit(130)
+with gpiod.Chip(sys.argv[1]) as chip:
+ offsets = []
+ for off in sys.argv[2:]:
+ offsets.append(int(off))
+
+ lines = chip.get_lines(offsets)
+ lines.request(consumer=sys.argv[0], type=gpiod.LINE_REQ_EV_BOTH_EDGES)
+
+ try:
+ while True:
+ ev_lines = lines.event_wait(sec=1)
+ if ev_lines:
+ for line in ev_lines:
+ event = line.event_read()
+ print_event(event)
+ except KeyboardInterrupt:
+ sys.exit(130)
if len(sys.argv) < 3:
raise TypeError('usage: gpioset.py <gpiochip> <offset1>=<value1> ...')
-chip = gpiod.Chip(sys.argv[1])
+with gpiod.Chip(sys.argv[1]) as chip:
+ offsets = []
+ values = []
+ for arg in sys.argv[2:]:
+ arg = arg.split('=')
+ offsets.append(int(arg[0]))
+ values.append(int(arg[1]))
-offsets = []
-values = []
-for arg in sys.argv[2:]:
- arg = arg.split('=')
- offsets.append(int(arg[0]))
- values.append(int(arg[1]))
-
-lines = chip.get_lines(offsets)
-lines.request(consumer=sys.argv[0], type=gpiod.LINE_REQ_DIR_OUT)
-vals = lines.set_values(values)
+ lines = chip.get_lines(offsets)
+ lines.request(consumer=sys.argv[0], type=gpiod.LINE_REQ_DIR_OUT)
+ vals = lines.set_values(values)