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

Commit

Permalink
Merge branch 'dev' into users/t-xunguy/clue-sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
xnkevinnguyen committed Apr 1, 2020
2 parents a10f3eb + 66f72f3 commit 7441dc5
Show file tree
Hide file tree
Showing 30 changed files with 2,167 additions and 796 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
}
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
162 changes: 50 additions & 112 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,78 +78,6 @@ As we only support CPX library now, other libraries (i.e. simpleio) can’t run
- [Download Firmware .uf2 file](https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart)
- [Download the latest version of the Adafruit CPX library](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries)

### How to use

To use Device Simulator Express, install the extension from the marketplace and reload VS Code.

#### I. Take a look at the "Device Simulator Express: Getting Started" Command.
1. Type in `"Device Simulator Express: [Circuit Playground Express] New File"` in the command palette (`CTRL + SHIFT + P` / `CMD + SHIFT + P` to open the command palette).
<img alt='Getting Started' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/getting_started.png'>
2. Choose the `CPX` option from the dropdown.
3. Read, copy and learn some of the things you can do with the simulator!

#### II. Start with the "Device Simulator Express [Circuit Playground Express]: New File" Command.

1. Type in `"Device Simulator Express: [Circuit Playground Express] New File"` in the command palette (`CTRL + SHIFT + P` / `CMD + SHIFT + P` to open the command palette).
<img alt='"New CPX File" animation' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/cpx/cpx-new-file.gif'>
2. Name and save your file somewhere, and we’re good to go!
3. Start with some examples: you can find examples files and tutorials inside the comments, as well as in the notification pop up when you run the `"Device Simulator Express: [Circuit Playground Express] New File"` Command.

#### III. Start from an existing Python file.

1. Open the folder or your .py file in Visual Studio Code.
2. Run `Device Simulator Express: [Circuit Playground Express] Open Simulator` from the command palette or icon in the editor toolbar.

#### IV. Run your code on the simulator.

<img alt='How to run the CPX simulator animation' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/cpx/cpx-run.gif'>

1. Run `Run Simulator` from the command palette or use the `Play` button on the simulator webview.

#### V. Deploy your code to the physical device

Before deploying the Python code to your CPX device, you need to format your device by following these tutorials:

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).

<img alt='Deploy to CPX Device' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/cpx/cpx-deploy.png'>

#### VI. Use the Serial Monitor for your Adafruit CPX device (available on Windows and Mac only)

1. Plug in your CPX device (make sure it’s formatted properly already).
2. Run the command `"Device Simulator Express: Open Serial Monitor"`.
3. Select your baud rate for the serial port.
4. The `print()` statements in your code will show in the output console.

#### VII. Use the sensors in the Device Simulator Express

Generating input for the sensors can be done by interacting directly with device on the webview
or by using the toolbar.

- **Switch, push buttons and capacitive touch:** click directly on the corresponding element on the device or use the keybindings.
- **Temperature sensor, Light sensor, Acceleration sensor:** click on the corresponding button in the toolbar and change the value using the slider or the input box attached to it.
- **Shake detection:** go to the motion sensor section in the toolbar and click on the shake button.

#### VIII. Debug your project on the simulator

1. Add breakpoints in your code
2. Press F5 to enter the debugging mode, and you can start debugging line by line!

### Commands

Device Simulator Express provides several commands in the Command Palette (`F1` or `CTRL + SHIFT + P` / `CMD + SHIFT + P` for Mac OS) for working with \*.py files:

- `Device Simulator Express: Getting Started`: Opens a page in VS Code that helps users get started with the extension. Here, users can browse through code that they can use to play with the simulators.
- `Device Simulator Express: Run Simulator`: Runs Python code on the simulator.
- `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] Deploy to Device`: Copies the current file to CIRCUITPY drive if detected a CPX is plugged in.
- `Device Simulator Express: Open Serial Monitor`: Opens the serial monitor in the integrated output window.
- `Device Simulator Express: Close Serial Monitor`: Stops the serial monitor and releases the serial port.
- `Device Simulator Express: Change Baud Rate`: Changes the baud rate of the selected serial port. For Adafruit CPX, the default baud rate is 115200.
- `Device Simulator Express: Select Serial Port`: Changes the current serial port.

