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:
Dave Jones
2016-08-30 15:16:15 +01:00
parent bb8ea5249d
commit 6f67a973cf
6 changed files with 45 additions and 32 deletions

View File

@@ -12,9 +12,9 @@ devices = [InputDevice(device) for device in list_devices()]
must_have = {i for i in range(1, 32)} must_have = {i for i in range(1, 32)}
must_not_have = {0} must_not_have = {0}
devices = [ devices = [
device dev
for device in devices for dev in devices
for keys in (set(device.capabilities().get(ecodes.EV_KEY, [])),) for keys in (set(dev.capabilities().get(ecodes.EV_KEY, [])),)
if must_have.issubset(keys) if must_have.issubset(keys)
and must_not_have.isdisjoint(keys) and must_not_have.isdisjoint(keys)
] ]

View File

@@ -9,6 +9,8 @@ library. Please note that all recipes are written assuming Python 3. Recipes
*may* work under Python 2, but no guarantees! *may* work under Python 2, but no guarantees!
.. _pin_numbering:
Pin Numbering Pin Numbering
============= =============
@@ -18,8 +20,9 @@ configurable.
.. _RPi.GPIO: https://pypi.python.org/pypi/RPi.GPIO .. _RPi.GPIO: https://pypi.python.org/pypi/RPi.GPIO
Any pin marked ``GPIO`` in the diagram below can be used for generic Any pin marked "GPIO" in the diagram below can be used as a pin number. For
components: example, if an LED was attached to "GPIO17" you would specify the pin number as
17 rather than 11:
.. image:: images/pin_layout.* .. image:: images/pin_layout.*

View File

@@ -240,8 +240,8 @@ class Button(HoldMixin, DigitalInputDevice):
print("The button was pressed!") print("The button was pressed!")
:param int pin: :param int pin:
The GPIO pin which the button is attached to. See :doc:`notes` for The GPIO pin which the button is attached to. See :ref:`pin_numbering`
valid pin numbers. for valid pin numbers.
:param bool pull_up: :param bool pull_up:
If ``True`` (the default), the GPIO pin will be pulled high by default. If ``True`` (the default), the GPIO pin will be pulled high by default.
@@ -302,8 +302,8 @@ class LineSensor(SmoothedInputDevice):
pause() pause()
:param int pin: :param int pin:
The GPIO pin which the sensor is attached to. See :doc:`notes` for The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
valid pin numbers. for valid pin numbers.
:param int queue_len: :param int queue_len:
The length of the queue used to store values read from the sensor. This The length of the queue used to store values read from the sensor. This
@@ -371,8 +371,8 @@ class MotionSensor(SmoothedInputDevice):
print("Motion detected!") print("Motion detected!")
:param int pin: :param int pin:
The GPIO pin which the sensor is attached to. See :doc:`notes` for The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
valid pin numbers. for valid pin numbers.
:param int queue_len: :param int queue_len:
The length of the queue used to store values read from the sensor. This The length of the queue used to store values read from the sensor. This
@@ -435,8 +435,8 @@ class LightSensor(SmoothedInputDevice):
print("Light detected!") print("Light detected!")
:param int pin: :param int pin:
The GPIO pin which the sensor is attached to. See :doc:`notes` for The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
valid pin numbers. for valid pin numbers.
:param int queue_len: :param int queue_len:
The length of the queue used to store values read from the circuit. The length of the queue used to store values read from the circuit.
@@ -542,12 +542,12 @@ class DistanceSensor(SmoothedInputDevice):
sleep(1) sleep(1)
:param int echo: :param int echo:
The GPIO pin which the ECHO pin is attached to. See :doc:`notes` for The GPIO pin which the ECHO pin is attached to. See
valid pin numbers. :ref:`pin_numbering` for valid pin numbers.
:param int trigger: :param int trigger:
The GPIO pin which the TRIG pin is attached to. See :doc:`notes` for The GPIO pin which the TRIG pin is attached to. See
valid pin numbers. :ref:`pin_numbering` for valid pin numbers.
:param int queue_len: :param int queue_len:
The length of the queue used to store values read from the sensor. The length of the queue used to store values read from the sensor.

View File

