mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Fix all the stuff you broke last night...
In particular the `pi_revision` thing in PiGPIOPin, all the stuff @lurch picked up in `pins/data.py` (thank goodness *someone's* watching!), and make all those links pointing to "Notes" point somewhere useful like "Pin Numbering"...
This commit is contained in:
@@ -12,9 +12,9 @@ devices = [InputDevice(device) for device in list_devices()]
|
||||
must_have = {i for i in range(1, 32)}
|
||||
must_not_have = {0}
|
||||
devices = [
|
||||
device
|
||||
for device in devices
|
||||
for keys in (set(device.capabilities().get(ecodes.EV_KEY, [])),)
|
||||
dev
|
||||
for dev in devices
|
||||
for keys in (set(dev.capabilities().get(ecodes.EV_KEY, [])),)
|
||||
if must_have.issubset(keys)
|
||||
and must_not_have.isdisjoint(keys)
|
||||
]
|
||||
|
||||
@@ -9,6 +9,8 @@ library. Please note that all recipes are written assuming Python 3. Recipes
|
||||
*may* work under Python 2, but no guarantees!
|
||||
|
||||
|
||||
.. _pin_numbering:
|
||||
|
||||
Pin Numbering
|
||||
=============
|
||||
|
||||
@@ -18,8 +20,9 @@ configurable.
|
||||
|
||||
.. _RPi.GPIO: https://pypi.python.org/pypi/RPi.GPIO
|
||||
|
||||
Any pin marked ``GPIO`` in the diagram below can be used for generic
|
||||
components:
|
||||
Any pin marked "GPIO" in the diagram below can be used as a pin number. For
|
||||
example, if an LED was attached to "GPIO17" you would specify the pin number as
|
||||
17 rather than 11:
|
||||
|
||||
.. image:: images/pin_layout.*
|
||||
|
||||
|
||||
@@ -240,8 +240,8 @@ class Button(HoldMixin, DigitalInputDevice):
|
||||
print("The button was pressed!")
|
||||
|
||||
:param int pin:
|
||||
The GPIO pin which the button is attached to. See :doc:`notes` for
|
||||
valid pin numbers.
|
||||
The GPIO pin which the button is attached to. See :ref:`pin_numbering`
|
||||
for valid pin numbers.
|
||||
|
||||
:param bool pull_up:
|
||||
If ``True`` (the default), the GPIO pin will be pulled high by default.
|
||||
@@ -302,8 +302,8 @@ class LineSensor(SmoothedInputDevice):
|
||||
pause()
|
||||
|
||||
:param int pin:
|
||||
The GPIO pin which the sensor is attached to. See :doc:`notes` for
|
||||
valid pin numbers.
|
||||
The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
|
||||
for valid pin numbers.
|
||||
|
||||
:param int queue_len:
|
||||
The length of the queue used to store values read from the sensor. This
|
||||
@@ -371,8 +371,8 @@ class MotionSensor(SmoothedInputDevice):
|
||||
print("Motion detected!")
|
||||
|
||||
:param int pin:
|
||||
The GPIO pin which the sensor is attached to. See :doc:`notes` for
|
||||
valid pin numbers.
|
||||
The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
|
||||
for valid pin numbers.
|
||||
|
||||
:param int queue_len:
|
||||
The length of the queue used to store values read from the sensor. This
|
||||
@@ -435,8 +435,8 @@ class LightSensor(SmoothedInputDevice):
|
||||
print("Light detected!")
|
||||
|
||||
:param int pin:
|
||||
The GPIO pin which the sensor is attached to. See :doc:`notes` for
|
||||
valid pin numbers.
|
||||
The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
|
||||
for valid pin numbers.
|
||||
|
||||
:param int queue_len:
|
||||
The length of the queue used to store values read from the circuit.
|
||||
@@ -542,12 +542,12 @@ class DistanceSensor(SmoothedInputDevice):
|
||||
sleep(1)
|
||||
|
||||
:param int echo:
|
||||
The GPIO pin which the ECHO pin is attached to. See :doc:`notes` for
|
||||
valid pin numbers.
|
||||
The GPIO pin which the ECHO pin is attached to. See
|
||||
:ref:`pin_numbering` for valid pin numbers.
|
||||
|
||||
:param int trigger:
|
||||
The GPIO pin which the TRIG pin is attached to. See :doc:`notes` for
|
||||
valid pin numbers.
|
||||
The GPIO pin which the TRIG pin is attached to. See
|
||||
:ref:`pin_numbering` for valid pin numbers.
|
||||
|
||||
:param int queue_len:
|
||||
The length of the queue used to store values read from the sensor.
|
||||
|
||||
@@ -217,8 +217,8 @@ class LED(DigitalOutputDevice):
|
||||
led.on()
|
||||
|
||||
:param int pin:
|
||||
The GPIO pin which the LED is attached to. See :doc:`notes` for valid
|
||||
pin numbers.
|
||||
The GPIO pin which the LED is attached to. See :ref:`pin_numbering` for
|
||||
valid pin numbers.
|
||||
|
||||
:param bool active_high:
|
||||
If ``True`` (the default), the LED will operate normally with the
|
||||
@@ -252,8 +252,8 @@ class Buzzer(DigitalOutputDevice):
|
||||
bz.on()
|
||||
|
||||
:param int pin:
|
||||
The GPIO pin which the buzzer is attached to. See :doc:`notes` for
|
||||
valid pin numbers.
|
||||
The GPIO pin which the buzzer is attached to. See :ref:`pin_numbering`
|
||||
for valid pin numbers.
|
||||
|
||||
:param bool active_high:
|
||||
If ``True`` (the default), the buzzer will operate normally with the
|
||||
@@ -276,8 +276,8 @@ class PWMOutputDevice(OutputDevice):
|
||||
Generic output device configured for pulse-width modulation (PWM).
|
||||
|
||||
:param int pin:
|
||||
The GPIO pin which the device is attached to. See :doc:`notes` for
|
||||
valid pin numbers.
|
||||
The GPIO pin which the device is attached to. See :ref:`pin_numbering`
|
||||
for valid pin numbers.
|
||||
|
||||
:param bool active_high:
|
||||
If ``True`` (the default), the :meth:`on` method will set the GPIO to
|
||||
@@ -483,7 +483,7 @@ class PWMLED(PWMOutputDevice):
|
||||
an optional resistor to prevent the LED from burning out.
|
||||
|
||||
:param int pin:
|
||||
The GPIO pin which the LED is attached to. See :doc:`notes` for
|
||||
The GPIO pin which the LED is attached to. See :ref:`pin_numbering` for
|
||||
valid pin numbers.
|
||||
|
||||
:param bool active_high:
|
||||
@@ -897,3 +897,4 @@ class Motor(SourceMixin, CompositeDevice):
|
||||
"""
|
||||
self.forward_device.off()
|
||||
self.backward_device.off()
|
||||
|
||||
|
||||
@@ -573,10 +573,12 @@ def _parse_pi_revision(revision):
|
||||
'3B': True,
|
||||
}.get(model, False)
|
||||
csi = {
|
||||
'Zero': 0 if pcb_revision == '0.0' else 1,
|
||||
'Zero': 0 if pcb_revision == '1.0' else 1,
|
||||
'CM': 2,
|
||||
}.get(model, 1)
|
||||
dsi = csi
|
||||
dsi = {
|
||||
'Zero': 0,
|
||||
}.get(model, csi)
|
||||
headers = {
|
||||
'A': {'P1': REV2_P1, 'P5': REV2_P5},
|
||||
'B': {'P1': REV2_P1, 'P5': REV2_P5} if pcb_revision == '2.0' else {'P1': REV1_P1},
|
||||
|
||||
@@ -106,7 +106,7 @@ class PiGPIOPin(Pin):
|
||||
return cls._PINS[(host, port, number)]
|
||||
except KeyError:
|
||||
self = super(PiGPIOPin, cls).__new__(cls)
|
||||
cls.pi_revision(host, port) # implicitly creates connection
|
||||
cls.pi_info(host, port) # implicitly creates connection
|
||||
self._connection, self._pi_info = cls._CONNECTIONS[(host, port)]
|
||||
try:
|
||||
self._pi_info.physical_pin('GPIO%d' % number)
|
||||
@@ -129,7 +129,6 @@ class PiGPIOPin(Pin):
|
||||
raise ValueError(e)
|
||||
self._connection.set_pull_up_down(self._number, self.GPIO_PULL_UPS[self._pull])
|
||||
self._connection.set_glitch_filter(self._number, 0)
|
||||
self._connection.set_PWM_range(self._number, 255)
|
||||
cls._PINS[(host, port, number)] = self
|
||||
return self
|
||||
|
||||
@@ -175,14 +174,19 @@ class PiGPIOPin(Pin):
|
||||
|
||||
def _get_state(self):
|
||||
if self._pwm:
|
||||
return self._connection.get_PWM_dutycycle(self._number) / 255
|
||||
return (
|
||||
self._connection.get_PWM_dutycycle(self._number) /
|
||||
self._connection.get_PWM_range(self._number)
|
||||
)
|
||||
else:
|
||||
return bool(self._connection.read(self._number))
|
||||
|
||||
def _set_state(self, value):
|
||||
if self._pwm:
|
||||
try:
|
||||
self._connection.set_PWM_dutycycle(self._number, int(value * 255))
|
||||
value = int(value * self._connection.get_PWM_range(self._number))
|
||||
if value != self._connection.get_PWM_dutycycle(self._number):
|
||||
self._connection.set_PWM_dutycycle(self._number, value)
|
||||
except pigpio.error:
|
||||
raise PinInvalidState('invalid state "%s" for pin %r' % (value, self))
|
||||
elif self.function == 'input':
|
||||
@@ -213,12 +217,15 @@ class PiGPIOPin(Pin):
|
||||
def _set_frequency(self, value):
|
||||
if not self._pwm and value is not None:
|
||||
self._connection.set_PWM_frequency(self._number, value)
|
||||
self._connection.set_PWM_range(self._number, 10000)
|
||||
self._connection.set_PWM_dutycycle(self._number, 0)
|
||||
self._pwm = True
|
||||
elif self._pwm and value is not None:
|
||||
self._connection.set_PWM_frequency(self._number, value)
|
||||
if value != self._connection.get_PWM_frequency(self._number):
|
||||
self._connection.set_PWM_frequency(self._number, value)
|
||||
self._connection.set_PWM_range(self._number, 10000)
|
||||
elif self._pwm and value is None:
|
||||
self._connection.set_PWM_dutycycle(self._number, 0)
|
||||
self._connection.write(self._number, 0)
|
||||
self._pwm = False
|
||||
|
||||
def _get_bounce(self):
|
||||
|
||||
Reference in New Issue
Block a user