Skip to content

Commit 8f647a6

Browse files
author
sam
committed
Added or mocked all other ev3dev2 classes
1 parent 1edfa19 commit 8f647a6

13 files changed

Lines changed: 1843 additions & 0 deletions

File tree

source/Main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
from ev3dev2._platform.ev3 import INPUT_1, INPUT_4, INPUT_3, INPUT_2
4+
from ev3dev2.led import Led
45
from ev3dev2.motor import MoveTank, OUTPUT_A, OUTPUT_D, SpeedPercent
56
from ev3dev2.sensor.lego import ColorSensor
67
from ev3dev2.sensor.lego import TouchSensor
@@ -71,5 +72,7 @@ def check():
7172

7273
tank_drive = MoveTank(OUTPUT_A, OUTPUT_D)
7374

75+
led = Led()
76+
7477
drive()
7578
check()

source/ev3dev2/button.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) 2015 Ralph Hempel <rhempel@hempeldesigngroup.com>
3+
# Copyright (c) 2015 Anton Vanhoucke <antonvh@gmail.com>
4+
# Copyright (c) 2015 Denis Demidov <dennis.demidov@gmail.com>
5+
# Copyright (c) 2015 Eric Pascual <eric@pobot.org>
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
# -----------------------------------------------------------------------------
25+
26+
import sys
27+
28+
if sys.version_info < (3, 4):
29+
raise SystemError('Must be using Python 3.4 or higher')
30+
31+
from logging import getLogger
32+
33+
log = getLogger(__name__)
34+
35+
36+
class MissingButton(Exception):
37+
pass
38+
39+
40+
class ButtonCommon(object):
41+
42+
def __str__(self):
43+
return self.__class__.__name__
44+
45+
46+
@staticmethod
47+
def on_change(changed_buttons):
48+
"""
49+
This handler is called by `process()` whenever state of any button has
50+
changed since last `process()` call. `changed_buttons` is a list of
51+
tuples of changed button names and their states.
52+
"""
53+
54+
pass
55+
56+
57+
@property
58+
def buttons_pressed(self):
59+
raise NotImplementedError()
60+
61+
62+
def any(self):
63+
"""
64+
Checks if any button is pressed.
65+
"""
66+
67+
pass
68+
69+
70+
def check_buttons(self, buttons=[]):
71+
"""
72+
Check if currently pressed buttons exactly match the given list.
73+
"""
74+
75+
pass
76+
77+
78+
def _wait(self, wait_for_button_press, wait_for_button_release, timeout_ms):
79+
raise NotImplementedError()
80+
81+
82+
def wait_for_pressed(self, buttons, timeout_ms=None):
83+
"""
84+
Wait for the button to be pressed down.
85+
"""
86+
87+
pass
88+
89+
90+
def wait_for_released(self, buttons, timeout_ms=None):
91+
"""
92+
Wait for the button to be released.
93+
"""
94+
95+
pass
96+
97+
98+
def wait_for_bump(self, buttons, timeout_ms=None):
99+
"""
100+
Wait for the button to be pressed down and then released.
101+
Both actions must happen within timeout_ms.
102+
"""
103+
104+
pass
105+
106+
107+
def process(self, new_state=None):
108+
"""
109+
Check for currenly pressed buttons. If the new state differs from the
110+
old state, call the appropriate button event handlers (on_up, on_down, etc).
111+
"""
112+
113+
pass
114+
115+
116+
class EV3ButtonCommon(object):
117+
# These handlers are called by `ButtonCommon.process()` whenever the
118+
# state of 'up', 'down', etc buttons have changed since last
119+
# `ButtonCommon.process()` call
120+
on_up = None
121+
on_down = None
122+
on_left = None
123+
on_right = None
124+
on_enter = None
125+
on_backspace = None
126+
127+
128+
@property
129+
def up(self):
130+
"""
131+
Check if 'up' button is pressed.
132+
"""
133+
134+
pass
135+
136+
137+
@property
138+
def down(self):
139+
"""
140+
Check if 'down' button is pressed.
141+
"""
142+
143+
pass
144+
145+
146+
@property
147+
def left(self):
148+
"""
149+
Check if 'left' button is pressed.
150+
"""
151+
152+
pass
153+
154+
155+
@property
156+
def right(self):
157+
"""
158+
Check if 'right' button is pressed.
159+
"""
160+
161+
pass
162+
163+
164+
@property
165+
def enter(self):
166+
"""
167+
Check if 'enter' button is pressed.
168+
"""
169+
170+
pass
171+
172+
173+
@property
174+
def backspace(self):
175+
"""
176+
Check if 'backspace' button is pressed.
177+
"""
178+
179+
pass

