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

Commit 1f3023c

Browse files
Merge pull request #339 from microsoft/dev
Official CLUE release
2 parents 9a1adc9 + f090660 commit 1f3023c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1933
-1617
lines changed

README.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<a href='https://microsoftgarage.visualstudio.com/002806e2-ebaa-4672-9d2e-5fe5d29154ef/_boards/board/t/227906bb-31ac-4b07-8626-3d757754a616/Microsoft.RequirementCategory/'><img src='https://microsoftgarage.visualstudio.com/002806e2-ebaa-4672-9d2e-5fe5d29154ef/227906bb-31ac-4b07-8626-3d757754a616/_apis/work/boardbadge/73f82653-3da1-4a6f-bb79-c91c9eecec28' alt='Azure DevOps Board Badge' /></a>
66

7-
Make without limit! Device Simulator Express, a Microsoft Garage project, allows you to code microcontrollers without the hardware on hand! You can program your Adafruit Circuit Playground Express (CPX) or your BBC micro:bit! Test and debug your code on the device simulator and see the same
7+
Make without limit! Device Simulator Express, a Microsoft Garage project, allows you to code microcontrollers without the hardware on hand! You can program your Adafruit Circuit Playground Express (CPX), your BBC micro:bit or the Adafruit CLUE! Test and debug your code on the device simulator and see the same
88
result when you plug in your actual microcontroller. Curious about the output of the device, the serial
99
monitor allows you to observe the device output.
1010

@@ -18,7 +18,7 @@ monitor allows you to observe the device output.
1818