@@ -217,8 +217,8 @@ class LED(DigitalOutputDevice):
led.on() led.on()
:param int pin: :param int pin:
The GPIO pin which the LED is attached to. See :doc:`notes` for valid The GPIO pin which the LED is attached to. See :ref:`pin_numbering` for
pin numbers. valid pin numbers.
:param bool active_high: :param bool active_high:
If ``True`` (the default), the LED will operate normally with the If ``True`` (the default), the LED will operate normally with the
@@ -252,8 +252,8 @@ class Buzzer(DigitalOutputDevice):
bz.on() bz.on()
:param int pin: :param int pin:
The GPIO pin which the buzzer is attached to. See :doc:`notes` for The GPIO pin which the buzzer is attached to. See :ref:`pin_numbering`
valid pin numbers. for valid pin numbers.
:param bool active_high: :param bool active_high:
If ``True`` (the default), the buzzer will operate normally with the 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). Generic output device configured for pulse-width modulation (PWM).
:param int pin: :param int pin:
The GPIO pin which the device is attached to. See :doc:`notes` for The GPIO pin which the device is attached to. See :ref:`pin_numbering`
valid pin numbers. for valid pin numbers.
:param bool active_high: :param bool active_high:
If ``True`` (the default), the :meth:`on` method will set the GPIO to 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. an optional resistor to prevent the LED from burning out.
:param int pin: :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. valid pin numbers.
:param bool active_high: :param bool active_high:
@@ -897,3 +897,4 @@ class Motor(SourceMixin, CompositeDevice):
""" """
self.forward_device.off() self.forward_device.off()
self.backward_device.off() self.backward_device.off()

View File

@@ -573,10 +573,12 @@ def _parse_pi_revision(revision):
'3B': True, '3B': True,
}.get(model, False) }.get(model, False)
csi = { csi = {
'Zero': 0 if pcb_revision == '0.0' else 1, 'Zero': 0 if pcb_revision == '1.0' else 1,
'CM': 2, 'CM': 2,
}.get(model, 1) }.get(model, 1)
dsi = csi dsi = {
'Zero': 0,
}.get(model, csi)
headers = { headers = {
'A': {'P1': REV2_P1, 'P5': REV2_P5}, 'A': {'P1': REV2_P1, 'P5': REV2_P5},
'B': {'P1': REV2_P1, 'P5': REV2_P5} if pcb_revision == '2.0' else {'P1': REV1_P1}, 'B': {'P1': REV2_P1, 'P5': REV2_P5} if pcb_revision == '2.0' else {'P1': REV1_P1},

View File

@@ -106,7 +106,7 @@ class PiGPIOPin(Pin):
return cls._PINS[(host, port, number)] return cls._PINS[(host, port, number)]
except KeyError: except KeyError:
self = super(PiGPIOPin, cls).__new__(cls) 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)] self._connection, self._pi_info = cls._CONNECTIONS[(host, port)]
try: try:
self._pi_info.physical_pin('GPIO%d' % number) self._pi_info.physical_pin('GPIO%d' % number)
@@ -129,7 +129,6 @@ class PiGPIOPin(Pin):
raise ValueError(e) raise ValueError(e)
self._connection.set_pull_up_down(self._number, self.GPIO_PULL_UPS[self._pull]) 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_glitch_filter(self._number, 0)
self._connection.set_PWM_range(self._number, 255)
cls._PINS[(host, port, number)] = self cls._PINS[(host, port, number)] = self
return self return self
@@ -175,14 +174,19 @@ class PiGPIOPin(Pin):
def _get_state(self): def _get_state(self):
if self._pwm: 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: else:
return bool(self._connection.read(self._number)) return bool(self._connection.read(self._number))
def _set_state(self, value): def _set_state(self, value):
if self._pwm: if self._pwm:
try: 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: except pigpio.error:
raise PinInvalidState('invalid state "%s" for pin %r' % (value, self)) raise PinInvalidState('invalid state "%s" for pin %r' % (value, self))
elif self.function == 'input': elif self.function == 'input':
@@ -213,12 +217,15 @@ class PiGPIOPin(Pin):
def _set_frequency(self, value): def _set_frequency(self, value):
if not self._pwm and value is not None: if not self._pwm and value is not None:
self._connection.set_PWM_frequency(self._number, value) 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._connection.set_PWM_dutycycle(self._number, 0)
self._pwm = True self._pwm = True
elif self._pwm and value is not None: 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: elif self._pwm and value is None:
self._connection.set_PWM_dutycycle(self._number, 0) self._connection.write(self._number, 0)
self._pwm = False self._pwm = False
def _get_bounce(self): def _get_bounce(self):