Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 9fba43a

Browse files
Merge branch 'dev' into users/t-xunguy/currently-running
2 parents 9ab039c + f957777 commit 9fba43a

37 files changed

+2907
-2049
lines changed

gulpfile.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ gulp.task("clean", () => {
3535

3636
const pythonToMove = [
3737
"./src/adafruit_circuitplayground/*.*",
38-
"./src/microbit/*.*",
39-
"./src/microbit/!(test)/**/*",
38+
"./src/micropython/*.*",
39+
"./src/micropython/microbit/*.*",
40+
"./src/micropython/microbit/!(test)/**/*",
4041
"./src/*.py",
4142
"./src/common/*.py",
4243
"./src/dev-requirements.txt",

package-lock.json

Lines changed: 36 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adafruit_circuitplayground/express.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def tapped(self):
8686
""" Not Implemented!
8787
"""
8888
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_TAPPED)
89-
raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR)
89+
utils.print_for_unimplemented_functions("tapped")
9090

9191
@property
9292
def red_led(self):
@@ -154,12 +154,12 @@ def touch_A6(self):
154154
def touch_A7(self):
155155
return self.__touch(7)
156156

157-
def adjust_touch_threshold(self, adjustement):
157+
def adjust_touch_threshold(self, adjustment):
158158
"""Not implemented!
159159
The CPX Simulator doesn't use capacitive touch threshold.
160160
"""
161161
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_ADJUST_THRESHOLD)
162-
raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR)
162+
utils.print_for_unimplemented_functions(Express.adjust_touch_threshold.__name__)
163163

164164
def shake(self, shake_threshold=30):
165165
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_SHAKE)
@@ -192,19 +192,19 @@ def play_tone(self, frequency, duration):
192192
""" Not Implemented!
193193
"""
194194
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_PLAY_TONE)
195-
raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR)
195+
utils.print_for_unimplemented_functions(Express.play_tone.__name__)
196196

197197
def start_tone(self, frequency):
198198
""" Not Implemented!
199199
"""
200200
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_START_TONE)
201-
raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR)
201+
utils.print_for_unimplemented_functions(Express.start_tone.__name__)
202202

203203
def stop_tone(self):
204204
""" Not Implemented!
205205
"""
206206
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_STOP_TONE)
207-
raise NotImplementedError(CONSTANTS.NOT_IMPLEMENTED_ERROR)
207+
utils.print_for_unimplemented_functions(Express.stop_tone.__name__)
208208

209209
def update_state(self, new_state):
210210
for event in CONSTANTS.ALL_EXPECTED_INPUT_EVENTS:

src/common/debugger_communication_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from adafruit_circuitplayground.express import cpx
1515
from adafruit_circuitplayground.constants import CPX
1616

17-
from microbit.__model.microbit_model import __mb as mb
18-
from microbit.__model.constants import MICROBIT
17+
from micropython.microbit.__model.microbit_model import __mb as mb
18+
from micropython.microbit.__model.constants import MICROBIT
1919

2020

2121
device_dict = {CPX: cpx, MICROBIT: mb}

src/common/telemetry_events.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ class TelemetryEvent(enum.Enum):
3131
MICROBIT_API_IMAGE_OTHER = "MICROBIT.API.IMAGE.OTHER"
3232
MICROBIT_API_IMAGE_STATIC = "MICROBIT.API.IMAGE.STATIC"
3333
MICROBIT_API_BUTTON = "MICROBIT.API.BUTTON"
34+
MICROBIT_API_COMPASS = "MICROBIT.API.COMPASS"
35+
MICROBIT_API_I2C = "MICROBIT.API.I2C"
36+
MICROBIT_API_SPI = "MICROBIT.API.SPI"
37+
MICROBIT_API_AUDIO = "MICROBIT.API.AUDIO"
38+
MICROBIT_API_MUSIC = "MICROBIT.API.MUSIC"
39+
MICROBIT_API_NEOPIXEL = "MICROBIT.API.NEOPIXEL"
40+
MICROBIT_API_RADIO = "MICROBIT.API.RADIO"
41+
MICROBIT_API_SPEECH = "MICROBIT.API.SPEECH"
42+
MICROBIT_API_UTIME = "MICROBIT.API.UTIME"

src/adafruit_circuitplayground/test/test_utils.py renamed to src/common/test/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from unittest import mock
44

5-
from .. import constants as CONSTANTS
5+
from common import constants as CONSTANTS
66
from common import utils
77

88