1919
[<img alt='bbc micro:bit' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/microbit/microbit.png'>](#bbc-microbit-simulator)
2020

21-
- [**Adafruit CLUE**](#adafruit-clue-simulator) (hidden behind preview flag)
21+
- [**Adafruit CLUE**](#adafruit-clue-simulator)
2222

2323
[<img alt='Adafruit CLUE' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/clue/clue.png'>](#adafruit-clue-simulator)
2424

@@ -120,8 +120,6 @@ In Device Simulator Express, you can use keyboard to interact with the device:
120120

121121
## Adafruit CLUE Simulator
122122

123-
NOTE: This simulator is hidden under the preview mode flag. See below on how to enable the preview mode flag.
124-
125123
### Features
126124

127125
- IntelliSense and syntax highlighting for CircuitPython code for the following drivers and libraries:
@@ -164,22 +162,6 @@ NOTE: This simulator is hidden under the preview mode flag. See below on how to
164162
- Refresh the simulator: <kbd>Shift</kbd> + <kbd>R</kbd>
165163
- Run the simulator: <kbd>Shift</kbd> + <kbd>F</kbd>
166164

167-
## How to enable preview flag
168-
169-
Currently, we have our Adafruit CLUE simulator hidden behind a preview flag and we want you to try it out!
170-
171-
### I. Open settings
172-
173-
For Windows and Linux, you can use <kbd>Ctrl</kbd> + <kbd>,</kbd> or use `File -> Preferences -> Settings` in the top menu to navigate to settings. For Mac, you can use <kbd>Cmd</kbd> + <kbd>,</kbd> or use `Code -> Preferences -> Settings`.
174-
175-
<img alt='Adafruit CLUE' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/clue/open_settings.PNG'>
176-
177-
### II. Search for our preview flag and enable it!
178-
179-
In the top search bar, search for `DeviceSimulatorExpress.previewMode`. Then, check the checkbox for the setting that pops up when you serach.
180-
181-
<img alt='Adafruit CLUE' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/clue/check_preview_mode.gif'>
182-
183165
## How to use
184166

185167
To use Device Simulator Express, install the extension from the marketplace and reload VS Code.
@@ -225,8 +207,12 @@ Before deploying the Python code to your CPX device, you need to format your dev
225207
- Download the lastest versions of the cpx libraries (link: https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).
226208

227209
- _For the micro:bit_:
210+
228211
- Download the firmware with the .hex file (link: https://microbit.org/get-started/user-guide/firmware/).
229212

213+
- _For the CLUE_:
214+
- Download the latest versions of the cpx libraries and follow the instructions here (link:https://learn.adafruit.com/adafruit-clue/circuitpython).
215+
230216
1. Plug in your device (make sure it’s formatted properly already).
231217
2. Run the command `"Device Simulator Express: Deploy to Device"`.
232218

@@ -305,6 +291,7 @@ A `ThirdPartyNotices.txt` file is provided in the extension's source code listin
305291
- If you try to deploy to the CPX while it's plugged in but you still get an error saying it cannot find the board, make sure your device is formatted correctly and that its name matches `CIRCUITPY`.
306292
- If you can't get the Simulator communication working while debugging, try to open your `Settings` and check the port used under `"Device Simulator Express: Debugger Server Port"`. You can either change it (usually ports above 5000 should work) or try to free it, then start debugging again.
307293
- When you are using the serial monitor, if you get some unusual error messages, unplug the device and reload the VS Code windows.
294+
- If you're using Ubuntu and having some problems with setting up the environment, try reviewing [this article's](https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-ubuntu-16-04) "Step 1" section on how to set up Python 3 on Ubuntu 16.04. Then, ensure that you've run `sudo apt-get install -y python3-venv` to allow for virtual environment creation.
308295

309296
## License
310297

locales/en/package.i18n.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@
1313
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
1414
"deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange": "When you change the Python interpreter, the Device Simulator Express will automatically configure itself for the required dependencies.",
1515
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.",
16-
"deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask if we can download dependencies. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files.",
17-
"deviceSimulatorExpressExtension.configuration.properties.previewMode": "Enable this to test out and play with the new Adafruit CLUE simulator!"
16+
"deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask if we can download dependencies. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files."
1817
}

package-lock.json

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

package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,6 @@
144144
"default": 5577,
145145
"description": "%deviceSimulatorExpressExtension.configuration.properties.debuggerPort%",
146146
"scope": "resource"
147-
},
148-
"deviceSimulatorExpress.previewMode": {
149-
"type": "boolean",
150-
"default": false,
151-
"description": "%deviceSimulatorExpressExtension.configuration.properties.previewMode%",
152-
"scope": "resource"
153147
}
154148
}
155149
},
@@ -286,7 +280,7 @@
286280
"tslint-microsoft-contrib": "^6.1.0",
287281
"tslint-react": "^3.6.0",
288282
"tslint-react-hooks": "^2.0.0",
289-
"typescript": "^3.3.1",
283+
"typescript": "^3.8.3",
290284
"typescript-react-intl": "^0.4.0",
291285
"version-from-git": "^1.1.1",
292286
"vsce": "^1.47.0",

package.nls.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@
1313
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
1414
"deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange": "When you change the Python interpreter, the Device Simulator Express will automatically configure itself for the required dependencies.",
1515
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.",
16-
"deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask for dependency downloads. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files.",
17-
"deviceSimulatorExpressExtension.configuration.properties.previewMode": "Enable this to test out and play with the new Adafruit CLUE simulator!"
16+
"deviceSimulatorExpressExtension.configuration.properties.dependencyChecker": "Whether or not to ask for dependency downloads. If unchecked, the extension will default to never download dependencies, except when automatically creating a virtual environment in the extension files."
1817
}

src/adafruit_circuitplayground/constants.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT license.
33

4+
5+
class EXPRESS_STATE:
6+
BUTTON_A = "button_a"
7+
BUTTON_B = "button_b"
8+
ACCELERATION = "acceleration"
9+
BRIGHTNESS = "brightness"
10+
PIXELS = "pixels"
11+
RED_LED = "red_led"
12+
SWITCH = "switch"
13+
TEMPERATURE = "temperature"
14+
LIGHT = "light"
15+
MOTION_X = "motion_x"
16+
MOTION_Y = "motion_y"
17+
MOTION_Z = "motion_z"
18+
TOUCH = "touch"
19+
SHAKE = "shake"
20+
DETECT_TAPS = "detect_taps"
21+
22+
423
ASSIGN_PIXEL_TYPE_ERROR = (
524
"The pixel color value type should be tuple, list or hexadecimal."
625
)
@@ -32,18 +51,28 @@
3251
TIME_DELAY = 0.03
3352

