mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Overhaul the pi_info system: Pin factories are now capable of generating pi_info themselves (although currently they all just look up the revision and call pi_info with a specific one). PiGPIOPin will now return pi_info for the remote pi which can be specified by parameter or implicitly by the environment vars. Overvolted Pis should work properly no matter what (some argument over whether the revision 7 or 8 chars in this case; both should work). Added some minor tweaks for the new camera-capable Pi Zero Finally, added a bunch of tests for pins.data
This commit is contained in:
@@ -37,28 +37,21 @@ You can change the default pin implementation by over-writing the
|
||||
# This will now use NativePin instead of RPiGPIOPin
|
||||
led = LED(16)
|
||||
|
||||
``pin_factory`` is simply a callable that accepts a single argument: the number
|
||||
of the pin to be constructed (this prototype *may* be expanded in future). This
|
||||
means you can define it as a function that provides additional parameters to an
|
||||
underlying class. For example, to default to creating pins with
|
||||
:class:`gpiozero.pins.pigpiod.PiGPIOPin` on a remote pi called ``remote-pi``::
|
||||
``pin_factory`` is a concrete descendent of the abstract :class:`Pin` class.
|
||||
The descendent may take additional parameters in its constructor provided they
|
||||
are optional; GPIO Zero will expect to be able to construct instances with
|
||||
nothing more than an integer pin number.
|
||||
|
||||
from gpiozero.pins.pigpiod import PiGPIOPin
|
||||
import gpiozero.devices
|
||||
However, the descendent may take default information from additional sources.
|
||||
For example, to default to creating pins with
|
||||
:class:`gpiozero.pins.pigpiod.PiGPIOPin` on a remote pi called ``remote-pi``
|
||||
you can set the :envvar:`PIGPIO_ADDR` environment variable when running your
|
||||
script::
|
||||
|
||||
def my_pin_factory(number):
|
||||
return PiGPIOPin(number, host='remote-pi')
|
||||
$ PIGPIO_ADDR=remote-pi python my_script.py
|
||||
|
||||
gpiozero.devices.pin_factory = my_pin_factory
|
||||
|
||||
from gpiozero import TrafficLights
|
||||
|
||||
# This will now use pins on remote-pi (assuming it has the
|
||||
# pigpiod daemon installed and running)
|
||||
tl = TrafficLights(13, 19, 26)
|
||||
|
||||
Alternatively, instead of passing an integer to the device constructor, you
|
||||
can pass an object derived from :class:`Pin` itself::
|
||||
It is worth noting that instead of passing an integer to device constructors,
|
||||
you can pass an object derived from :class:`Pin` itself::
|
||||
|
||||
from gpiozero.pins.native import NativePin
|
||||
from gpiozero import LED
|
||||
@@ -121,6 +114,13 @@ Abstract Pin
|
||||
:members:
|
||||
|
||||
|
||||
Local Pin
|
||||
=========
|
||||
|
||||
.. autoclass:: LocalPin
|
||||
:members:
|
||||
|
||||
|
||||
Utilities
|
||||
=========
|
||||
|
||||
|
||||
Reference in New Issue
Block a user