How to use the gpiozero.devices.Device.pin_factory function in gpiozero

To help you get started, we’ve selected a few gpiozero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gpiozero / gpiozero / gpiozero / devices.py View on Github external
def __init__(self, **kwargs):
        # Force pin_factory to be keyword-only, even in Python 2
        pin_factory = kwargs.pop('pin_factory', None)
        if pin_factory is None:
            if Device.pin_factory is None:
                Device.pin_factory = Device._default_pin_factory()
            self.pin_factory = Device.pin_factory
        else:
            self.pin_factory = pin_factory
        if kwargs:
            raise TypeError("Device.__init__() got unexpected keyword "
                            "argument '%s'" % kwargs.popitem()[0])
        super(Device, self).__init__()
github gpiozero / gpiozero / gpiozero / devices.py View on Github external
def _devices_shutdown():
    if Device.pin_factory is not None:
        with Device.pin_factory._res_lock:
            reserved_devices = {
                dev
                for ref_list in Device.pin_factory._reservations.values()
                for ref in ref_list
                for dev in (ref(),)
                if dev is not None
            }
        for dev in reserved_devices:
            dev.close()
        Device.pin_factory.close()
        Device.pin_factory = None
github gpiozero / gpiozero / gpiozero / pins / data.py View on Github external
def pi_info(revision=None):
    """
    Returns a :class:`PiBoardInfo` instance containing information about a
    *revision* of the Raspberry Pi.

    :param str revision:
        The revision of the Pi to return information about. If this is omitted
        or :data:`None` (the default), then the library will attempt to determine
        the model of Pi it is running on and return information about that.
    """
    if revision is None:
        if Device.pin_factory is None:
            Device.pin_factory = Device._default_pin_factory()
        result = Device.pin_factory.pi_info
        if result is None:
            raise PinUnknownPi('The default pin_factory is not attached to a Pi')
        else:
            return result
    else:
        if isinstance(revision, bytes):
            revision = revision.decode('ascii')
        if isinstance(revision, str):
            revision = int(revision, base=16)
        else:
            # be nice to people passing an int (or something numeric anyway)
            revision = int(revision)
        return PiBoardInfo.from_revision(revision)
github gpiozero / gpiozero / gpiozero / devices.py View on Github external
def _devices_shutdown():
    if Device.pin_factory is not None:
        with Device.pin_factory._res_lock:
            reserved_devices = {
                dev
                for ref_list in Device.pin_factory._reservations.values()
                for ref in ref_list
                for dev in (ref(),)
                if dev is not None
            }
        for dev in reserved_devices:
            dev.close()
        Device.pin_factory.close()
        Device.pin_factory = None
github gpiozero / gpiozero / gpiozero / devices.py View on Github external
def _devices_shutdown():
    if Device.pin_factory is not None:
        with Device.pin_factory._res_lock:
            reserved_devices = {
                dev
                for ref_list in Device.pin_factory._reservations.values()
                for ref in ref_list
                for dev in (ref(),)
                if dev is not None
            }
        for dev in reserved_devices:
            dev.close()
        Device.pin_factory.close()
        Device.pin_factory = None
github gpiozero / gpiozero / gpiozero / pins / mock.py View on Github external
def __init__(
            self, clock_pin, mosi_pin=None, miso_pin=None, select_pin=None,
            clock_polarity=False, clock_phase=False, lsb_first=False,
            bits_per_word=8, select_high=False):
        self.clock_pin = Device.pin_factory.pin(clock_pin, pin_class=MockSPIClockPin)
        self.mosi_pin = None if mosi_pin is None else Device.pin_factory.pin(mosi_pin)
        self.miso_pin = None if miso_pin is None else Device.pin_factory.pin(miso_pin)
        self.select_pin = None if select_pin is None else Device.pin_factory.pin(select_pin, pin_class=MockSPISelectPin)
        self.clock_polarity = clock_polarity
        self.clock_phase = clock_phase
        self.lsb_first = lsb_first
        self.bits_per_word = bits_per_word
        self.select_high = select_high
        self.rx_bit = 0
        self.rx_buf = []
        self.tx_buf = []
        self.clock_pin.spi_devices.append(self)
        self.select_pin.spi_device = self
github gpiozero / gpiozero / gpiozero / devices.py View on Github external
def _devices_shutdown():
    if Device.pin_factory is not None:
        with Device.pin_factory._res_lock:
            reserved_devices = {
                dev
                for ref_list in Device.pin_factory._reservations.values()
                for ref in ref_list
                for dev in (ref(),)
                if dev is not None
            }
        for dev in reserved_devices:
            dev.close()
        Device.pin_factory.close()
        Device.pin_factory = None
github gpiozero / gpiozero / gpiozero / pins / mock.py View on Github external
def __init__(
            self, clock_pin, mosi_pin=None, miso_pin=None, select_pin=None,
            clock_polarity=False, clock_phase=False, lsb_first=False,
            bits_per_word=8, select_high=False):
        self.clock_pin = Device.pin_factory.pin(clock_pin, pin_class=MockSPIClockPin)
        self.mosi_pin = None if mosi_pin is None else Device.pin_factory.pin(mosi_pin)
        self.miso_pin = None if miso_pin is None else Device.pin_factory.pin(miso_pin)
        self.select_pin = None if select_pin is None else Device.pin_factory.pin(select_pin, pin_class=MockSPISelectPin)
        self.clock_polarity = clock_polarity
        self.clock_phase = clock_phase
        self.lsb_first = lsb_first
        self.bits_per_word = bits_per_word
        self.select_high = select_high
        self.rx_bit = 0
        self.rx_buf = []
        self.tx_buf = []
        self.clock_pin.spi_devices.append(self)
        self.select_pin.spi_device = self
github gpiozero / gpiozero / gpiozero / devices.py View on Github external
def _devices_shutdown():
    if Device.pin_factory is not None:
        with Device.pin_factory._res_lock:
            reserved_devices = {
                dev
                for ref_list in Device.pin_factory._reservations.values()
                for ref in ref_list
                for dev in (ref(),)
                if dev is not None
            }
        for dev in reserved_devices:
            dev.close()
        Device.pin_factory.close()
        Device.pin_factory = None
github gpiozero / gpiozero / gpiozero / devices.py View on Github external
def __init__(self, **kwargs):
        # Force pin_factory to be keyword-only, even in Python 2
        pin_factory = kwargs.pop('pin_factory', None)
        if pin_factory is None:
            if Device.pin_factory is None:
                Device.pin_factory = Device._default_pin_factory()
            self.pin_factory = Device.pin_factory
        else:
            self.pin_factory = pin_factory
        if kwargs:
            raise TypeError("Device.__init__() got unexpected keyword "
                            "argument '%s'" % kwargs.popitem()[0])
        super(Device, self).__init__()