Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ python-ev3dev2 (2.1.0) UNRELEASED; urgency=medium

[Daniel Walton]
* RPyC update docs and make it easier to use
* use double backticks consistently in docstrings

[Matěj Volf]
* LED animation fix duration None
Expand Down
32 changes: 16 additions & 16 deletions ev3dev2/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def __str__(self):
@staticmethod
def on_change(changed_buttons):
"""
This handler is called by `process()` whenever state of any button has
changed since last `process()` call. `changed_buttons` is a list of
This handler is called by ``process()`` whenever state of any button has
changed since last ``process()`` call. ``changed_buttons`` is a list of
tuples of changed button names and their states.
"""
pass
Expand All @@ -89,7 +89,7 @@ def any(self):

def check_buttons(self, buttons=[]):
"""
Check if currently pressed buttons exactly match the given list.
Check if currently pressed buttons exactly match the given list ``buttons``.
"""
return set(self.buttons_pressed) == set(buttons)

Expand All @@ -98,20 +98,20 @@ def _wait(self, wait_for_button_press, wait_for_button_release, timeout_ms):

def wait_for_pressed(self, buttons, timeout_ms=None):
"""
Wait for the button to be pressed down.
Wait for ``buttons`` to be pressed down.
"""
return self._wait(buttons, [], timeout_ms)

def wait_for_released(self, buttons, timeout_ms=None):
"""
Wait for the button to be released.
Wait for ``buttons`` to be released.
"""
return self._wait([], buttons, timeout_ms)

def wait_for_bump(self, buttons, timeout_ms=None):
"""
Wait for the button to be pressed down and then released.
Both actions must happen within timeout_ms.
Wait for ``buttons`` to be pressed down and then released.
Both actions must happen within ``timeout_ms``.
"""
stopwatch = StopWatch()
stopwatch.start()
Expand All @@ -125,7 +125,7 @@ def wait_for_bump(self, buttons, timeout_ms=None):

def process(self, new_state=None):
"""
Check for currenly pressed buttons. If the new state differs from the
Check for currenly pressed buttons. If the ``new_state`` differs from the
old state, call the appropriate button event handlers (on_up, on_down, etc).
"""
if new_state is None:
Expand All @@ -146,9 +146,9 @@ def process(self, new_state=None):

class EV3ButtonCommon(object):

# These handlers are called by `ButtonCommon.process()` whenever the
# These handlers are called by ButtonCommon.process() whenever the
# state of 'up', 'down', etc buttons have changed since last
# `ButtonCommon.process()` call
# ButtonCommon.process() call
on_up = None
on_down = None
on_left = None
Expand All @@ -159,42 +159,42 @@ class EV3ButtonCommon(object):
@property
def up(self):
"""
Check if 'up' button is pressed.
Check if ``up`` button is pressed.
"""
return 'up' in self.buttons_pressed

@property
def down(self):
"""
Check if 'down' button is pressed.
Check if ``down`` button is pressed.
"""
return 'down' in self.buttons_pressed

@property
def left(self):
"""
Check if 'left' button is pressed.
Check if ``left`` button is pressed.
"""
return 'left' in self.buttons_pressed

@property
def right(self):
"""
Check if 'right' button is pressed.
Check if ``right`` button is pressed.
"""
return 'right' in self.buttons_pressed

@property
def enter(self):
"""
Check if 'enter' button is pressed.
Check if ``enter`` button is pressed.
"""
return 'enter' in self.buttons_pressed

@property
def backspace(self):
"""
Check if 'backspace' button is pressed.
Check if ``backspace`` button is pressed.
"""
return 'backspace' in self.buttons_pressed

Expand Down
38 changes: 19 additions & 19 deletions ev3dev2/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, font="Lat15-TerminusBold24x12"):

Parameter:

- `font` (string): Font name, as found in `/usr/share/consolefonts/`
- ``font`` (string): Font name, as found in ``/usr/share/consolefonts/``

"""
self._font = None
Expand Down Expand Up @@ -94,38 +94,38 @@ def cursor(self, value):

def text_at(self, text, column=1, row=1, reset_console=False, inverse=False, alignment="L"):
"""
Display `text` (string) at grid position (`column`, `row`).
Display ``text`` (string) at grid position (``column``, ``row``).
Note that the grid locations are 1-based (not 0-based).

