Skip to content

Commit 723772d

Browse files
author
Martin O'Hanlon
authored
Merge pull request #60 from RaspberryPiFoundation/dev
v0.1.1
2 parents 6d8d12c + 0acaa00 commit 723772d

File tree

8 files changed

+453
-11
lines changed

8 files changed

+453
-11
lines changed

docs/changelog.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ Change log
33

44
.. currentmodule:: picozero
55

6+
0.1.1 - 2022-06-08
7+
~~~~~~~~~~~~~~~~~~
8+
9+
+ Minor bug fixes found during testing
10+
+ Small improvements to exception messages
11+
+ Added close methods to Speaker and PWMOutputDevice
12+
+ Added unit tests
13+
+ Added RGBLED.colour as an alias to RGBLED.color
14+
615
0.1.0 - 2022-04-08
716
~~~~~~~~~~~~~~~~~~
817

918
+ Beta release
10-
+ Documentation updates
19+
+ Documentation update
1120
+ Minor bug fixes and refactoring
1221

1322
0.0.2 - 2022-03-31

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __getattr__(cls, name):
4646
author = 'Raspberry Pi Foundation'
4747

4848
# The full version, including alpha/beta/rc tags
49-
release = '0.1.0'
49+
release = '0.1.1'
5050

5151

5252
# -- General configuration ---------------------------------------------------

docs/developing.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,17 @@ The website will be built in the directory docs/_build/html.
3939

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

42-
.. _picozero.readthedocs.io: https://picozero.readthedocs.io
42+
.. _picozero.readthedocs.io: https://picozero.readthedocs.io
43+
44+
Tests
45+
-----
46+
47+
The tests are design to be run on a Raspberry Pi Pico.
48+
49+
1. Install the `picozero <https://pypi.org/project/picozero/>`_ package.
50+
51+
2. Install the `micropython-unittest <https://pypi.org/project/micropython-unittest/>`_ package.
52+
53+
3. Copy the ``test_picozero.py`` to the pico.
54+
55+
4. Run the ``test_picozero.py`` file.

picozero/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__name__ = "picozero"
22
__package__ = "picozero"
3-
__version__ = '0.1.0'
3+
__version__ = '0.1.1'
44
__author__ = "Raspberry Pi Foundation"
55

66
from .picozero import (

picozero/picozero.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,16 @@ def _check_pwm_channel(self, pin_num):
364364
channel = PWMOutputDevice.PIN_TO_PWM_CHANNEL[pin_num]
365365
if channel in PWMOutputDevice._channels_used.keys():
366366
raise PWMChannelAlreadyInUse(
367-
f"PWM channel {channel} is already in use by pin {PWMOutputDevice._channels_used[channel]}. Use a different pin"
367+
"PWM channel {} is already in use by {}. Use a different pin".format(
368+
channel,
369+
str(PWMOutputDevice._channels_used[channel])
370+
)
368371
)
369372
else:
370-
PWMOutputDevice._channels_used[channel] = pin_num
373+
PWMOutputDevice._channels_used[channel] = self
371374

372375
def _state_to_value(self, state):
373-
return (state if self.active_high else 1 - state) / self._duty_factor
376+
return (state if self.active_high else self._duty_factor - state) / self._duty_factor
374377

375378
def _value_to_state(self, value):
376379
return int(self._duty_factor * (value if self.active_high else 1 - value))
@@ -497,8 +500,8 @@ def close(self):
497500
del PWMOutputDevice._channels_used[
498501
PWMOutputDevice.PIN_TO_PWM_CHANNEL[self._pin_num]
499502
]
500-
self._pin.deinit()
501-
self._pin = None
503+
self._pwm.deinit()
504+
self._pwm = None
502505

503506
class PWMLED(PWMOutputDevice):
504507
"""
@@ -807,6 +810,9 @@ def tune_generator():
807810

808811
self._start_change(tune_generator, n, wait)
809812

813+
def close(self):
814+
self._pwm_buzzer.close()
815+
810816
class RGBLED(OutputDevice, PinsMixin):
811817
"""
812818
Extends :class:`OutputDevice` and represents a full color LED component (composed
@@ -1077,6 +1083,8 @@ def cycle(self, fade_times=1, colors=((1, 0, 0), (0, 1, 0), (0, 0, 1)), n=None,
10771083
on_times = 0
10781084
self.blink(on_times, fade_times, colors, n, wait, fps)
10791085

1086+
RGBLED.colour = RGBLED.color
1087+
10801088
###############################################################################
10811089
# INPUT DEVICES
10821090
###############################################################################
@@ -1332,7 +1340,7 @@ def __init__(self, pin, active_state=True, threshold=0.5):
13321340
self._threshold = float(threshold)
13331341

13341342
def _state_to_value(self, state):
1335-
return (state if self.active_state else 1 - state) / 65535
1343+
return (state if self.active_state else 65535 - state) / 65535
13361344

13371345
def _value_to_state(self, value):
13381346
return int(65535 * (value if self.active_state else 1 - value))
@@ -1366,6 +1374,9 @@ def voltage(self):
13661374
"""
13671375
return self.value * 3.3
13681376

1377+
def close(self):
1378+
self._adc = None
1379+
13691380
class Potentiometer(AnalogInputDevice):
13701381
"""
13711382
Represents a Potentiometer which outputs with a variable voltage

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__project__ = 'picozero'
44
__packages__ = ['picozero']
55
__desc__ = 'A beginner-friendly library for using common electronics components with the Raspberry Pi Pico. '
6-
__version__ = '0.1.0'
6+
__version__ = '0.1.1'
77
__author__ = "Raspberry Pi Foundation"
88
__author_email__ = '[email protected]'
99
__license__ = 'MIT'

tests/README.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Tests
2+
=====
3+
4+
The tests are design to be run on a Raspberry Pi Pico.
5+
6+
Setup
7+
-----
8+
9+
1. Install the `picozero <https://pypi.org/project/picozero/>`_ package.
10+
11+
2. Install the `micropython-unittest <https://pypi.org/project/micropython-unittest/>`_ package.
12+
13+
3. Copy the ``test_picozero.py`` to the pico.
14+
15+
4. Run the ``test_picozero.py`` file.
16+
17+
Error messsages
18+
---------------
19+
20+
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.
21+
22+
Locate the following code in the ``run_class`` function::
23+
24+
# Uncomment to investigate failure in detail
25+
#raise
26+
27+
Uncomment ``raise``::
28+
29+
# Uncomment to investigate failure in detail
30+
raise

0 commit comments

Comments
 (0)