Skip to content

Commit d72ff6d

Browse files
author
Martin O'Hanlon
authoredApr 8, 2022
Merge pull request #43 from RaspberryPiFoundation/dev
v0.1.0
2 parents 7a237ff + 03be2b4 commit d72ff6d

14 files changed

+422
-20
lines changed
 

‎.github/CODE_OF_CONDUCT.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
2+
# Contributor Covenant Code of Conduct
3+
4+
## Our Pledge
5+
6+
We as members, contributors, and leaders pledge to make participation in our
7+
community a harassment-free experience for everyone, regardless of age, body
8+
size, visible or invisible disability, ethnicity, sex characteristics, gender
9+
identity and expression, level of experience, education, socio-economic status,
10+
nationality, personal appearance, race, caste, color, religion, or sexual
11+
identity and orientation.
12+
13+
We pledge to act and interact in ways that contribute to an open, welcoming,
14+
diverse, inclusive, and healthy community.
15+
16+
## Our Standards
17+
18+
Examples of behavior that contributes to a positive environment for our
19+
community include:
20+
21+
* Demonstrating empathy and kindness toward other people
22+
* Being respectful of differing opinions, viewpoints, and experiences
23+
* Giving and gracefully accepting constructive feedback
24+
* Accepting responsibility and apologizing to those affected by our mistakes,
25+
and learning from the experience
26+
* Focusing on what is best not just for us as individuals, but for the overall
27+
community
28+
29+
Examples of unacceptable behavior include:
30+
31+
* The use of sexualized language or imagery, and sexual attention or advances of
32+
any kind
33+
* Trolling, insulting or derogatory comments, and personal or political attacks
34+
* Public or private harassment
35+
* Publishing others' private information, such as a physical or email address,
36+
without their explicit permission
37+
* Other conduct which could reasonably be considered inappropriate in a
38+
professional setting
39+
40+
## Enforcement Responsibilities
41+
42+
Community leaders are responsible for clarifying and enforcing our standards of
43+
acceptable behavior and will take appropriate and fair corrective action in
44+
response to any behavior that they deem inappropriate, threatening, offensive,
45+
or harmful.
46+
47+
Community leaders have the right and responsibility to remove, edit, or reject
48+
comments, commits, code, wiki edits, issues, and other contributions that are
49+
not aligned to this Code of Conduct, and will communicate reasons for moderation
50+
decisions when appropriate.
51+
52+
## Scope
53+
54+
This Code of Conduct applies within all community spaces, and also applies when
55+
an individual is officially representing the community in public spaces.
56+
Examples of representing our community include using an official e-mail address,
57+
posting via an official social media account, or acting as an appointed
58+
representative at an online or offline event.
59+
60+
## Enforcement
61+
62+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
63+
reported to the community leaders responsible for enforcement at
64+
web@raspberrypi.org.
65+
All complaints will be reviewed and investigated promptly and fairly.
66+
67+
All community leaders are obligated to respect the privacy and security of the
68+
reporter of any incident.
69+
70+
## Enforcement Guidelines
71+
72+
Community leaders will follow these Community Impact Guidelines in determining
73+
the consequences for any action they deem in violation of this Code of Conduct:
74+
75+
### 1. Correction
76+
77+
**Community Impact**: Use of inappropriate language or other behavior deemed
78+
unprofessional or unwelcome in the community.
79+
80+
**Consequence**: A private, written warning from community leaders, providing
81+
clarity around the nature of the violation and an explanation of why the
82+
behavior was inappropriate. A public apology may be requested.
83+
84+
### 2. Warning
85+
86+
**Community Impact**: A violation through a single incident or series of
87+
actions.
88+
89+
**Consequence**: A warning with consequences for continued behavior. No
90+
interaction with the people involved, including unsolicited interaction with
91+
those enforcing the Code of Conduct, for a specified period of time. This
92+
includes avoiding interactions in community spaces as well as external channels
93+
like social media. Violating these terms may lead to a temporary or permanent
94+
ban.
95+
96+
### 3. Temporary Ban
97+
98+
**Community Impact**: A serious violation of community standards, including
99+
sustained inappropriate behavior.
100+
101+
**Consequence**: A temporary ban from any sort of interaction or public
102+
communication with the community for a specified period of time. No public or
103+
private interaction with the people involved, including unsolicited interaction
104+
with those enforcing the Code of Conduct, is allowed during this period.
105+
Violating these terms may lead to a permanent ban.
106+
107+
### 4. Permanent Ban
108+
109+
**Community Impact**: Demonstrating a pattern of violation of community
110+
standards, including sustained inappropriate behavior, harassment of an
111+
individual, or aggression toward or disparagement of classes of individuals.
112+
113+
**Consequence**: A permanent ban from any sort of public interaction within the
114+
community.
115+
116+
## Attribution
117+
118+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119+
version 2.1, available at
120+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
121+
122+
Community Impact Guidelines were inspired by
123+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
124+
125+
For answers to common questions about this code of conduct, see the FAQ at
126+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
127+
[https://www.contributor-covenant.org/translations][translations].
128+
129+
[homepage]: https://www.contributor-covenant.org
130+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
131+
[Mozilla CoC]: https://github.com/mozilla/diversity
132+
[FAQ]: https://www.contributor-covenant.org/faq
133+
[translations]: https://www.contributor-covenant.org/translations

‎.github/CONTRIBUTING.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Contributing
2+
3+
Contributions to the picozero are welcome. Here is some advice.
4+
5+
1. picozero is 'lightweight', it is designed to be easy to use but also needs to run on a micro controller, please take this into account when considering feature requests or raising issues.
6+
2. see below for other stuff!
7+
8+
# Status
9+
10+
picozero is currently in Beta, pre release 1.0, you should consider the following:
11+
12+
- The API is not yet set, however, this doesn't mean that backwards compatibility is not important! It is a balancing act.
13+
- Requests for new features will need to be prioritised and responses to feature requests may take some time.
14+
- Refactoring of the code base is very likely and as a result pull requests may need rework.
15+
- Issues are likely to exist within the code base, be kind!
16+
17+
# Suggestions
18+
19+
If you have an idea for a new feature or would like to see a device included in picozero, please raise an [issue](https://github.com/RaspberryPiFoundation/picozero/issues). Please explain your reasoning clearly.
20+
21+
# Bugs
22+
23+
Please raise an [issue](https://github.com/RaspberryPiFoundation/picozero/issues) for any bugs found. Please include code examples and circuit diagrams if appropriate.
24+
25+
# Pull requests
26+
27+
All pull requests should be based on the [dev](https://github.com/RaspberryPiFoundation/picozero/tree/dev) branch of picozero.
28+

‎.github/ISSUE_TEMPLATE/bug_report.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behaviour:
15+
1. Setup this device like this '...'
16+
2. Run this code '....'
17+
3. This thing occurred '...'
18+
4. This error was reported '...'
19+
20+
Please include code in code blocks e.g.
21+
22+
```python
23+
print("picozero")
24+
```
25+
26+
**Expected behaviour**
27+
A clear and concise description of what you expected to happen.
28+
29+
**System information:**
30+
- OS: [e.g. Windows]
31+
- Development environment [e.g. Thonny]
32+
- picozero version: [available in `/Lib/picozero/__init__.py`]
33+
34+
**Additional context**
35+
Add any other context about the problem here.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this picozero
4+
title: ''
5+
labels: nice to have
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

‎README.rst

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
picozero
22
========
33

4+
|pypibadge| |docsbadge|
5+
46
A beginner-friendly library for using common electronics components with the Raspberry Pi Pico.
57

68
.. code-block:: python
@@ -19,9 +21,9 @@ A beginner-friendly library for using common electronics components with the Ras
1921
Status
2022
------
2123

22-
Pre-alpha - not yet for general release. Documentation is not yet available. There will be many bugs and issues.
24+
Beta. There will be bugs and issues. API changes are likely.
2325

24-
Full documentation will be available at `picozero.readthedocs.io <https://picozero.readthedocs.io>`_ :
26+
Documentation is available at `picozero.readthedocs.io <https://picozero.readthedocs.io>`_ :
2527

2628
- `Installation and getting started guide <https://picozero.readthedocs.io/en/latest/gettingstarted.html>`_
2729
- `Recipes and how-to's <https://picozero.readthedocs.io/en/latest/recipes.html>`_
@@ -32,3 +34,10 @@ Notes
3234

3335
picozero is inspired by `gpiozero <https://gpiozero.readthedocs.io/en/stable/>`_ (and reuses some of its underlying structure), but is by design lighter weight and aligned with the Raspberry Pi Pico. Thank you to everyone who has contributed to the gpiozero project.
3436

37+
.. |pypibadge| image:: https://badge.fury.io/py/picozero.svg
38+
:target: https://badge.fury.io/py/picozero
39+
:alt: Latest Version
40+
41+
.. |docsbadge| image:: https://readthedocs.org/projects/picozero/badge/
42+
:target: https://readthedocs.org/projects/picozero/
43+
:alt: Docs

‎docs/api.rst

+23
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ Speaker
5656
:inherited-members:
5757
:members:
5858

59+
60+
DigitalOutputDevice
61+
-------------------
62+
.. autoclass:: DigitalOutputDevice
63+
:show-inheritance:
64+
:inherited-members:
65+
:members:
66+
67+
PWMOutputDevice
68+
---------------
69+
.. autoclass:: PWMOutputDevice
70+
:show-inheritance:
71+
:inherited-members:
72+
:members:
73+
5974
Button
6075
------
6176

@@ -87,3 +102,11 @@ TemperatureSensor
87102
:show-inheritance:
88103
:inherited-members:
89104
:members:
105+
106+
DigitalInputDevice
107+
------------------
108+
109+
.. autoclass:: DigitalInputDevice
110+
:show-inheritance:
111+
:inherited-members:
112+
:members:

‎docs/changelog.rst

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ Change log
33

44
.. currentmodule:: picozero
55

6+
0.1.0 - 2022-04-08
7+
~~~~~~~~~~~~~~~~~~
8+
9+
+ Beta release
10+
+ Documentation updates
11+
+ Minor bug fixes and refactoring
12+
613
0.0.2 - 2022-03-31
714
~~~~~~~~~~~~~~~~~~
815

‎docs/conf.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import sys
1515
# sys.path.insert(0, os.path.abspath('.'))
1616
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
17+
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
1718

1819
# Mock out certain modules while building documentation
1920
class Mock:
@@ -45,7 +46,7 @@ def __getattr__(cls, name):
4546
author = 'Raspberry Pi Foundation'
4647

4748
# The full version, including alpha/beta/rc tags
48-
release = '0.0.2'
49+
release = '0.1.0'
4950

5051

5152
# -- General configuration ---------------------------------------------------
@@ -73,7 +74,23 @@ def __getattr__(cls, name):
7374
# The theme to use for HTML and HTML Help pages. See the documentation for
7475
# a list of builtin themes.
7576
#
76-
html_theme = 'alabaster'
77+
# The theme to use for HTML and HTML Help pages. See the documentation for
78+
# a list of builtin themes.
79+
#
80+
if on_rtd:
81+
html_theme = 'sphinx_rtd_theme'
82+
#html_theme_options = {}
83+
html_sidebars = {
84+
'**': [
85+
'globaltoc.html',
86+
'relations.html',
87+
'searchbox.html',
88+
],
89+
}
90+
else:
91+
html_theme = 'alabaster'
92+
#html_theme_options = {}
93+
#html_sidebars = {}
7794

7895
# Add any paths that contain custom static files (such as style sheets) here,
7996
# relative to this directory. They are copied after the builtin static files,

‎docs/contributing.rst

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Contributing
2+
============
3+
4+
Contributions to the picozero are welcome. Here is some advice.
5+
6+
1. picozero is 'lightweight', it is designed to be easy to use but also needs to run on a micro controller, please take this into account when considering feature requests or raising issues.
7+
2. see below for other stuff!
8+
9+
Status
10+
------
11+
12+
picozero is currently in Beta, pre release 1.0, you should consider the following:
13+
14+
- The API is not yet set, however, this doesn't mean that backwards compatibility is not important! It is a balancing act.
15+
- Requests for new features will need to be prioritised and responses to feature requests may take some time.
16+
- Refactoring of the code base is very likely and as a result pull requests may need rework.
17+
- Issues are likely to exist within the code base, be kind!
18+
19+
Suggestions
20+
-----------
21+
22+
If you have an idea for a new feature or would like to see a device included in picozero, please raise an `issue`_. Please explain your reasoning clearly.
23+
24+
Bugs
25+
----
26+
27+
Please raise an `issue`_ for any bugs found. Please include code examples and circuit diagrams if appropriate.
28+
29+
Pull requests
30+
-------------
31+
32+
All pull requests should be based on the `dev <https://github.com/RaspberryPiFoundation/picozero/tree/dev>`_ branch of picozero.
33+
34+
.. _issue: https://github.com/RaspberryPiFoundation/picozero/issues

‎docs/developing.rst

+9-7
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,33 @@ Build
1010

1111
2. Add release to ``docs/changelog.rst``
1212

13-
3. Run `setup.py` and create a source distribution.:
13+
3. Run `setup.py` and create a source distribution ::
1414

1515
python3 setup.py sdist
1616

17-
4. Upload to PyPI:
17+
4. Upload to PyPI ::
1818

1919
twine upload dist/*
2020

21-
5. Push all change to ``master`` branch
21+
5. Push all changes to ``master`` branch
2222

23-
6. Create a release in github and upload picozero-*.tar.gz to the release.
23+
6. Create a `release <https://github.com/RaspberryPiFoundation/picozero/releases>`_ in github and upload ``picozero-#-#-#.tar.gz`` source file to the release.
2424

2525
Documentation
2626
-------------
2727

2828
The documentation site is built using Sphinx.
2929

30-
Install sphinx using :
30+
Install sphinx using ::
3131

3232
pip3 install sphinx
3333

34-
To build the documentation, run the following command from the docs directory:
34+
To build the documentation, run the following command from the docs directory ::
3535

3636
$ make html
3737

3838
The website will be built in the directory docs/_build/html.
3939

40-
Documentation can be viewed at http://picozero.readthedocs.io/
40+
Documentation can be viewed at `picozero.readthedocs.io`_.
41+
42+
.. _picozero.readthedocs.io: https://picozero.readthedocs.io

‎docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ Table of Contents
1111
recipes
1212
api
1313
developing
14+
contributing
1415
changelog

‎picozero/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
__name__ = "picozero"
22
__package__ = "picozero"
3-
__version__ = '0.0.2'
3+
__version__ = '0.1.0'
44
__author__ = "Raspberry Pi Foundation"
55

66
from .picozero import (
77
PWMChannelAlreadyInUse,
8+
EventFailedScheduleQueueFull,
89

910
DigitalOutputDevice,
1011
DigitalLED,

‎picozero/picozero.py

+97-5
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ def blink(self, on_times=1, fade_times=0, colors=((1, 0, 0), (0, 1, 0), (0, 0, 1
990990
:param float on_times:
991991
Single value or tuple of numbers of seconds to stay on each colour. Defaults to 1 second.
992992
:param float fade_times:
993-
Sinlge value or tuple of times to fade between each colour. Must be 0 if
993+
Single value or tuple of times to fade between each colour. Must be 0 if
994994
*pwm* was :data:`False` when the class was constructed.
995995
:type colors: tuple
996996
Tuple of colours to blink between, use ``(0, 0, 0)`` for off.
@@ -1305,6 +1305,25 @@ class Button(Switch):
13051305
Button.when_released = Button.when_deactivated
13061306

13071307
class AnalogInputDevice(InputDevice, PinMixin):
1308+
"""
1309+
Represents a generic input device with analogy functionality e.g.
1310+
a potentiometer
1311+
1312+
:param int pin:
1313+
The pin that the device is connected to.
1314+
1315+
:param active_state:
1316+
The active state of the device. If :data:`True` (the default),
1317+
the :class:`AnalogInputDevice` will assume that the device is
1318+
active when the pin is high and above the threshold . If
1319+
``active_state`` is ``False``, the device will be active when
1320+
the pin is is low and below the threshold.
1321+
1322+
:param float threshold:
1323+
The threshold that the device must be above or below to be
1324+
considered active. The default is 0.5.
1325+
1326+
"""
13081327
def __init__(self, pin, active_state=True, threshold=0.5):
13091328
self._pin_num = pin
13101329
super().__init__(active_state)
@@ -1322,6 +1341,10 @@ def _read(self):
13221341

13231342
@property
13241343
def threshold(self):
1344+
"""
1345+
The threshold that the device must be above or below to be
1346+
considered active. The default is 0.5.
1347+
"""
13251348
return self._threshold
13261349

13271350
@threshold.setter
@@ -1330,17 +1353,38 @@ def threshold(self, value):
13301353

13311354
@property
13321355
def is_active(self):
1356+
"""
1357+
Returns :data:`True` if the device is active.
1358+
"""
13331359
return self.value > self.threshold
13341360

13351361
@property
13361362
def voltage(self):
1363+
"""
1364+
Returns the voltage of the analog device.
1365+
"""
13371366
return self.value * 3.3
1338-
1339-
@property
1340-
def percent(self):
1341-
return int(self.value * 100)
13421367

13431368
class Potentiometer(AnalogInputDevice):
1369+
"""
1370+
Represents a Potentiometer which outputs with a variable voltage
1371+
between 0 and 3.3V.
1372+
1373+
:param int pin:
1374+
The pin that the device is connected to.
1375+
1376+
:param active_state:
1377+
The active state of the device. If :data:`True` (the default),
1378+
the :class:`AnalogInputDevice` will assume that the device is
1379+
active when the pin is high and above the threshold . If
1380+
``active_state`` is ``False``, the device will be active when
1381+
the pin is is low and below the threshold.
1382+
1383+
:param float threshold:
1384+
The threshold that the device must be above or below to be
1385+
considered active. The default is 0.5.
1386+
1387+
"""
13441388
pass
13451389

13461390
Pot = Potentiometer
@@ -1350,16 +1394,64 @@ def pico_temp_conversion(voltage):
13501394
return 27 - (voltage - 0.706)/0.001721
13511395

13521396
class TemperatureSensor(AnalogInputDevice):
1397+
"""
1398+
Represents a TemperatureSensor which outputs a variable voltage. The voltage
1399+
can be converted to a temperature using a `conversion` function passed as a
1400+
parameter.
1401+
1402+
:param int pin:
1403+
The pin that the device is connected to.
1404+
1405+
:param active_state:
1406+
The active state of the device. If :data:`True` (the default),
1407+
the :class:`AnalogInputDevice` will assume that the device is
1408+
active when the pin is high and above the threshold . If
1409+
``active_state`` is ``False``, the device will be active when
1410+
the pin is is low and below the threshold.
1411+
1412+
:param float threshold:
1413+
The threshold that the device must be above or below to be
1414+
considered active. The default is 0.5.
1415+
1416+
:param float conversion:
1417+
A function that takes a voltage and returns a temperature.
1418+
1419+
e.g. The internal temperature sensor has a voltage range of 0.706V to 0.716V
1420+
and would use the follow conversion function::
1421+
1422+
def temp_conversion(voltage):
1423+
return 27 - (voltage - 0.706)/0.001721
1424+
1425+
temp_sensor = TemperatureSensor(pin, conversion=temp_conversion)
1426+
1427+
If :data:`None` (the default), the ``temp`` property will return :data:`None`.
1428+
1429+
"""
13531430
def __init__(self, pin, active_state=True, threshold=0.5, conversion=None):
13541431
self._conversion = conversion
13551432
super().__init__(pin, active_state, threshold)
13561433

13571434
@property
13581435
def temp(self):
1436+
"""
1437+
Returns the temperature of the device. If the conversion function is not
1438+
set, this will return :data:`None`.
1439+
"""
13591440
if self._conversion is not None:
13601441
return self._conversion(self.voltage)
13611442
else:
13621443
return None
1444+
1445+
@property
1446+
def conversion(self):
1447+
"""
1448+
Set or returns the conversion function for the device.
1449+
"""
1450+
return self._conversion
1451+
1452+
@conversion.setter
1453+
def conversion(self, value):
1454+
self._conversion = value
13631455

13641456
pico_temp_sensor = TemperatureSensor(4, True, 0.5, pico_temp_conversion)
13651457
TempSensor = TemperatureSensor

‎setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
__project__ = 'picozero'
44
__packages__ = ['picozero']
5-
__desc__ = 'A beginner-friendly library for using common electronics components with the Raspberry Pi Pico. Not yet for general release.'
6-
__version__ = '0.0.2'
5+
__desc__ = 'A beginner-friendly library for using common electronics components with the Raspberry Pi Pico. '
6+
__version__ = '0.1.0'
77
__author__ = "Raspberry Pi Foundation"
88
__author_email__ = 'learning@raspberrypi.org'
99
__license__ = 'MIT'
@@ -32,7 +32,7 @@
3232
button.when_released = led.off
3333
```
3434
35-
Not yet for general release.
35+
Documentation is available at [picozero.readthedocs.io](https://picozero.readthedocs.io/en/latest/).
3636
"""
3737

3838
setup(

0 commit comments

Comments
 (0)
Please sign in to comment.