Skip to content

Commit 6f67a97

Browse files
committed
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"...
1 parent bb8ea52 commit 6f67a97

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
lines changed

docs/examples/robot_keyboard_2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
must_have = {i for i in range(1, 32)}
1313
must_not_have = {0}
1414
devices = [
15-
device
16-
for device in devices
17-
for keys in (set(device.capabilities().get(ecodes.EV_KEY, [])),)
15+
dev
16+
for dev in devices
17+
for keys in (set(dev.capabilities().get(ecodes.EV_KEY, [])),)
1818
if must_have.issubset(keys)
1919
and must_not_have.isdisjoint(keys)
2020
]

docs/recipes.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ library. Please note that all recipes are written assuming Python 3. Recipes
99
*may* work under Python 2, but no guarantees!
1010

1111

12+
.. _pin_numbering:
13+
1214
Pin Numbering
1315
=============
1416

@@ -18,8 +20,9 @@ configurable.
1820

1921
.. _RPi.GPIO: https://pypi.python.org/pypi/RPi.GPIO
2022

21-
Any pin marked ``GPIO`` in the diagram below can be used for generic
22-
components:
23+
Any pin marked "GPIO" in the diagram below can be used as a pin number. For
24+
example, if an LED was attached to "GPIO17" you would specify the pin number as
25+
17 rather than 11:
2326

2427
.. image:: images/pin_layout.*
2528

gpiozero/input_devices.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ class Button(HoldMixin, DigitalInputDevice):
240240
print("The button was pressed!")
241241
242242
:param int pin:
243-
The GPIO pin which the button is attached to. See :doc:`notes` for
244-
valid pin numbers.
243+
The GPIO pin which the button is attached to. See :ref:`pin_numbering`
244+
for valid pin numbers.
245245
246246
:param bool pull_up:
247247
If ``True`` (the default), the GPIO pin will be pulled high by default.
@@ -302,8 +302,8 @@ class LineSensor(SmoothedInputDevice):
302302
pause()
303303
304304
:param int pin:
305-
The GPIO pin which the sensor is attached to. See :doc:`notes` for
306-
valid pin numbers.
305+
The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
306+
for valid pin numbers.
307307
308308
:param int queue_len:
309309
The length of the queue used to store values read from the sensor. This
@@ -371,8 +371,8 @@ class MotionSensor(SmoothedInputDevice):
371371
print("Motion detected!")
372372
373373
:param int pin:
374-
The GPIO pin which the sensor is attached to. See :doc:`notes` for
375-
valid pin numbers.
374+
The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
375+
for valid pin numbers.
376376
377377
:param int queue_len:
378378
The length of the queue used to store values read from the sensor. This
@@ -435,8 +435,8 @@ class LightSensor(SmoothedInputDevice):
435435
print("Light detected!")
436436
437437
:param int pin:
438-
The GPIO pin which the sensor is attached to. See :doc:`notes` for
439-
valid pin numbers.
438+
The GPIO pin which the sensor is attached to. See :ref:`pin_numbering`
439+
for valid pin numbers.
440440
441441
:param int queue_len:
442442
The length of the queue used to store values read from the circuit.
@@ -542,12 +542,12 @@ class DistanceSensor(SmoothedInputDevice):
542542
sleep(1)
543543
544544
:param int echo:
545-
The GPIO pin which the ECHO pin is attached to. See :doc:`notes` for
546-
valid pin numbers.
545+
The GPIO pin which the ECHO pin is attached to. See
546+
:ref:`pin_numbering` for valid pin numbers.
547547
548548
:param int trigger:
549-
The GPIO pin which the TRIG pin is attached to. See :doc:`notes` for
550-
valid pin numbers.
549+
The GPIO pin which the TRIG pin is attached to. See
550+
:ref:`pin_numbering` for valid pin numbers.
551551
552552
:param int queue_len:
553553
The length of the queue used to store values read from the sensor.

