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

Deploy code to micro:bit and removed need to rename file to deploy to CPX #233

Merged
merged 20 commits into from
Mar 4, 2020
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Before deploying the python code to your CPX device, you need to format your dev

1. Download the firmware with the .uf2 file (link: https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart)
2. Download the lastest version of the cpx library (link: https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).
**_Note:_** Make sure you name your file `main.py` or `code.py`: the device automatically runs the first file that is likely named. This is the convention for CircuitPython ([source](https://learn.adafruit.com/welcome-to-circuitpython/creating-and-editing-code#naming-your-program-file-7-32)).

Then, if you are on Windows, you will also need to install the Python Pywin32 package. Use the following command in the console: `pip install pywin32`

Expand Down Expand Up @@ -135,7 +134,7 @@ Device Simulator Express provides several commands in the Command Palette (F1 or
- `Device Simulator Express: [Circuit Playground Express] New File`: Opens an unsaved .py file with template code, also opens the simulator.
- `Device Simulator Express: [Circuit Playground Express] Open Simulator`: Opens the simulator in the webView
- `Device Simulator Express: [Circuit Playground Express] Run on Simulator`: Runs python code on the simulator
- `Device Simulator Express: [Circuit Playground Express] Deploy to Device`: Copies & Pastes the code.py or main.py file to CIRCUITPY drive if detected a CPX is plugged in
- `Device Simulator Express: [Circuit Playground Express] Deploy to Device`: Copies & Pastes the current file to CIRCUITPY drive if detected a CPX is plugged in
- `Device Simulator Express: [Circuit Playground Express] Open Serial Monitor`: Opens the serial monitor in the integrated output window.
- `Device Simulator Express: [Circuit Playground Express] Close Serial Monitor`: Stops the serial monitor and releases the serial port.
- `Device Simulator Express: [Circuit Playground Express] Change Baud Rate`: Changes the baud rate of the selected serial port. For Adafruit CPX, the default baud rate is 115200.
Expand All @@ -160,6 +159,7 @@ In Device Simulator Express, you can use keyboard to interact with the device:
- IntelliSense and syntax highlighting for micro:bit code
- Template file generation
- Integrated Python Debugging for the Simulator
- Deploy MicroPython code to the physical device.
- Simulation of the micro:bit device, including:
- 25 LEDs
- Light sensor
Expand Down Expand Up @@ -252,4 +252,3 @@ A `ThirdPartyNotices.txt` file is provided in the extension's source code listin

1. Make sure that when you type _python_ in a terminal, the command is recognized and you have the correct version. The easiest way to do it is to select the "Add to PATH" option directly when you install Python. Otherwise you can search how to insert it manually.
2. You can choose to see the prompt or not by changing the extension configurations.
3. To be able to run the file on your physical device, it should either be named code.py or main.py.
20 changes: 20 additions & 0 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5829,6 +5829,26 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


uflash
The MIT License (MIT)
Copyright (c) 2015-2018 Nicholas H.Tollervey and others.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------

-------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Commands are accessible through :

- **Open Simulator** : opens the webview of the simulator.

- **New File** : opens an unsaved file with links to help you and a code snippet that you can save as `code.py` / `main.py`.
- **New File** : opens an unsaved file to help you and a code snippet that you can save and play around with.
_(**Note :** will open the simulator webview if it's not open yet)_.

- **Run Simulator** : runs the code you have opened in the simulator (make sure you've clicked on a valid code file).
Expand Down
4 changes: 0 additions & 4 deletions locales/en/out/constants.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
"dialogResponses.readInstall": "Read installation docs",
"error.debuggerServerInitFailed": "Warning : The Debugger Server cannot be opened. Please try to free the port {0} if it's already in use or select another one in your Settings 'Device Simulator Express: Debugger Server Port' and start another debug session.\n You can still debug your code but you won't be able to use the Simulator.",
"error.debuggingSessionInProgress": "[ERROR] A debugging session is currently in progress, please stop it before running your code. \n",
"error.incorrectFileNameForDevice": "[ERROR] Can\\'t deploy to your Circuit Playground Express device, please rename your file to \"code.py\" or \"main.py\". \n",
"error.incorrectFileNameForDevicePopup": "Seems like you have a different file name than what the CPX requires, please rename it to \"code.py\" or \"main.py\".",
"error.incorrectFileNameForSimulatorPopup": "We want your code to work on your actual board as well. Make sure you name your file \"code.py\" or \"main.py\" to be able to run your code on an actual physical device.",
"error.invalidFileNameDebug": "The file you tried to debug isn\\'t named \"code.py\" or \"main.py\\. Rename your file if you want your code to work on your actual device.",
"error.noDevice": "No plugged in boards detected. Please double check if your board is connected and/or properly formatted",
"error.noFileToRun": "\n[ERROR] We can't find the .py file to run on simulator. Open up a new .py file, or browse through some examples\n",
"error.noFolderCreated": "In order to use the Serial Monitor, you need to open a folder and reload VS Code.",
Expand Down
3 changes: 2 additions & 1 deletion locales/en/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
"deviceSimulatorExpressExtension.commands.microbit.deployToDevice": "[micro:bit] Deploy to Device",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
"deviceSimulatorExpressExtension.configuration.properties.configEnvOnChange": "When you change the Python interpreter, the Device Simulator Express will automatically configure itself for the required dependencies.",
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger.",
"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."
"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.",
"deviceSimulatorExpressExtension.configuration.properties.previewMode": "Enable this to test out and play with the new micro:bit simulator!"
}
16 changes: 4 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"onCommand:deviceSimulatorExpress.cpx.openSerialMonitor",
"onCommand:deviceSimulatorExpress.cpx.openSimulator",
"onCommand:deviceSimulatorExpress.cpx.selectSerialPort",
"onCommand:deviceSimulatorExpress.microbit.deployToDevice",
"onCommand:deviceSimulatorExpress.microbit.newFile",
"onCommand:deviceSimulatorExpress.microbit.openSimulator",
"onDebug"
Expand Down Expand Up @@ -89,6 +90,11 @@
"title": "%deviceSimulatorExpressExtension.commands.cpx.selectSerialPort%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.microbit.deployToDevice",
"title": "%deviceSimulatorExpressExtension.commands.microbit.deployToDevice%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.microbit.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.microbit.openSimulator%",
Expand All @@ -102,6 +108,12 @@
],
"menus": {
"commandPalette": [
{
"command": "deviceSimulatorExpress.microbit.deployToDevice",
"title": "%deviceSimulatorExpressExtension.commands.microbit.deployToDevice%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%",
"when": "config.deviceSimulatorExpress.previewMode"
},
{
"command": "deviceSimulatorExpress.microbit.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.microbit.openSimulator%",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.cpx.deployToDevice": "[Circuit Playground Express] Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.selectSerialPort": "[Circuit Playground Express] Select Serial Port",
"deviceSimulatorExpressExtension.commands.microbit.deployToDevice": "[micro:bit] Deploy to Device",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
Expand Down
34 changes: 11 additions & 23 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ export const CONSTANTS = {
`[ERROR] Failed to open serial port ${port} due to error: ${error}. \n`
);
},
INCORRECT_FILE_NAME_FOR_DEVICE: localize(
"error.incorrectFileNameForDevice",
'[ERROR] Can\'t deploy to your Circuit Playground Express device, please rename your file to "code.py" or "main.py". \n'
),
INCORRECT_FILE_NAME_FOR_DEVICE_POPUP: localize(
"error.incorrectFileNameForDevicePopup",
'Seems like you have a different file name than what CPX requires, please rename it to "code.py" or "main.py".'
),
INSTALLATION_ERROR: localize(
"error.installationError",
"Installation Error"
Expand All @@ -85,6 +77,10 @@ export const CONSTANTS = {
"error.invalidPythonPath",
'We found that your selected Python interpreter version is too low to run the extension. Please upgrade to version 3.7+ or select a different interpreter (CTRL+SHIFT+P and type "python.selectInterpreter") and restart the application.'
),
LOW_PYTHON_VERSION_FOR_MICROBIT_DEPLOYMENT: localize(
"error.lowPythonVersionForMicrobitDeployment",
"To deploy your code to the micro:bit, you must be using Python 3.3+"
),
NO_DEVICE: localize(
"error.noDevice",
"No plugged in boards detected. Please double check if your board is connected and/or properly formatted"
Expand Down Expand Up @@ -155,11 +151,11 @@ export const CONSTANTS = {
),
DEPLOY_SUCCESS: localize(
"info.deploySuccess",
"\n[INFO] Code successfully copied! Your Circuit Playground Express should be loading and ready to go shortly.\n"
"\n[INFO] Code successfully copied! Your device should be loading and ready to go shortly.\n"
),
EXTENSION_ACTIVATED: localize(
"info.extensionActivated",
"Congratulations, your extension Adafruit_Simulator is now active!"
"Congratulations, your extension Device Simulator Express is now active!"
),
FILE_SELECTED: (filePath: string) => {
return localize(
Expand All @@ -171,10 +167,6 @@ export const CONSTANTS = {
"info.firstTimeWebview",
'To reopen the simulator select the command "Open Simulator" from command palette.'
),
INCORRECT_FILE_NAME_FOR_SIMULATOR_POPUP: localize(
"info.incorrectFileNameForSimulatorPopup",
'We want your code to work on your actual board as well. Make sure you name your file "code.py" or "main.py" to be able to run your code on an actual physical device'
),
INSTALLING_PYTHON_VENV: localize(
"info.installingPythonVenv",
"A virtual environment is currently being created. The required Python packages will be installed. You will be prompted a message telling you when the installation is done."
Expand All @@ -187,10 +179,6 @@ export const CONSTANTS = {
"info.installPythonVenv",
"Do you want us to try and install this extension's dependencies via virtual environment for you?"
),
INVALID_FILE_NAME_DEBUG: localize(
"info.invalidFileNameDebug",
'The file you tried to debug isn\'t named "code.py" or "main.py". Rename your file if you want your code to work on your actual device.'
),
NEW_FILE: localize(
"info.newFile",
"New to Python or the Circuit Playground Express? We are here to help!"
Expand Down Expand Up @@ -336,6 +324,7 @@ export enum TelemetryEventName {
CPX_COMMAND_SERIAL_MONITOR_BAUD_RATE = "CPX.COMMAND.SERIAL_MONITOR.BAUD_RATE",
CPX_COMMAND_SERIAL_MONITOR_CLOSE = "CPX.COMMAND.SERIAL_MONITOR.CLOSE",

MICROBIT_COMMAND_DEPLOY_DEVICE = "MICROBIT.COMMAND.DEPLOY.DEVICE",
MICROBIT_COMMAND_NEW_FILE = "MICROBIT.COMMAND.NEW.FILE",
MICROBIT_COMMAND_OPEN_SIMULATOR = "MICROBIT.COMMAND.OPEN.SIMULATOR",

Expand Down Expand Up @@ -373,12 +362,16 @@ export enum TelemetryEventName {
CPX_SUCCESS_COMMAND_DEPLOY_DEVICE = "CPX.SUCCESS.COMMAND.DEPLOY.DEVICE",

MICROBIT_ERROR_COMMAND_NEW_FILE = "MICROBIT.ERROR.COMMAND.NEW.FILE",
MICROBIT_ERROR_DEPLOY_WITHOUT_DEVICE = "MICROBIT.ERROR.DEPLOY.WITHOUT.DEVICE",
MICROBIT_ERROR_PYTHON_DEVICE_PROCESS = "MICROBIT.ERROR.PYTHON.DEVICE.PROCESS",
MICROBIT_SUCCESS_COMMAND_DEPLOY_DEVICE = "MICROBIT.SUCCESS.COMMAND.DEPLOY.DEVICE",

// Performance
CPX_PERFORMANCE_DEPLOY_DEVICE = "CPX.PERFORMANCE.DEPLOY.DEVICE",
CPX_PERFORMANCE_NEW_FILE = "CPX.PERFORMANCE.NEW.FILE",
CPX_PERFORMANCE_OPEN_SIMULATOR = "CPX.PERFORMANCE.OPEN.SIMULATOR",

MICROBIT_PERFORMANCE_DEPLOY_DEVICE = "MICROBIT.PERFORMANCE.DEPLOY.DEVICE",
MICROBIT_PERFORMANCE_NEW_FILE = "MICROBIT.PERFORMANCE.NEW.FILE",
MICROBIT_PERFORMANCE_OPEN_SIMULATOR = "MICROBIT.PERFORMANCE.OPEN.SIMULATOR",
}
Expand Down Expand Up @@ -450,11 +443,6 @@ export namespace DialogResponses {

export const CPX_CONFIG_FILE = path.join(".vscode", "cpx.json");

export const USER_CODE_NAMES = {
CODE_PY: "code.py",
MAIN_PY: "main.py",
};

export const STATUS_BAR_PRIORITY = {
PORT: 20,
OPEN_PORT: 30,
Expand Down
Loading