diff --git a/gulpfile.js b/gulpfile.js index 7bf6b6239..e2b15d39b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -40,6 +40,7 @@ const pythonToMove = [ "./src/*.py", "./src/common/*.py", "./src/requirements.txt", + "./src/templates/*.*" ]; gulp.task("python-compile", () => { diff --git a/package.json b/package.json index 6ec86ed53..ca902a0eb 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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%" }, { diff --git a/package.nls.json b/package.nls.json index 49d2906a0..ac75ddbe3 100644 --- a/package.nls.json +++ b/package.nls.json @@ -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." +} diff --git a/src/constants.ts b/src/constants.ts index 495fe0c04..7da1b990a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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", diff --git a/src/extension.ts b/src/extension.ts index b65a648e1..d22686a7a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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, @@ -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 ); } @@ -912,7 +931,8 @@ export async function activate(context: vscode.ExtensionContext) { closeSerialMonitor, openSerialMonitor, openSimulator, - newFile, + newFileCPX, + newFileMicrobit, runSimulator, runSimulatorEditorButton, runDevice, diff --git a/src/template.py b/src/templates/cpx_template.py similarity index 81% rename from src/template.py rename to src/templates/cpx_template.py index b32caaae0..3c118c7e9 100644 --- a/src/template.py +++ b/src/templates/cpx_template.py @@ -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 diff --git a/src/templates/microbit_template.py b/src/templates/microbit_template.py new file mode 100644 index 000000000..88becabfe --- /dev/null +++ b/src/templates/microbit_template.py @@ -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!") \ No newline at end of file