3453

35-
EVENTS_BUTTON_PRESS = ["button_a", "button_b", "switch"]
36-
EVENTS_SENSOR_CHANGED = ["temperature", "light", "motion_x", "motion_y", "motion_z"]
54+
EVENTS_BUTTON_PRESS = [
55+
EXPRESS_STATE.BUTTON_A,
56+
EXPRESS_STATE.BUTTON_B,
57+
EXPRESS_STATE.SWITCH,
58+
]
59+
EVENTS_SENSOR_CHANGED = [
60+
EXPRESS_STATE.TEMPERATURE,
61+
EXPRESS_STATE.LIGHT,
62+
EXPRESS_STATE.MOTION_X,
63+
EXPRESS_STATE.MOTION_Y,
64+
EXPRESS_STATE.MOTION_Z,
65+
]
3766

3867
ALL_EXPECTED_INPUT_EVENTS = [
39-
"button_a",
40-
"button_b",
41-
"switch",
42-
"temperature",
43-
"light",
44-
"shake",
45-
"motion_x",
46-
"motion_y",
47-
"motion_z",
48-
"touch",
68+
EXPRESS_STATE.BUTTON_A,
69+
EXPRESS_STATE.BUTTON_B,
70+
EXPRESS_STATE.SWITCH,
71+
EXPRESS_STATE.TEMPERATURE,
72+
EXPRESS_STATE.LIGHT,
73+
EXPRESS_STATE.SHAKE,
74+
EXPRESS_STATE.MOTION_X,
75+
EXPRESS_STATE.MOTION_Y,
76+
EXPRESS_STATE.MOTION_Z,
77+
EXPRESS_STATE.TOUCH,
4978
]

src/adafruit_circuitplayground/express.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,69 @@
1414
from collections import namedtuple
1515
import common
1616

17-
Acceleration = namedtuple("acceleration", ["x", "y", "z"])
17+
Acceleration = namedtuple(CONSTANTS.EXPRESS_STATE.ACCELERATION, ["x", "y", "z"])
1818

1919

2020
class Express:
2121
def __init__(self):
2222
# State in the Python process
23-
self.__state = {
24-
"brightness": 1.0,
25-
"button_a": False,
26-
"button_b": False,
27-
"pixels": [
28-
(0, 0, 0),
29-
(0, 0, 0),
30-
(0, 0, 0),
31-
(0, 0, 0),
32-
(0, 0, 0),
33-
(0, 0, 0),
34-
(0, 0, 0),
35-
(0, 0, 0),
36-
(0, 0, 0),
37-
(0, 0, 0),
38-
],
39-
"red_led": False,
40-
"switch": False,
41-
"temperature": 0,
42-
"light": 0,
43-
"motion_x": 0,
44-
"motion_y": 0,
45-
"motion_z": 0,
46-
"touch": [False] * 7,
47-
"shake": False,
48-
}
23+
self.__state = {}
24+
self.__state[CONSTANTS.EXPRESS_STATE.BRIGHTNESS] = 1.0
25+
self.__state[CONSTANTS.EXPRESS_STATE.BUTTON_A] = False
26+
self.__state[CONSTANTS.EXPRESS_STATE.BUTTON_B] = False
27+
self.__state[CONSTANTS.EXPRESS_STATE.PIXELS] = [
28+
(0, 0, 0),
29+
(0, 0, 0),
30+
(0, 0, 0),
31+
(0, 0, 0),
32+
(0, 0, 0),
33+
(0, 0, 0),
34+
(0, 0, 0),
35+
(0, 0, 0),
36+
(0, 0, 0),
37+
(0, 0, 0),
38+
]
39+
self.__state[CONSTANTS.EXPRESS_STATE.RED_LED] = False
40+
self.__state[CONSTANTS.EXPRESS_STATE.SWITCH] = False
41+
self.__state[CONSTANTS.EXPRESS_STATE.TEMPERATURE] = 0
42+
self.__state[CONSTANTS.EXPRESS_STATE.LIGHT] = 0
43+
self.__state[CONSTANTS.EXPRESS_STATE.MOTION_X] = 0
44+
self.__state[CONSTANTS.EXPRESS_STATE.MOTION_Y] = 0
45+
self.__state[CONSTANTS.EXPRESS_STATE.MOTION_Z] = 0
46+
self.__state[CONSTANTS.EXPRESS_STATE.TOUCH] = [False] * 7
47+
self.__state[CONSTANTS.EXPRESS_STATE.SHAKE] = False
48+
self.__state[CONSTANTS.EXPRESS_STATE.DETECT_TAPS] = 0
4949
self.pixels = Pixel(self.__state)
5050