src/common/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,16 @@ def escape_if_OSX(file_name):
4747
if sys.platform == CONSTANTS.MAC_OS:
4848
file_name = file_name.replace(" ", "%20")
4949
return file_name
50+
51+
52+
def print_for_unimplemented_functions(function_name, one_more_call=False):
53+
# Frame 0 is this function call
54+
# Frame 1 is the call that calls this function, which is a microbit function
55+
# Frame 2 is the call that calls the microbit function, which is in the user's file
56+
# If one_more_call is True, then there is another frame between what was originally supposed to be frame 1 and 2.
57+
frame_no = 2 if not one_more_call else 3
58+
line_number = sys._getframe(frame_no).f_lineno
59+
user_file_name = sys._getframe(frame_no).f_code.co_filename
60+
print(
61+
f"'{function_name}' on line {line_number} in {user_file_name} is not implemented in the simulator but it will work on the actual device!"
62+
)

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const CONSTANTS = {
121121
FILESYSTEM: {
122122
OUTPUT_DIRECTORY: "out",
123123
PYTHON_VENV_DIR: "venv",
124+
MICROPYTHON_DIRECTORY: "micropython",
124125
},
125126
INFO: {
126127
ALREADY_SUCCESSFUL_INSTALL: localize(

src/debug_user_code.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@
1111
# will propagate errors if dependencies aren't sufficient
1212
check_python_dependencies.check_for_dependencies()
1313

14-
# Insert absolute path to Adafruit library into sys.path
1514
abs_path_to_parent_dir = os.path.dirname(os.path.abspath(__file__))
16-
abs_path_to_lib = os.path.join(abs_path_to_parent_dir, CONSTANTS.LIBRARY_NAME)
17-
sys.path.insert(0, abs_path_to_lib)
1815

19-
# Insert absolute path to python libraries into sys.path
20-
abs_path_to_parent_dir = os.path.dirname(os.path.abspath(__file__))
21-
sys.path.insert(0, abs_path_to_lib)
16+
# Insert absolute path to Adafruit library for CPX into sys.path
17+
abs_path_to_adafruit_lib = os.path.join(
18+
abs_path_to_parent_dir, CONSTANTS.ADAFRUIT_LIBRARY_NAME
19+
)
20+
sys.path.insert(0, abs_path_to_adafruit_lib)
21+
22+
# Insert absolute path to Micropython libraries for micro:bit into sys.path
23+
abs_path_to_micropython_lib = os.path.join(
24+
abs_path_to_parent_dir, CONSTANTS.MICROPYTHON_LIBRARY_NAME
25+
)
26+
sys.path.insert(0, abs_path_to_micropython_lib)
2227

2328
# This import must happen after the sys.path is modified
2429
from adafruit_circuitplayground.express import cpx

src/extension.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,10 @@ const handleNewFileErrorTelemetry = () => {
12731273
const updatePythonExtraPaths = () => {
12741274
updateConfigLists(
12751275
"python.autoComplete.extraPaths",
1276-
[__dirname],
1276+
[
1277+
__dirname,
1278+
path.join(__dirname, CONSTANTS.FILESYSTEM.MICROPYTHON_DIRECTORY),
1279+
],
12771280
vscode.ConfigurationTarget.Global
12781281
);
12791282
};
@@ -1283,12 +1286,20 @@ const updatePylintArgs = (context: vscode.ExtensionContext) => {
12831286
context.extensionPath,
12841287
CONSTANTS.FILESYSTEM.OUTPUT_DIRECTORY
12851288
);
1289+
const micropythonPath: string = utils.createEscapedPath(
1290+
context.extensionPath,
1291+
CONSTANTS.FILESYSTEM.OUTPUT_DIRECTORY,
1292+
CONSTANTS.FILESYSTEM.MICROPYTHON_DIRECTORY
1293+
);
12861294

12871295
// update pylint args to extend system path
12881296
// to include python libs local to extention
12891297
updateConfigLists(
12901298
"python.linting.pylintArgs",
1291-
["--init-hook", `import sys; sys.path.append(\"${outPath}\")`],
1299+
[
1300+
"--init-hook",
1301+
`import sys; sys.path.extend([\"${outPath}\",\"${micropythonPath}\"])`,
1302+
],
12921303
vscode.ConfigurationTarget.Workspace
12931304
);
12941305
};
File renamed without changes.

src/micropython/audio.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from common import utils
2+
from common.telemetry import telemetry_py
3+
from common.telemetry_events import TelemetryEvent
4+
5+
# The implementation is based off of https://microbit-micropython.readthedocs.io/en/v1.0.1/audio.html.
6+
7+
8+
def play(source, wait=True, pin="pin0", return_pin=None):
9+
"""
10+
This function is not implemented in the simulator.
11+
12+
Play the source to completion.
13+
14+
``source`` is an iterable, each element of which must be an ``AudioFrame``.
15+
16+
If ``wait`` is ``True``, this function will block until the source is exhausted.
17+
18+
``pin`` specifies which pin the speaker is connected to.
19+
20+
``return_pin`` specifies a differential pin to connect to the speaker
21+
instead of ground.
22+
"""
23+
utils.print_for_unimplemented_functions(play.__name__)
24+
telemetry_py.send_telemetry(TelemetryEvent.MICROBIT_API_AUDIO)
25+
26+
27+
class AudioFrame:
28+
"""
29+
This class is not implemented in the simulator.
30+
31+
An ``AudioFrame`` object is a list of 32 samples each of which is a signed byte
32+
(whole number between -128 and 127).
33+
34+
It takes just over 4 ms to play a single frame.
35+
"""
36+
37+
def __init__(self):
38+
utils.print_for_unimplemented_functions(AudioFrame.__init__.__qualname__)
39+
telemetry_py.send_telemetry(TelemetryEvent.MICROBIT_API_AUDIO)

src/microbit/__init__.py renamed to src/micropython/microbit/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,24 @@
66
accelerometer = __mb.accelerometer
77
button_a = __mb.button_a
88
button_b = __mb.button_b
9+
compass = __mb.compass
910
display = __mb.display
11+
i2c = __mb.i2c
12+
spi = __mb.spi
13+
14+
15+
def panic(n):
16+
"""
17+
Enter a panic mode. Requires restart. Pass in an arbitrary integer <= 255 to indicate a status
18+
"""
19+
__mb.panic(n)
20+
21+
22+
def reset():
23+
"""
24+
Restart the board.
25+
"""
26+
__mb.reset()
1027

1128

1229
def sleep(n):

0 commit comments

Comments
 (0)