gpiozero/output_devices.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ class LED(DigitalOutputDevice):
217217
led.on()
218218
219219
:param int pin:
220-
The GPIO pin which the LED is attached to. See :doc:`notes` for valid
221-
pin numbers.
220+
The GPIO pin which the LED is attached to. See :ref:`pin_numbering` for
221+
valid pin numbers.
222222
223223
:param bool active_high:
224224
If ``True`` (the default), the LED will operate normally with the
@@ -252,8 +252,8 @@ class Buzzer(DigitalOutputDevice):
252252
bz.on()
253253
254254
:param int pin:
255-
The GPIO pin which the buzzer is attached to. See :doc:`notes` for
256-
valid pin numbers.
255+
The GPIO pin which the buzzer is attached to. See :ref:`pin_numbering`
256+
for valid pin numbers.
257257
258258
:param bool active_high:
259259
If ``True`` (the default), the buzzer will operate normally with the
@@ -276,8 +276,8 @@ class PWMOutputDevice(OutputDevice):
276276
Generic output device configured for pulse-width modulation (PWM).
277277
278278
:param int pin:
279-
The GPIO pin which the device is attached to. See :doc:`notes` for
280-
valid pin numbers.
279+
The GPIO pin which the device is attached to. See :ref:`pin_numbering`
280+
for valid pin numbers.
281281
282282
:param bool active_high:
283283
If ``True`` (the default), the :meth:`on` method will set the GPIO to
@@ -483,7 +483,7 @@ class PWMLED(PWMOutputDevice):
483483
an optional resistor to prevent the LED from burning out.
484484
485485
:param int pin:
486-
The GPIO pin which the LED is attached to. See :doc:`notes` for
486+
The GPIO pin which the LED is attached to. See :ref:`pin_numbering` for
487487
valid pin numbers.
488488
489489
:param bool active_high:
@@ -897,3 +897,4 @@ def stop(self):
897897
"""
898898
self.forward_device.off()
899899
self.backward_device.off()
900+

gpiozero/pins/data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,12 @@ def _parse_pi_revision(revision):
573573
'3B': True,
574574
}.get(model, False)
575575
csi = {
576-
'Zero': 0 if pcb_revision == '0.0' else 1,
576+
'Zero': 0 if pcb_revision == '1.0' else 1,
577577
'CM': 2,
578578
}.get(model, 1)
579-
dsi = csi
579+
dsi = {
580+
'Zero': 0,
581+
}.get(model, csi)
580582
headers = {
581583
'A': {'P1': REV2_P1, 'P5': REV2_P5},
582584
'B': {'P1': REV2_P1, 'P5': REV2_P5} if pcb_revision == '2.0' else {'P1': REV1_P1},

gpiozero/pins/pigpiod.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __new__(
106106
return cls._PINS[(host, port, number)]
107107
except KeyError:
108108
self = super(PiGPIOPin, cls).__new__(cls)
109-
cls.pi_revision(host, port) # implicitly creates connection
109+
cls.pi_info(host, port) # implicitly creates connection
110110
self._connection, self._pi_info = cls._CONNECTIONS[(host, port)]
111111
try:
112112
self._pi_info.physical_pin('GPIO%d' % number)
@@ -129,7 +129,6 @@ def __new__(
129129
raise ValueError(e)
130130
self._connection.set_pull_up_down(self._number, self.GPIO_PULL_UPS[self._pull])
131131
self._connection.set_glitch_filter(self._number, 0)
132-
self._connection.set_PWM_range(self._number, 255)
133132
cls._PINS[(host, port, number)] = self
134133
return self
135134

@@ -175,14 +174,19 @@ def _set_function(self, value):
175174

176175
def _get_state(self):
177176
if self._pwm:
178-
return self._connection.get_PWM_dutycycle(self._number) / 255
177+
return (
178+
self._connection.get_PWM_dutycycle(self._number) /
179+
self._connection.get_PWM_range(self._number)
180+
)
179181
else:
180182
return bool(self._connection.read(self._number))
181183

182184
def _set_state(self, value):
183185
if self._pwm:
184186
try:
185-
self._connection.set_PWM_dutycycle(self._number, int(value * 255))
187+
value = int(value * self._connection.get_PWM_range(self._number))
188+
if value != self._connection.get_PWM_dutycycle(self._number):
189+
self._connection.set_PWM_dutycycle(self._number, value)
186190
except pigpio.error:
187191
raise PinInvalidState('invalid state "%s" for pin %r' % (value, self))
188192
elif self.function == 'input':
@@ -213,12 +217,15 @@ def _get_frequency(self):
213217
def _set_frequency(self, value):
214218
if not self._pwm and value is not None:
215219
self._connection.set_PWM_frequency(self._number, value)
220+
self._connection.set_PWM_range(self._number, 10000)
216221
self._connection.set_PWM_dutycycle(self._number, 0)
217222
self._pwm = True
218223
elif self._pwm and value is not None:
219-
self._connection.set_PWM_frequency(self._number, value)
224+
if value != self._connection.get_PWM_frequency(self._number):
225+
self._connection.set_PWM_frequency(self._number, value)
226+
self._connection.set_PWM_range(self._number, 10000)
220227
elif self._pwm and value is None:
221-
self._connection.set_PWM_dutycycle(self._number, 0)
228+
self._connection.write(self._number, 0)
222229
self._pwm = False
223230

224231
def _get_bounce(self):

0 commit comments

Comments
 (0)