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

Commit

Permalink
first comimt
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandy Liu committed Feb 11, 2020
1 parent 8e1afe9 commit f621753
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 44 deletions.
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const pythonToMove = [
"./src/*.py",
"./src/common/*.py",
"./src/requirements.txt",
"./src/templates/*.*"
];

gulp.task("python-compile", () => {
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"onCommand:deviceSimulatorExpress.openSerialMonitor",
"onCommand:deviceSimulatorExpress.openSimulator",
"onCommand:deviceSimulatorExpress.runSimulator",
"onCommand:deviceSimulatorExpress.newFile",
"onCommand:deviceSimulatorExpress.newFileCPX",
"onCommand:deviceSimulatorExpress.newFileMicrobit",
"onCommand:deviceSimulatorExpress.runDevice",
"onCommand:deviceSimulatorExpress.runSimulatorEditorButton",
"onCommand:deviceSimulatorExpress.selectSerialPort",
Expand Down Expand Up @@ -79,8 +80,13 @@
}
},
{
"command": "deviceSimulatorExpress.newFile",
"title": "%deviceSimulatorExpressExtension.commands.newFile%",
"command": "deviceSimulatorExpress.newFileCPX",
"title": "%deviceSimulatorExpressExtension.commands.newFileCPX%",
"category": "%deviceSimulatorExpressExtension.commands.label%"
},
{
"command": "deviceSimulatorExpress.newFileMicrobit",
"title": "%deviceSimulatorExpressExtension.commands.newFileMicrobit%",
"category": "%deviceSimulatorExpressExtension.commands.label%"
},
{
Expand Down
33 changes: 17 additions & 16 deletions package.nls.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"deviceSimulatorExpressExtension.commands.changeBaudRate": "Change Baud Rate",
"deviceSimulatorExpressExtension.commands.closeSerialMonitor": "Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.label": "Device Simulator Express",
"deviceSimulatorExpressExtension.commands.openSerialMonitor": "Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.openSimulator": "Open Simulator",
"deviceSimulatorExpressExtension.commands.runSimulator": "Run Simulator",
"deviceSimulatorExpressExtension.commands.newFile": "New File",
"deviceSimulatorExpressExtension.commands.runDevice": "Deploy to Device",
"deviceSimulatorExpressExtension.commands.selectSerialPort": "Select Serial Port",
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
"deviceSimulatorExpressExtension.configuration.properties.open": "Whether to show 'Open Simulator' icon in editor title menu.",
"deviceSimulatorExpressExtension.configuration.properties.device": "Whether to show 'Run Device' icon in editor title menu.",
"deviceSimulatorExpressExtension.configuration.properties.simulator": "Whether to show 'Run Simulator' icon in editor title menu.",
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger."
}
{
"deviceSimulatorExpressExtension.commands.changeBaudRate": "Change Baud Rate",
"deviceSimulatorExpressExtension.commands.closeSerialMonitor": "Close Serial Monitor",
"deviceSimulatorExpressExtension.commands.label": "Device Simulator Express",
"deviceSimulatorExpressExtension.commands.openSerialMonitor": "Open Serial Monitor",
"deviceSimulatorExpressExtension.commands.openSimulator": "Open Simulator",
"deviceSimulatorExpressExtension.commands.runSimulator": "Run Simulator",
"deviceSimulatorExpressExtension.commands.newFileCPX": "New Circuit Playground Express File",
"deviceSimulatorExpressExtension.commands.newFileMicrobit": "New micro:bit File",
"deviceSimulatorExpressExtension.commands.runDevice": "Deploy to Device",
"deviceSimulatorExpressExtension.commands.selectSerialPort": "Select Serial Port",
"deviceSimulatorExpressExtension.configuration.title": "Device Simulator Express configuration",
"deviceSimulatorExpressExtension.configuration.properties.open": "Whether to show 'Open Simulator' icon in editor title menu.",
"deviceSimulatorExpressExtension.configuration.properties.device": "Whether to show 'Run Device' icon in editor title menu.",
"deviceSimulatorExpressExtension.configuration.properties.simulator": "Whether to show 'Run Simulator' icon in editor title menu.",
"deviceSimulatorExpressExtension.configuration.properties.debuggerPort": "The port the Server will listen on for communication with the debugger."
}
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ export enum TelemetryEventName {

// Extension commands
COMMAND_DEPLOY_DEVICE = "COMMAND.DEPLOY.DEVICE",
COMMAND_NEW_FILE = "COMMAND.NEW.FILE",
COMMAND_NEW_FILE_CPX = "COMMAND.NEW.FILE.CPX",
COMMAND_NEW_FILE_MICROBIT = "COMMAND.NEW.FILE.MICROBIT",
COMMAND_OPEN_SIMULATOR = "COMMAND.OPEN.SIMULATOR",
COMMAND_RUN_SIMULATOR_BUTTON = "COMMAND.RUN.SIMULATOR_BUTTON",
COMMAND_RUN_PALETTE = "COMMAND.RUN.PALETTE",
Expand Down
38 changes: 29 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,23 @@ export async function activate(context: vscode.ExtensionContext) {
}
);