5151
@property
5252
def acceleration(self):
5353
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_ACCELERATION)
5454
return Acceleration(
55-
self.__state["motion_x"], self.__state["motion_y"], self.__state["motion_z"]
55+
self.__state[CONSTANTS.EXPRESS_STATE.MOTION_X],
56+
self.__state[CONSTANTS.EXPRESS_STATE.MOTION_Y],
57+
self.__state[CONSTANTS.EXPRESS_STATE.MOTION_Z],
5658
)
5759

5860
@property
5961
def button_a(self):
6062
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_BUTTON_A)
61-
return self.__state["button_a"]
63+
return self.__state[CONSTANTS.EXPRESS_STATE.BUTTON_A]
6264

6365
@property
6466
def button_b(self):
6567
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_BUTTON_B)
66-
return self.__state["button_b"]
68+
return self.__state[CONSTANTS.EXPRESS_STATE.BUTTON_B]
6769

6870
@property
6971
def detect_taps(self):
7072
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_DETECT_TAPS)
71-
return self.__state["detect_taps"]
73+
return self.__state[CONSTANTS.EXPRESS_STATE.DETECT_TAPS]
7274

7375
@detect_taps.setter
7476
def detect_taps(self, value):
7577
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_DETECT_TAPS)
7678
value_int = int(value)
77-
self.__state["detect_taps"] = (
79+
self.__state[CONSTANTS.EXPRESS_STATE.DETECT_TAPS] = (
7880
value_int if (value_int == 1 or value_int == 2) else 1
7981
)
8082

@@ -88,28 +90,28 @@ def tapped(self):
8890
@property
8991
def red_led(self):
9092
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_RED_LED)
91-
return self.__state["red_led"]
93+
return self.__state[CONSTANTS.EXPRESS_STATE.RED_LED]
9294

9395
@red_led.setter
9496
def red_led(self, value):
9597
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_RED_LED)
96-
self.__state["red_led"] = bool(value)
98+
self.__state[CONSTANTS.EXPRESS_STATE.RED_LED] = bool(value)
9799
self.__show()
98100

99101
@property
100102
def switch(self):
101103
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_SWITCH)
102-
return self.__state["switch"]
104+
return self.__state[CONSTANTS.EXPRESS_STATE.SWITCH]
103105

104106
@property
105107
def temperature(self):
106108
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_TEMPERATURE)
107-
return self.__state["temperature"]
109+
return self.__state[CONSTANTS.EXPRESS_STATE.TEMPERATURE]
108110

109111
@property
110112
def light(self):
111113
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_LIGHT)
112-
return self.__state["light"]
114+
return self.__state[CONSTANTS.EXPRESS_STATE.LIGHT]
113115

114116
def __show(self):
115117
if utils.debug_mode:
@@ -121,7 +123,7 @@ def __show(self):
121123

122124
def __touch(self, i):
123125
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_TOUCH)
124-
return self.__state["touch"][i - 1]
126+
return self.__state[CONSTANTS.EXPRESS_STATE.TOUCH][i - 1]
125127

126128
@property
127129
def touch_A1(self):
@@ -160,7 +162,7 @@ def adjust_touch_threshold(self, adjustment):
160162

161163
def shake(self, shake_threshold=30):
162164
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_SHAKE)
163-
return self.__state["shake"]
165+
return self.__state[CONSTANTS.EXPRESS_STATE.SHAKE]
164166

165167
def play_file(self, file_name):
166168
telemetry_py.send_telemetry(TelemetryEvent.CPX_API_PLAY_FILE)

0 commit comments

Comments
 (0)