Depending on the font, the number of columns and rows supported by the EV3 LCD console
can vary. Large fonts support as few as 11 columns and 4 rows, while small fonts support
44 columns and 21 rows. The default font for the Console() class results in a grid that
is 14 columns and 5 rows.

Using the `inverse=True` parameter will display the `text` with more emphasis and contrast,
Using the ``inverse=True`` parameter will display the ``text`` with more emphasis and contrast,
as the background of the text will be black, and the foreground is white. Using inverse
can help in certain situations, such as to indicate when a color sensor senses
black, or the gyro sensor is pointing to zero.

Use the `alignment` parameter to enable the function to align the `text` differently to the
column/row values passed-in. Use `L` for left-alignment (default), where the first character
in the `text` will show at the column/row position. Use `R` for right-alignment, where the
last character will show at the column/row position. Use `C` for center-alignment, where the
Use the ``alignment`` parameter to enable the function to align the ``text`` differently to the
column/row values passed-in. Use ``L`` for left-alignment (default), where the first character
in the ``text`` will show at the column/row position. Use ``R`` for right-alignment, where the
last character will show at the column/row position. Use ``C`` for center-alignment, where the
text string will centered at the column/row position (as close as possible using integer
division--odd-length text string will center better than even-length).

Parameters:

- `text` (string): Text to display
- `column` (int): LCD column position to start the text (1 = left column);
- ``text`` (string): Text to display
- ``column`` (int): LCD column position to start the text (1 = left column);
text will wrap when it reaches the right edge
- `row` (int): LCD row position to start the text (1 = top row)
- `reset_console` (bool): ``True`` to reset the EV3 LCD console before showing
- ``row`` (int): LCD row position to start the text (1 = top row)
- ``reset_console`` (bool): ``True`` to reset the EV3 LCD console before showing
the text; default is ``False``
- `inverse` (bool): ``True`` for white on black, otherwise black on white;
- ``inverse`` (bool): ``True`` for white on black, otherwise black on white;
default is ``False``
- `alignment` (string): Align the `text` horizontally. Use `L` for left-alignment (default),
`R` for right-alignment, or `C` for center-alignment
- ``alignment`` (string): Align the ``text`` horizontally. Use ``L`` for left-alignment (default),
``R`` for right-alignment, or ``C`` for center-alignment

"""

Expand All @@ -149,8 +149,8 @@ def set_font(self, font="Lat15-TerminusBold24x12", reset_console=True):

Parameters:

- `font` (string): Font name, as found in `/usr/share/consolefonts/`
- `reset_console` (bool): ``True`` to reset the EV3 LCD console
- ``font`` (string): Font name, as found in ``/usr/share/consolefonts/``
- ``reset_console`` (bool): ``True`` to reset the EV3 LCD console
after the font change; default is ``True``

"""
Expand All @@ -166,13 +166,13 @@ def set_font(self, font="Lat15-TerminusBold24x12", reset_console=True):

def clear_to_eol(self, column=None, row=None):
"""
Clear to the end of line from the `column` and `row` position
Clear to the end of line from the ``column`` and ``row`` position
on the EV3 LCD console. Default to current cursor position.

Parameters:

- `column` (int): LCD column position to move to before clearing
- `row` (int): LCD row position to move to before clearing
- ``column`` (int): LCD column position to move to before clearing
- ``row`` (int): LCD row position to move to before clearing

"""
if column is not None and row is not None:
Expand Down
17 changes: 8 additions & 9 deletions ev3dev2/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ def __init__(self, fbdev=None):
def _open_fbdev(fbdev=None):
"""Return the framebuffer file descriptor.

Try to use the FRAMEBUFFER
environment variable if fbdev is not given. Use '/dev/fb0' by
default.
Try to use the FRAMEBUFFER environment variable if fbdev is
not given. Use '/dev/fb0' by default.
"""
dev = fbdev or os.getenv('FRAMEBUFFER', '/dev/fb0')
fbfid = os.open(dev, os.O_RDWR)
Expand Down Expand Up @@ -370,19 +369,19 @@ def point(self, clear_screen=True, x=10, y=10, point_color='black'):