const openTemplateFile = () => {
const fileName = "template.py";
const filePath = __dirname + path.sep + fileName;
const openCPXTemplateFile = () => {
openTemplateFile("cpx");
}

const openMicrobitTemplateFile = () => {
openTemplateFile("microbit");
}

const openTemplateFile = (device: string) => {
const fileName = `${device}_template.py`;
const filePath = __dirname + path.sep + "templates" + path.sep + fileName;
const file = fs.readFileSync(filePath, "utf8");
const showNewFilePopup: boolean = vscode.workspace
.getConfiguration()
.get(CONFIG.SHOW_NEW_FILE_POPUP);

if (showNewFilePopup) {
if (showNewFilePopup && device === "cpx") {
vscode.window
.showInformationMessage(
CONSTANTS.INFO.NEW_FILE,
Expand Down Expand Up @@ -344,12 +352,23 @@ export async function activate(context: vscode.ExtensionContext) {
};
};

const newFile: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.newFile",
const newFileCPX: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.newFileCPX",
() => {
telemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_NEW_FILE_CPX);
telemetryAI.runWithLatencyMeasure(
openCPXTemplateFile,
TelemetryEventName.PERFORMANCE_NEW_FILE
);
}
);

const newFileMicrobit: vscode.Disposable = vscode.commands.registerCommand(
"deviceSimulatorExpress.newFileMicrobit",
() => {
telemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_NEW_FILE);
telemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_NEW_FILE_MICROBIT);
telemetryAI.runWithLatencyMeasure(
openTemplateFile,
openMicrobitTemplateFile,
TelemetryEventName.PERFORMANCE_NEW_FILE
);
}
Expand Down Expand Up @@ -912,7 +931,8 @@ export async function activate(context: vscode.ExtensionContext) {
closeSerialMonitor,
openSerialMonitor,
openSimulator,
newFile,
newFileCPX,
newFileMicrobit,
runSimulator,
runSimulatorEditorButton,
runDevice,
Expand Down
31 changes: 16 additions & 15 deletions src/template.py → src/templates/cpx_template.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Save your file as "code.py" or "main.py" to run on the actual device.
Getting started with CPX and CircuitPython intro on:
https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library
Find example code for CPX on:
https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples
"""

# import CPX library
from adafruit_circuitplayground import cp

while True:
# start your code here
pass
"""
Save your file as "code.py" or "main.py" to run on the actual device.
Getting started with CPX and CircuitPython intro on:
https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/circuit-playground-express-library
Find example code for CPX on:
https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground/tree/master/examples
"""

# import CPX library
from adafruit_circuitplayground import cp

while True:
# start your code here
pass
9 changes: 9 additions & 0 deletions src/templates/microbit_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Get started with micro:bit and MicroPython on:
https://microbit-micropython.readthedocs.io/en/latest/.
"""

from microbit import *

while True:
display.scroll("Hello World!")

0 comments on commit f621753

Please sign in to comment.