### Keybindings

In Device Simulator Express, you can use keyboard to interact with the device:
Expand All @@ -172,82 +100,92 @@ In Device Simulator Express, you can use keyboard to interact with the device:
- 25 LEDs
- Light sensor
- Motion sensors
- Acceleration detection
- Acceleration detection including gesture detection
- Temperature sensor

### Useful Links
- Tutorials and Example Code for BBC micro:bit:
- [MicroPython documentation](https://microbit-micropython.readthedocs.io/en/latest/)
- [BBC micro:bit examples on the official micro:bit website](https://microbit.org/projects/make-it-code-it/?filters=python)

### How to use
### Keybindings
- Push Button `A for A, B for B, C for A & B`
- Refresh the simulator: `SHIFT + R`
- Run the simulator: `SHIFT + F`

## How to use

#### I. Take a look at the "Device Simulator Express: Getting Started" Command.
1. Type in `"Device Simulator Express: [Circuit Playground Express] New File"` in the command palette (`CTRL + SHIFT + P` / `CMD + SHIFT + P` to open the command palette).
<img alt='Getting Started' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/getting_started.png'>
2. Choose the `micro:bit` option from the dropdown.
To use Device Simulator Express, install the extension from the marketplace and reload VS Code.

### I. Take a look at the "Device Simulator Express: Getting Started" Command.
1. Type in `"Device Simulator Express: Getting Started"` in the command palette (`CTRL + SHIFT + P` / `CMD + SHIFT + P` to open the command palette).
2. Choose the the device you want to play with from the dropdown.
3. Read, copy and learn some of the things you can do with the simulator!

#### II. Start with the "Device Simulator Express [micro:bit]: New File" Command.

1. Type in `"Device Simulator Express: [micro:bit] New File"` in the command palette (`CTRL + SHFT + P / CMD + SHIFT + P` to open the command palette).
<img alt='"New micro:bit File" animation' src='https://github.com/microsoft/vscode-python-devicesimulator/blob/dev/assets/readmeFiles/microbit/microbit-new-file.gif'>
2. Name and save your file somewhere, and we’re good to go!
<img alt='Getting Started' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/getting_started.png'>

### II. Start with the "Device Simulator Express: New File" Command.
1. Type in `"Device Simulator Express: New File"` in the command palette (`CTRL + SHIFT + P` / `CMD + SHIFT + P` to open the command palette).
2. Select the device you want to use.
3. Name and save your file somewhere, and we’re good to go!
4. Start with some examples: you can find examples files and tutorials inside the comments at the top of the file.

#### III. Start from an existing Python file.
<img alt='"New File" animation' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/new_file.gif'>

1. Open the folder or your .py file in Visual Studio Code.
2. Run `Device Simulator Express: [micro:bit] Open Simulator` from the command palette or icon in the editor toolbar.
### III. Start from an existing Python file.

#### IV. Run your code on the simulator.
1. Open the folder or your .py file in Visual Studio Code.
2. Run `Device Simulator Express: Open Simulator` from the command palette or icon in the editor toolbar.
3. Select the device you want to use.

<img alt='How to run the micro:bit simulator animation' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/microbit/microbit-run.gif'>
### IV. Run your code on the simulator.

1. Run `Run Simulator` from the command palette or use the `Play` button on the simulator webview.

#### V. Deploy your code to the physical device
<img alt='How to run the simulator animation' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/run.gif'>

1. Run `[micro:bit] Deploy to Device` from the command palette
### V. Deploy your code to the physical device

<img alt='Deploy to micro:bit device' src='https://github.com/microsoft/vscode-python-devicesimulator/blob/dev/assets/readmeFiles/microbit/microbit-deploy.png'>
Before deploying the Python code to your CPX device, you need to format your device by following these tutorials:

#### VI. Use the Serial Monitor for your BBC micro:bit device (available on Windows and Mac only)
- *For the CPX*:
- Download the firmware with the .uf2 file (link: https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-quickstart).
- Download the lastest versions of the cpx libraries (link: https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

1. Plug in your BBC micro:bit.
2. Run the command `"Device Simulator Express: Open Serial Monitor"`.
3. Select your baud rate for the serial port.
4. The `print()` statements in your code will show in the output console.
- *For the micro:bit*:
- Download the firmware with the .hex file (link: https://microbit.org/get-started/user-guide/firmware/).

#### VII. Use the sensors in the Device Simulator Express
1. Plug in your device (make sure it’s formatted properly already).
2. Run the command `"Device Simulator Express: Deploy to Device"`.

Generating input for the sensors can be done by interacting directly with device on the webview
or by using the toolbar.
<img alt='Deploy to Device' src='https://raw.githubusercontent.com/microsoft/vscode-python-devicesimulator/dev/assets/readmeFiles/deploy.png'>

- **Push buttons:** click directly on the buttons on the device or use the keybindings.
- **Temperature sensor, Light sensor, Acceleration sensor:** click on the corresponding button in the toolbar and change the value using the slider or the input box attached to it.
### VI. Use the Serial Monitor for your device (available on Windows and Mac only)

1. Plug in your device (make sure it’s formatted properly already).
2. Run the command `"Device Simulator Express: Open Serial Monitor"`.
3. Select your baud rate for the serial port.
4. The `print()` statements in your code will show in the output console.

#### VIII. Debug your project on the simulator
### VII. Debug your project on the simulator

1. Add breakpoints in your code
2. Press F5 to enter the debugging mode, and you can start debugging line by line!

### Commands
Using the simulator for the micro:bit is similar to using the one for the CPX. The only difference is that the commands in the command palette display `Device Simulator Express: [micro:bit] <command>` instead of `Device Simulator Express: [Circuit Playground Express] <command>`. Currently, we support the following commands for micro:bit:

Device Simulator Express provides several commands in the Command Palette (`F1` or `CTRL + SHIFT + P` / `CMD + SHIFT + P` for Mac OS) for working with \*.py files:

- `Device Simulator Express: Getting Started`: Opens a page in VS Code that helps users get started with the extension. Here, users can browse through code that they can use to play with the simulators.
- `Device Simulator Express: Run Simulator`: Runs Python code on the simulator.
- `Device Simulator Express: [micro:bit] Open Simulator`: Opens an unsaved .py file with template code, also opens the simulator.
- `Device Simulator Express: [micro:bit] New File`: Opens the simulator in the webView.
- `Device Simulator Express: [micro:bit] Deploy to Device`: Copies the current file to the micro:bit if the device is detected.
- `Device Simulator Express: New File`: Opens an unsaved .py file with template code, also opens the simulator for the selected device.
- `Device Simulator Express: Open Simulator`: Opens the simulator in the simulator window for the selected device
- `Device Simulator Express: Deploy to Device`: Copies the current file to the selected device.
- `Device Simulator Express: Open Serial Monitor`: Opens the serial monitor in the integrated output window.
- `Device Simulator Express: Close Serial Monitor`: Stops the serial monitor and releases the serial port.
- `Device Simulator Express: Change Baud Rate`: Changes the baud rate of the selected serial port. For BBC micro:bit, the default baud rate is 115200.
- `Device Simulator Express: Change Baud Rate`: Changes the baud rate of the selected serial port. For Adafruit CPX, the default baud rate is 115200.
- `Device Simulator Express: Select Serial Port`: Changes the current serial port.

### Keybindings
- Push Button `A for A, B for B, C for A & B`
- Refresh the simulator: `SHIFT + R`
- Run the simulator: `SHIFT + F`

## Contribute
[See here for steps to run the extension locally.](https://github.com/microsoft/vscode-python-devicesimulator/blob/dev/docs/developers-setup.md)

Expand Down
Binary file added assets/readmeFiles/deploy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/readmeFiles/new_file.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/readmeFiles/run.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions locales/en/out/constants.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"error.invalidFileExtensionDebug": "The file you tried to run isn\\'t a Python file.",
"info.newFile": "New to Python or the Circuit Playground Express? We are here to help!",
"info.noDeviceChosenToDeployTo": "\n[INFO] No device was selected to deploy to.\n",
"info.noDeviceChosenToSimulateTo": "\n[INFO] No device was selected to simulate.\n",
"info.noDeviceChosenForNewFile": "\n[INFO] No device was selected to open a template file for.\n",
"info.redirect": "You are being redirected.",
"info.runningCode": "Running user code",
"info.privacyStatement": "Privacy Statement",
Expand Down
8 changes: 2 additions & 6 deletions locales/en/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
"deviceSimulatorExpressExtension.commands.common.openSerialMonitor": "Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.common.selectSerialPort": "Select Serial Port",
"deviceSimulatorExpressExtension.commands.common.deployToDevice": "Deploy to Device",
"deviceSimulatorExpressExtension.commands.cpx.openSimulator": "[Circuit Playground Express] Open Simulator",
"deviceSimulatorExpressExtension.commands.cpx.newFile": "[Circuit Playground Express] New File",
"deviceSimulatorExpressExtension.commands.microbit.openSimulator": "[micro:bit] Open Simulator",
"deviceSimulatorExpressExtension.commands.microbit.newFile": "[micro:bit] New File",
"deviceSimulatorExpressExtension.commands.clue.openSimulator": "[Clue] Open Simulator",
"deviceSimulatorExpressExtension.commands.clue.newFile": "[Clue] New File",
"deviceSimulatorExpressExtension.commands.common.openSimulator": "Open Simulator",
"deviceSimulatorExpressExtension.commands.common.newFile": "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.",
Expand Down
38 changes: 7 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@
"onCommand:deviceSimulatorExpress.common.selectSerialPort",
"onCommand:deviceSimulatorExpress.common.gettingStarted",
"onCommand:deviceSimulatorExpress.common.deployToDevice",
"onCommand:deviceSimulatorExpress.cpx.newFile",
"onCommand:deviceSimulatorExpress.cpx.openSimulator",
"onCommand:deviceSimulatorExpress.microbit.newFile",
"onCommand:deviceSimulatorExpress.microbit.openSimulator",
"onCommand:deviceSimulatorExpress.clue.newFile",
"onCommand:deviceSimulatorExpress.clue.openSimulator",
"onCommand:deviceSimulatorExpress.common.newFile",
"onCommand:deviceSimulatorExpress.common.openSimulator",
"onDebug"
],
"main": "./out/extension.js",
Expand Down Expand Up @@ -88,33 +84,13 @@
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.newFile",
"title": "%deviceSimulatorExpressExtension.commands.cpx.newFile%",
"command": "deviceSimulatorExpress.common.newFile",
"title": "%deviceSimulatorExpressExtension.commands.common.newFile%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.cpx.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.cpx.openSimulator%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.microbit.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.microbit.openSimulator%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.microbit.newFile",
"title": "%deviceSimulatorExpressExtension.commands.microbit.newFile%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.clue.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.clue.openSimulator%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
},
{
"command": "deviceSimulatorExpress.clue.newFile",
"title": "%deviceSimulatorExpressExtension.commands.clue.newFile%",
"command": "deviceSimulatorExpress.common.openSimulator",
"title": "%deviceSimulatorExpressExtension.commands.common.openSimulator%",
"category": "%deviceSimulatorExpressExtension.commands.common.label%"
}
],
Expand Down Expand Up @@ -348,4 +324,4 @@
"extensionDependencies": [
"ms-python.python"
]
}
}
Loading

0 comments on commit 7441dc5

Please sign in to comment.