Skip to content

Commit

Permalink
Merge pull request #60 from RaspberryPiFoundation/dev
Browse files Browse the repository at this point in the history
v0.1.1
  • Loading branch information
Martin O'Hanlon authored Jun 8, 2022
2 parents 6d8d12c + 0acaa00 commit 723772d
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 11 deletions.
11 changes: 10 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ Change log

.. currentmodule:: picozero

0.1.1 - 2022-06-08
~~~~~~~~~~~~~~~~~~

+ Minor bug fixes found during testing
+ Small improvements to exception messages
+ Added close methods to Speaker and PWMOutputDevice
+ Added unit tests
+ Added RGBLED.colour as an alias to RGBLED.color

0.1.0 - 2022-04-08
~~~~~~~~~~~~~~~~~~

+ Beta release
+ Documentation updates
+ Documentation update
+ Minor bug fixes and refactoring

0.0.2 - 2022-03-31
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __getattr__(cls, name):
author = 'Raspberry Pi Foundation'

# The full version, including alpha/beta/rc tags
release = '0.1.0'
release = '0.1.1'


# -- General configuration ---------------------------------------------------
Expand Down
15 changes: 14 additions & 1 deletion docs/developing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ The website will be built in the directory docs/_build/html.

Documentation can be viewed at `picozero.readthedocs.io`_.

.. _picozero.readthedocs.io: https://picozero.readthedocs.io
.. _picozero.readthedocs.io: https://picozero.readthedocs.io

Tests
-----

The tests are design to be run on a Raspberry Pi Pico.

1. Install the `picozero <https://pypi.org/project/picozero/>`_ package.

2. Install the `micropython-unittest <https://pypi.org/project/micropython-unittest/>`_ package.

3. Copy the ``test_picozero.py`` to the pico.

4. Run the ``test_picozero.py`` file.
2 changes: 1 addition & 1 deletion picozero/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__name__ = "picozero"
__package__ = "picozero"
__version__ = '0.1.0'
__version__ = '0.1.1'
__author__ = "Raspberry Pi Foundation"

from .picozero import (
Expand Down
23 changes: 17 additions & 6 deletions picozero/picozero.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,16 @@ def _check_pwm_channel(self, pin_num):
channel = PWMOutputDevice.PIN_TO_PWM_CHANNEL[pin_num]
if channel in PWMOutputDevice._channels_used.keys():
raise PWMChannelAlreadyInUse(
f"PWM channel {channel} is already in use by pin {PWMOutputDevice._channels_used[channel]}. Use a different pin"
"PWM channel {} is already in use by {}. Use a different pin".format(
channel,
str(PWMOutputDevice._channels_used[channel])
)
)
else:
PWMOutputDevice._channels_used[channel] = pin_num
PWMOutputDevice._channels_used[channel] = self

def _state_to_value(self, state):
return (state if self.active_high else 1 - state) / self._duty_factor
return (state if self.active_high else self._duty_factor - state) / self._duty_factor

def _value_to_state(self, value):
return int(self._duty_factor * (value if self.active_high else 1 - value))
Expand Down Expand Up @@ -497,8 +500,8 @@ def close(self):
del PWMOutputDevice._channels_used[
PWMOutputDevice.PIN_TO_PWM_CHANNEL[self._pin_num]
]
self._pin.deinit()
self._pin = None
self._pwm.deinit()
self._pwm = None

class PWMLED(PWMOutputDevice):
"""
Expand Down Expand Up @@ -807,6 +810,9 @@ def tune_generator():

self._start_change(tune_generator, n, wait)

def close(self):
self._pwm_buzzer.close()

class RGBLED(OutputDevice, PinsMixin):
"""
Extends :class:`OutputDevice` and represents a full color LED component (composed
Expand Down Expand Up @@ -1077,6 +1083,8 @@ def cycle(self, fade_times=1, colors=((1, 0, 0), (0, 1, 0), (0, 0, 1)), n=None,
on_times = 0
self.blink(on_times, fade_times, colors, n, wait, fps)

RGBLED.colour = RGBLED.color

###############################################################################
# INPUT DEVICES
###############################################################################
Expand Down Expand Up @@ -1332,7 +1340,7 @@ def __init__(self, pin, active_state=True, threshold=0.5):
self._threshold = float(threshold)

def _state_to_value(self, state):
return (state if self.active_state else 1 - state) / 65535
return (state if self.active_state else 65535 - state) / 65535

def _value_to_state(self, value):
return int(65535 * (value if self.active_state else 1 - value))
Expand Down Expand Up @@ -1366,6 +1374,9 @@ def voltage(self):
"""
return self.value * 3.3

def close(self):
self._adc = None

class Potentiometer(AnalogInputDevice):
"""
Represents a Potentiometer which outputs with a variable voltage
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__project__ = 'picozero'
__packages__ = ['picozero']
__desc__ = 'A beginner-friendly library for using common electronics components with the Raspberry Pi Pico. '
__version__ = '0.1.0'
__version__ = '0.1.1'
__author__ = "Raspberry Pi Foundation"
__author_email__ = 'learning@raspberrypi.org'
__license__ = 'MIT'
Expand Down
30 changes: 30 additions & 0 deletions tests/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Tests
=====

The tests are design to be run on a Raspberry Pi Pico.

Setup
-----

1. Install the `picozero <https://pypi.org/project/picozero/>`_ package.

2. Install the `micropython-unittest <https://pypi.org/project/micropython-unittest/>`_ package.

3. Copy the ``test_picozero.py`` to the pico.

4. Run the ``test_picozero.py`` file.

Error messsages
---------------

If a test fails it is helpful to be able to see verbose error messages. To see error messages you need to modify the ``lib/unittest.py`` file on the pico.

Locate the following code in the ``run_class`` function::

# Uncomment to investigate failure in detail
#raise

Uncomment ``raise``::

# Uncomment to investigate failure in detail
raise
Loading

0 comments on commit 723772d

Please sign in to comment.