def test_global_find_line_function(self): line = gpiod.find_line('gpio-mockup-B-4') self.assertNotEqual(line, None) try: self.assertEqual(line.owner().label(), 'gpio-mockup-B') self.assertEqual(line.offset(), 4) finally: line.owner().close()
def __init__(self, name, direction=INPUT, default_val=None): self._direction = direction self._line = gpiod.find_line(name) self._out_value = False if self._line is None: raise RuntimeError('failed to find gpio with name %s' % name) if default_val is not None and direction == Gpio.OUTPUT: self.set(default_val)
def cfg_to_line(cfg): if 'name' in cfg: name = cfg['name'] line = gpiod.find_line(name) if not line: raise FileNotFoundError(errno.ENOENT, "No such GPIO line", name) else: try: chip = gpiod.Chip(cfg['chip'], gpiod.Chip.OPEN_LOOKUP) line = chip.get_line(cfg['line']) except FileNotFoundError as e: e.strerror = "No such GPIO chip" e.filename = cfg['chip'] raise e except OSError as e: if e.errno == errno.EINVAL: raise FileNotFoundError( errno.ENOENT, "GPIO chip '%s' has no line %d" % (cfg['chip'], cfg['line'])) raise e return line
def test_global_find_line_function_nonexistent(self): line = gpiod.find_line('nonexistent-line') self.assertEqual(line, None)
#!/usr/bin/env python3 # SPDX-License-Identifier: LGPL-2.1-or-later # # This file is part of libgpiod. # # Copyright (C) 2017-2018 Bartosz Golaszewski <*****@*****.**> # '''Reimplementation of the gpiofind tool in Python.''' import gpiod import sys line = gpiod.find_line(sys.argv[1]) print('{} {}'.format(line.owner().name(), line.offset()))
def find_line(): line = gpiod.find_line('gpio-mockup-A-4') print('found line - offset: {}'.format(line.offset()))
def setup(self, line, direction): self.chip = gpiod.find_line(str(line)).owner().name() self.offset = gpiod.find_line(str(line)).offset() self.offsetList.append(self.offset) self.pin = gpiod.Chip(self.chip).get_lines(self.offsetList) self.pin.request(consumer=self.chip, type=direction)