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

@@ -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.

View File

@@ -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()

View File

@@ -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},

View File

@@ -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):