Skip to content

Commit 255cf5d

Browse files
authored
Sync README, docs and code behavior (#490)
* Sync README, docs and code behavior Minor improvement to LED parameter options. * Make beep and tone behave the same as other sound methods * Add nitpick ignore for "list"
1 parent caa01ad commit 255cf5d

File tree

5 files changed

+191
-103
lines changed

5 files changed

+191
-103
lines changed

README.rst

+28-16
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ Getting Started
2222

2323
This library runs on ev3dev_. Before continuing, make sure that you have set up
2424
your EV3 or other ev3dev device as explained in the `ev3dev Getting Started guide`_.
25-
Make sure that you have a kernel version that includes ``-10-ev3dev`` or higher (a
26-
larger number). You can check the kernel version by selecting "About" in Brickman
27-
and scrolling down to the "kernel version". If you don't have a compatible version,
28-
`upgrade the kernel before continuing`_.
25+
Make sure you have an ev3dev-stretch version greater than ``2.2.0``. You can check
26+
the kernel version by selecting "About" in Brickman and scrolling down to the
27+
"kernel version". If you don't have a compatible version, `upgrade the kernel before continuing`_.
2928

3029
Usage
3130
-----
@@ -41,15 +40,16 @@ your own solution. If you don't know how to do that, you are probably better off
4140
choosing the recommended option above.
4241

4342
The template for a Python script
44-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4544

4645
Every Python program should have a few basic parts. Use this template
4746
to get started:
4847

4948
.. code-block:: python
5049
5150
#!/usr/bin/env python3
52-
from ev3dev2.motor import LargeMotor, OUTPUT_A, SpeedPercent
51+
from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, SpeedPercent, MoveTank
52+
from ev3dev2.sensor import INPUT_1
5353
from ev3dev2.sensor.lego import TouchSensor
5454
from ev3dev2.led import Leds
5555
@@ -64,6 +64,10 @@ or additional utilities.
6464

6565
You should use the ``.py`` extension for your file, e.g. ``my-file.py``.
6666

67+
If you encounter an error such as ``/usr/bin/env: 'python3\r': No such file or directory``,
68+
you must switch your editor's "line endings" setting for the file from "CRLF" to just "LF".
69+
This is usually in the status bar at the bottom. For help, see `our FAQ page`_.
70+
6771
Important: Make your script executable (non-Visual Studio Code only)
6872
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6973

@@ -80,7 +84,7 @@ from the command line by preceding the file name with ``./``: ``./my-file.py``
8084
Controlling the LEDs with a touch sensor
8185
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8286

83-
This code will turn the left LED red whenever the touch sensor is pressed, and
87+
This code will turn the LEDs red whenever the touch sensor is pressed, and
8488
back to green when it's released. Plug a touch sensor into any sensor port before
8589
trying this out.
8690

@@ -89,11 +93,21 @@ trying this out.
8993
ts = TouchSensor()
9094
leds = Leds()
9195
96+
print("Press the touch sensor to change the LED color!")
97+
9298
while True:
9399
if ts.is_pressed:
94-
leds.set_color(leds.led_groups.LEFT, leds.led_colors.GREEN)
100+
leds.set_color("LEFT", "GREEN")
101+
leds.set_color("RIGHT", "GREEN")
95102
else:
96-
leds.set_color(leds.led_groups.LEFT, leds.led_colors.RED)
103+
leds.set_color("LEFT", "RED")
104+
leds.set_color("RIGHT", "RED")
105+
106+
If you'd like to use a sensor on a specific port, specify the port like this:
107+
108+
.. code-block:: python
109+
110+
ts = TouchSensor(INPUT_1)
97111
98112
Running a single motor
99113
~~~~~~~~~~~~~~~~~~~~~~
@@ -144,7 +158,7 @@ If you want to make your robot speak, you can use the ``Sound.speak`` method:
144158
from ev3dev2.sound import Sound
145159
146160
sound = Sound()
147-
sound.speak('Welcome to the E V 3 dev project!').wait()
161+
sound.speak('Welcome to the E V 3 dev project!')
148162
149163
Make sure to check out the `User Resources`_ section for more detailed
150164
information on these features and many others.
@@ -192,7 +206,7 @@ to type the password (the default is ``maker``) when prompted.
192206
.. code-block:: bash
193207
194208
sudo apt-get update
195-
sudo apt-get install --only-upgrade python3-ev3dev
209+
sudo apt-get install --only-upgrade python3-ev3dev2
196210
197211
198212
Developer Resources
@@ -209,9 +223,6 @@ Python 2.x and Python 3.x Compatibility
209223
Some versions of the ev3dev_ distribution come with both `Python 2.x`_ and `Python 3.x`_ installed
210224
but this library is compatible only with Python 3.
211225

212-
As of the 2016-10-17 ev3dev image, the version of this library which is included runs on
213-
Python 3 and this is the only version that will be supported from here forward.
214-
215226
.. _ev3dev: http://ev3dev.org
216227
.. _ev3dev.org: ev3dev_
217228
.. _Getting Started: ev3dev-getting-started_
@@ -221,9 +232,10 @@ Python 3 and this is the only version that will be supported from here forward.
221232
.. _detailed instructions for USB connections: ev3dev-usb-internet_
222233
.. _via an SSH connection: http://www.ev3dev.org/docs/tutorials/connecting-to-ev3dev-with-ssh/
223234
.. _ev3dev-usb-internet: http://www.ev3dev.org/docs/tutorials/connecting-to-the-internet-via-usb/
224-
.. _our Read the Docs page: http://python-ev3dev.readthedocs.org/en/stable/
235+
.. _our Read the Docs page: http://python-ev3dev.readthedocs.org/en/ev3dev-stretch/
225236
.. _ev3python.com: http://ev3python.com/
226-
.. _FAQ: http://python-ev3dev.readthedocs.io/en/stable/faq.html
237+
.. _FAQ: http://python-ev3dev.readthedocs.io/en/ev3dev-stretch/faq.html
238+
.. _our FAQ page: FAQ_
227239
.. _ev3dev-lang-python: https://github.com/rhempel/ev3dev-lang-python
228240
.. _our Issues tracker: https://github.com/rhempel/ev3dev-lang-python/issues
229241
.. _EXPLOR3R: demo-robot_

docs/conf.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,14 @@
317317

318318
nitpick_ignore = [
319319
('py:class', 'ev3dev2.display.FbMem'),
320-
('py:class', 'ev3dev2.button.ButtonBase')
320+
('py:class', 'ev3dev2.button.ButtonBase'),
321+
('py:class', 'int'),
322+
('py:class', 'float'),
323+
('py:class', 'string'),
324+
('py:class', 'iterable'),
325+
('py:class', 'tuple'),
326+
('py:class', 'list'),
327+
('py:exc', 'ValueError')
321328
]
322329

323330
def setup(app):

docs/other.rst

+55-17
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,69 @@ Leds
3030
.. autoclass:: ev3dev2.led.Leds
3131
:members:
3232

33-
.. rubric:: EV3 platform
33+
LED group and color names
34+
~~~~~~~~~~~~~~~~~~~~~~~~~
3435

35-
Led groups:
36+
.. rubric:: EV3 platform
3637

37-
.. py:data:: LEFT
38-
.. py:data:: RIGHT
38+
Led groups:
3939

40-
Colors:
40+
- ``LEFT``
41+
- ``RIGHT``
4142

42-
.. py:data:: RED
43-
.. py:data:: GREEN
44-
.. py:data:: AMBER
45-
.. py:data:: ORANGE
46-
.. py:data:: YELLOW
43+
Colors:
4744

48-
.. rubric:: BrickPI platform
45+
- ``BLACK``
46+
- ``RED``
47+
- ``GREEN``
48+
- ``AMBER``
49+
- ``ORANGE``
50+
- ``YELLOW``
4951

50-
Led groups:
52+
.. rubric:: BrickPI platform
5153

52-
.. py:data:: LED1
53-
.. py:data:: LED2
54+
Led groups:
5455

55-
Colors:
56+
- ``LED1``
57+
- ``LED2``
5658

57-
.. py:data:: BLUE
59+
Colors:
60+
61+
- ``BLACK``
62+
- ``BLUE``
63+
64+
.. rubric:: BrickPI3 platform
65+
66+
Led groups:
67+
68+
- ``LED``
69+
70+
Colors:
71+
72+
- ``BLACK``
73+
- ``BLUE``
74+
75+
.. rubric:: PiStorms platform
76+
77+
Led groups:
78+
79+
- ``LEFT``
80+
- ``RIGHT``
81+
82+
Colors:
83+
84+
- ``BLACK``
85+
- ``RED``
86+
- ``GREEN``
87+
- ``BLUE``
88+
- ``YELLOW``
89+
- ``CYAN``
90+
- ``MAGENTA``
91+
92+
.. rubric:: EVB platform
93+
94+
None.
95+
5896

5997
Power Supply
6098
------------
@@ -76,7 +114,7 @@ Display
76114
:show-inheritance:
77115

78116
Bitmap fonts
79-
^^^^^^^^^^^^
117+
~~~~~~~~~~~~
80118

81119
The :py:class:`ev3dev2.display.Display` class allows to write text on the LCD using python
82120
imaging library (PIL) interface (see description of the ``text()`` method

ev3dev2/led.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -292,24 +292,35 @@ def set_color(self, group, color, pct=1):
292292
reduced proportionally.
293293
294294
Example::
295+
295296
my_leds = Leds()
296297
my_leds.set_color('LEFT', 'AMBER')
298+
299+
With a custom color::
300+
301+
my_leds = Leds()
302+
my_leds.set_color('LEFT', (0.5, 0.3))
297303
"""
298304
# If this is a platform without LEDs there is nothing to do
299305
if not self.leds:
300306
return
301307

308+
color_tuple = color
309+
if isinstance(color, str):
310+
assert color in self.led_colors, "%s is an invalid LED color, valid choices are %s" % (color, ','.join(self.led_colors.keys()))
311+
color_tuple = self.led_colors[color]
312+
302313
assert group in self.led_groups, "%s is an invalid LED group, valid choices are %s" % (group, ','.join(self.led_groups.keys()))
303-
assert color in self.led_colors, "%s is an invalid LED color, valid choices are %s" % (color, ','.join(self.led_colors.keys()))
304314

305-
for led, value in zip(self.led_groups[group], self.led_colors[color]):
315+
for led, value in zip(self.led_groups[group], color_tuple):
306316
led.brightness_pct = value * pct
307317

308318
def set(self, group, **kwargs):
309319
"""
310320
Set attributes for each led in group.
311321
312322
Example::
323+
313324
my_leds = Leds()
314325
my_leds.set_color('LEFT', brightness_pct=0.5, trigger='timer')
315326
"""

0 commit comments

Comments
 (0)