def text_pixels(self, text, clear_screen=True, x=0, y=0, text_color='black', font=None):
"""
Display `text` starting at pixel (x, y).
Display ``text`` starting at pixel (x, y).

The EV3 display is 178x128 pixels

- (0, 0) would be the top left corner of the display
- (89, 64) would be right in the middle of the display

'text_color' : PIL says it supports "common HTML color names". There
``text_color`` : PIL says it supports "common HTML color names". There
are 140 HTML color names listed here that are supported by all modern
browsers. This is probably a good list to start with.
https://www.w3schools.com/colors/colors_names.asp

'font' : can be any font displayed here
``font`` : can be any font displayed here
http://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/ev3dev-stretch/display.html#bitmap-fonts

- If font is a string, it is the name of a font to be loaded.
Expand All @@ -404,18 +403,18 @@ def text_pixels(self, text, clear_screen=True, x=0, y=0, text_color='black', fon

def text_grid(self, text, clear_screen=True, x=0, y=0, text_color='black', font=None):
"""
Display 'text' starting at grid (x, y)
Display ``text`` starting at grid (x, y)

The EV3 display can be broken down in a grid that is 22 columns wide
and 12 rows tall. Each column is 8 pixels wide and each row is 10
pixels tall.

'text_color' : PIL says it supports "common HTML color names". There
``text_color`` : PIL says it supports "common HTML color names". There
are 140 HTML color names listed here that are supported by all modern
browsers. This is probably a good list to start with.
https://www.w3schools.com/colors/colors_names.asp

'font' : can be any font displayed here
``font`` : can be any font displayed here
http://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/ev3dev-stretch/display.html#bitmap-fonts

- If font is a string, it is the name of a font to be loaded.
Expand Down
38 changes: 20 additions & 18 deletions ev3dev2/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def max_brightness(self):
@property
def brightness(self):
"""
Sets the brightness level. Possible values are from 0 to `max_brightness`.
Sets the brightness level. Possible values are from 0 to ``max_brightness``.
"""
self._brightness, value = self.get_attr_int(self._brightness, 'brightness')
return value
Expand All @@ -133,17 +133,17 @@ def trigger(self):
Sets the LED trigger. A trigger is a kernel based source of LED events.
Triggers can either be simple or complex. A simple trigger isn't
configurable and is designed to slot into existing subsystems with
minimal additional code. Examples are the `ide-disk` and `nand-disk`
minimal additional code. Examples are the ``ide-disk`` and ``nand-disk``
triggers.

Complex triggers whilst available to all LEDs have LED specific
parameters and work on a per LED basis. The `timer` trigger is an example.
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `on` and `off` time can
be specified via `delay_{on,off}` attributes in milliseconds.
parameters and work on a per LED basis. The ``timer`` trigger is an example.
The ``timer`` trigger will periodically change the LED brightness between
0 and the current brightness setting. The ``on`` and ``off`` time can
be specified via ``delay_{on,off}`` attributes in milliseconds.
You can change the brightness value of a LED independently of the timer
trigger. However, if you set the brightness value to 0 it will
also disable the `timer` trigger.
also disable the ``timer`` trigger.
"""
self._trigger, value = self.get_attr_from_set(self._trigger, 'trigger')
return value
Expand Down Expand Up @@ -179,9 +179,9 @@ def trigger(self, value):
@property
def delay_on(self):
"""
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `on` time can
be specified via `delay_on` attribute in milliseconds.
The ``timer`` trigger will periodically change the LED brightness between
0 and the current brightness setting. The ``on`` time can
be specified via ``delay_on`` attribute in milliseconds.
"""

# Workaround for ev3dev/ev3dev#225.
Expand Down Expand Up @@ -219,9 +219,9 @@ def delay_on(self, value):
@property
def delay_off(self):
"""
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `off` time can
be specified via `delay_off` attribute in milliseconds.
The ``timer`` trigger will periodically change the LED brightness between
0 and the current brightness setting. The ``off`` time can
be specified via ``delay_off`` attribute in milliseconds.
"""

# Workaround for ev3dev/ev3dev#225.
Expand All @@ -241,11 +241,13 @@ def delay_off(self):

@delay_off.setter
def delay_off(self, value):
# Workaround for ev3dev/ev3dev#225.
# 'delay_on' and 'delay_off' attributes are created when trigger is set
# to 'timer', and destroyed when it is set to anything else.
# This means the file cache may become outdated, and we may have to
# reopen the file.
"""
Workaround for ev3dev/ev3dev#225.
``delay_on`` and ``delay_off`` attributes are created when trigger is set
to ``timer``, and destroyed when it is set to anything else.
This means the file cache may become outdated, and we may have to
reopen the file.
"""
for retry in (True, False):
try:
self._delay_off = self.set_attr_int(self._delay_off, 'delay_off', value)
Expand Down
Loading