source/ev3dev2/console.py

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# -----------------------------------------------------------------------------
2+
# Permission is hereby granted, free of charge, to any person obtaining a copy
3+
# of this software and associated documentation files (the "Software"), to deal
4+
# in the Software without restriction, including without limitation the rights
5+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6+
# copies of the Software, and to permit persons to whom the Software is
7+
# furnished to do so, subject to the following conditions:
8+
#
9+
# The above copyright notice and this permission notice shall be included in
10+
# all copies or substantial portions of the Software.
11+
#
12+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18+
# THE SOFTWARE.
19+
# -----------------------------------------------------------------------------
20+
21+
22+
class Console():
23+
"""
24+
A class that represents the EV3 LCD console, which implements ANSI codes
25+
for cursor positioning, text color, and resetting the screen. Supports changing
26+
the console font using standard system fonts.
27+
"""
28+
29+
30+
def __init__(self, font="Lat15-TerminusBold24x12"):
31+
"""
32+
Construct the Console instance, optionally with a font name specified.
33+
34+
Parameter:
35+
36+
- `font` (string): Font name, as found in `/usr/share/consolefonts/`
37+
38+
"""
39+
self._font = None
40+
self._columns = 0
41+
self._rows = 0
42+
self._echo = False
43+
self._cursor = False
44+
self.set_font(font, reset_console=False) # don't reset the screen during construction
45+
self.cursor = False
46+
self.echo = False
47+
48+
49+
@property
50+
def columns(self):
51+
"""
52+
Return (int) number of columns on the EV3 LCD console supported by the current font.
53+
"""
54+
55+
pass
56+
57+
58+
@property
59+
def rows(self):
60+
"""
61+
Return (int) number of rows on the EV3 LCD console supported by the current font.
62+
"""
63+
64+
pass
65+
66+
67+
@property
68+
def echo(self):
69+
"""
70+
Return (bool) whether the console echo mode is enabled.
71+
"""
72+
73+
pass
74+
75+
76+
@echo.setter
77+
def echo(self, value):
78+
"""
79+
Enable/disable console echo (so that EV3 button presses do not show the escape characters on
80+
the LCD console). Set to True to show the button codes, or False to hide them.
81+
"""
82+
83+
pass
84+
85+
86+
@property
87+
def cursor(self):
88+
"""
89+
Return (bool) whether the console cursor is visible.
90+
"""
91+
92+
pass
93+
94+
95+
@cursor.setter
96+
def cursor(self, value):
97+
"""
98+
Enable/disable console cursor (to hide the cursor on the LCD).
99+
Set to True to show the cursor, or False to hide it.
100+
"""
101+
102+
pass
103+
104+
105+
def text_at(self, text, column=1, row=1, reset_console=False, inverse=False, alignment="L"):
106+
"""
107+
Display `text` (string) at grid position (`column`, `row`).
108+
Note that the grid locations are 1-based (not 0-based).
109+
110+
Depending on the font, the number of columns and rows supported by the EV3 LCD console
111+
can vary. Large fonts support as few as 11 columns and 4 rows, while small fonts support
112+
44 columns and 21 rows. The default font for the Console() class results in a grid that
113+
is 14 columns and 5 rows.
114+
115+
Using the `inverse=True` parameter will display the `text` with more emphasis and contrast,
116+
as the background of the text will be black, and the foreground is white. Using inverse
117+
can help in certain situations, such as to indicate when a color sensor senses
118+
black, or the gyro sensor is pointing to zero.
119+
120+
Use the `alignment` parameter to enable the function to align the `text` differently to the
121+
column/row values passed-in. Use `L` for left-alignment (default), where the first character
122+
in the `text` will show at the column/row position. Use `R` for right-alignment, where the
123+
last character will show at the column/row position. Use `C` for center-alignment, where the
124+
text string will centered at the column/row position (as close as possible using integer
125+
division--odd-length text string will center better than even-length).
126+
127+
Parameters:
128+
129+
- `text` (string): Text to display
130+
- `column` (int): LCD column position to start the text (1 = left column);
131+
text will wrap when it reaches the right edge
132+
- `row` (int): LCD row position to start the text (1 = top row)
133+
- `reset_console` (bool): ``True`` to reset the EV3 LCD console before showing
134+
the text; default is ``False``
135+
- `inverse` (bool): ``True`` for white on black, otherwise black on white;
136+
default is ``False``
137+
- `alignment` (string): Align the `text` horizontally. Use `L` for left-alignment (default),
138+
`R` for right-alignment, or `C` for center-alignment
139+
140+
"""
141+
142+
pass
143+
144+
145+
def set_font(self, font="Lat15-TerminusBold24x12", reset_console=True):
146+
"""
147+
Set the EV3 LCD console font and optionally reset the EV3 LCD console
148+
to clear it and turn off the cursor.
149+
150+
Parameters:
151+
152+
- `font` (string): Font name, as found in `/usr/share/consolefonts/`
153+
- `reset_console` (bool): ``True`` to reset the EV3 LCD console
154+
after the font change; default is ``True``
155+
156+
"""
157+
158+
pass
159+
160+
161+
def clear_to_eol(self, column=None, row=None):
162+
"""
163+
Clear to the end of line from the `column` and `row` position
164+
on the EV3 LCD console. Default to current cursor position.
165+
166+
Parameters:
167+
168+
- `column` (int): LCD column position to move to before clearing
169+
- `row` (int): LCD row position to move to before clearing
170+
171+
"""
172+
173+
pass
174+
175+
176+
def reset_console(self):
177+
"""
178+
Clear the EV3 LCD console using ANSI codes, and move the cursor to 1,1
179+
"""
180+
181+
pass

0 commit comments

Comments
 (0)