Skip to content

Commit 8accf9a

Browse files
committed
doc: add battery
Fixes #114 - reorganize common classes in fake API such as Display, Speaker and Battery. - This does not change the user API
1 parent 20f5ff4 commit 8accf9a

File tree

6 files changed

+181
-129
lines changed

6 files changed

+181
-129
lines changed

doc/source/ev3brick.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ Display
5050
.. automethod:: ev3brick.display.text
5151

5252
.. automethod:: ev3brick.display.image
53+
54+
Battery
55+
-------
56+
57+
.. automethod:: ev3brick.battery.voltage
58+
59+
.. automethod:: ev3brick.battery.current

doc/source/signaltypes.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,19 @@ frequency: Hz
111111
Sound frequencies are expressed in Hertz (Hz).
112112

113113
For example, you can choose the frequency of a :meth:`beep <.ev3brick.sound.beep>` to change the pitch.
114+
115+
.. _voltage:
116+
117+
voltage: mV
118+
--------------
119+
Voltages are expressed in millivolt (mV).
120+
121+
For example, you can check the voltage of the :meth:`battery <.ev3brick.battery.voltage>`.
122+
123+
.. _current:
124+
125+
current: mA
126+
--------------
127+
Electrical currents are expressed in milliampere (mA).
128+
129+
For example, you can check the current supplied by the :meth:`battery <.ev3brick.battery.current>`.
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
"""Generic cross-platform module for typical hub devices like displays, speakers, and batteries."""
2+
3+
from parameters import Align
4+
5+
6+
class Display():
7+
"""Show images or text on a display."""
8+
9+
def __init__(self, device_type):
10+
"""Device-specific display initialization."""
11+
pass
12+
13+
def clear(self):
14+
"""Clear everything on the display."""
15+
pass
16+
17+
def text(self, text, coordinate=None):
18+
"""Display text.
19+
20+
Parameters:
21+
text (str): The text to display.
22+
coordinate (tuple): ``(x, y)`` coordinate tuple. It is the top-left corner of the first character. If no coordinate is specified, it is printed on the next line.
23+
24+
Example::
25+
26+
# Clear the display
27+
brick.display.clear()
28+
29+
# Print ``Hello`` near the middle of the screen
30+
brick.display.text("Hello", (60, 50))
31+
32+
# Print ``World`` directly underneath it
33+
brick.display.text("World")
34+
35+
"""
36+
pass
37+
38+
def image(self, file_name, alignment=Align.CENTER, coordinate=None, clear=True):
39+
"""image(file_name, alignment=Align.CENTER, coordinate=None, clear=True)
40+
41+
Show an image file.
42+
43+
You can specify its placement either using ``alignment`` or by specifying a ``coordinate``, but not both.
44+
45+
Arguments:
46+
file_name (str): Path to the image file. Paths may be absolute or relative from the project folder.
47+
alignment (Align): Where to place the image (*Default*: Align.CENTER).
48+
coordinate (tuple): ``(x, y)`` coordinate tuple. It is the top-left corner of the image (*Default*: None).
49+
clear (bool): Whether to clear the screen before showing the image (*Default*: ``True``).
50+
51+
Example::
52+
53+
# Show a built-in image of two eyes looking upward
54+
brick.display.image(ImageFile.UP)
55+
56+
# Display a custom image from your project folder
57+
brick.display.image('pybricks.png')
58+
59+
# Display a custom image at the top right of the screen, without clearing
60+
# the screen first
61+
brick.display.image('arrow.png', Align.TOP_RIGHT, clear=False)
62+
"""
63+
pass
64+
65+
66+
class Speaker():
67+
"""Play beeps and sound files using a speaker."""
68+
69+
def __init__(self, device_type):
70+
"""Device specific speaker initialization."""
71+
pass
72+
73+
def beep(self, frequency=500, duration=100, volume=30):
74+
"""Play a beep/tone.
75+
76+
Arguments:
77+
frequency (:ref:`frequency`): Frequency of the beep (*Default*: 500).
78+
duration (:ref:`time`): Duration of the beep (*Default*: 100).
79+
volume (:ref:`percentage`): Volume of the beep (*Default*: 30).
80+
81+
Example::
82+
83+
# A simple beep
84+
brick.sound.beep()
85+
86+
# A high pitch (1500 Hz) for one second (1000 ms) at 50% volume
87+
brick.sound.beep(1500, 1000, 50)
88+
"""
89+
pass
90+
91+
def beeps(self, number):
92+
"""Play a number of default beeps with a brief pause in between.
93+
94+
Arguments:
95+
number (int): Number of beeps.
96+
97+
Example::
98+
99+
# Make 5 simple beeps
100+
brick.sound.beeps(5)
101+
"""
102+
pass
103+
104+
def file(self, file_name, volume=100):
105+
"""Play a sound file.
106+
107+
Arguments:
108+
file_name (str): Path to the sound file, including extension.
109+
volume (:ref:`percentage`): Volume of the sound (*Default*: 100).
110+
111+
Example::
112+
113+
# Play one of the built-in sounds
114+
brick.sound.file(SoundFile.HELLO)
115+
116+
# Play a sound file from your project folder
117+
brick.sound.file('mysound.wav')
118+
119+
"""
120+
121+
pass
122+
123+
124+
class Battery():
125+
"""Get the status of a battery."""
126+
127+
def __init__(self, device_type):
128+
"""Battery-specific initialization."""
129+
pass
130+
131+
def voltage(self):
132+
"""Get the voltage of the battery.
133+
134+
Returns:
135+
:ref:`voltage`: Battery voltage.
136+
137+
Examples::
138+
139+
# Play a warning sound when the battery voltage
140+
# is below 7 Volt (7000 mV = 7V)
141+
if brick.battery.voltage() < 7000:
142+
brick.sound.beep()
143+
144+
"""
145+
pass
146+
147+
def current(self):
148+
"""Get the current supplied by the battery.
149+
150+
Returns:
151+
:ref:`current`: Battery current.
152+
153+
"""
154+
pass

lib/fake-pybricks/pybricks/_display.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

lib/fake-pybricks/pybricks/_speaker.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

lib/fake-pybricks/pybricks/ev3brick.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""LEGO® MINDSTORMS® EV3 Brick."""
22

33
from parameters import Color
4-
from _speaker import Speaker
5-
from _display import Display
4+
from _common import Speaker, Display, Battery
5+
66

77
def buttons():
88
"""Check which buttons on the EV3 Brick are currently pressed.
@@ -47,5 +47,7 @@ def light(color):
4747
"""
4848
pass
4949

50+
5051
sound = Speaker('EV3')
5152
display = Display('EV3')
53+
battery = Battery('EV3')

0 commit comments

Comments
 (0)