diff --git a/clients/electron/.gitignore b/clients/electron/.gitignore new file mode 100644 index 00000000..ccedfdac --- /dev/null +++ b/clients/electron/.gitignore @@ -0,0 +1,2 @@ +node_modules +projects \ No newline at end of file diff --git a/clients/electron/README.md b/clients/electron/README.md new file mode 100644 index 00000000..f0aae8bb --- /dev/null +++ b/clients/electron/README.md @@ -0,0 +1,5 @@ +# PXT micro:bit Electron app + +A very basic wrapper around the web app. To install, copy the contents of this +directory to somewhere outside the main `pxt-microbit` repository. Then run `npm +install && npm start`. diff --git a/clients/electron/index.html b/clients/electron/index.html new file mode 100644 index 00000000..260b1839 --- /dev/null +++ b/clients/electron/index.html @@ -0,0 +1,15 @@ + + + + + code the micro:bit + + + + + + diff --git a/clients/electron/main.js b/clients/electron/main.js index e93a653b..58bba12e 100644 --- a/clients/electron/main.js +++ b/clients/electron/main.js @@ -1,67 +1,39 @@ -const electron = require('electron') -// Module to control application life. -const app = electron.app -// Module to create native browser window. -const BrowserWindow = electron.BrowserWindow -// pxt toolchain +const {app, BrowserWindow, Menu} = require('electron') const pxt = require('pxt-core') +const path = require('path') -// Keep a global reference of the window object, if you don't, the window will -// be closed automatically when the JavaScript object is garbage collected. -let mainWindow +let win -function createWindow() { - console.log('starting app...') - // Create the browser window. - mainWindow = new BrowserWindow({ - width: 800, height: 600, - webPreferences: { - nodeIntegration: false, - } +const cliPath = path.join(process.cwd(), "node_modules/pxt-microbit") + +function startServerAndCreateWindow() { + pxt.mainCli(cliPath, ["serve", "-no-browser"]) + createWindow() +} + +function createWindow () { + win = new BrowserWindow({ + width: 800, + height: 600, + title: "code the micro:bit" }) - - ts.pxt.Util.debug = true; - pxt.mainCli("C:/gh/pxt-microbit/clients/electron/node_modules/pxt-microbit", ["serve", "-just"]); - - // no menu - mainWindow.setMenu(null); - - // and load the index.html of the app. - mainWindow.loadURL(`http://localhost:3232/#local_token=08ba9b8f-6ccb-4202-296d-28fac7a553d9`) - - // Open the DevTools. - mainWindow.webContents.openDevTools() - - // Emitted when the window is closed. - mainWindow.on('closed', function () { - // Dereference the window object, usually you would store windows - // in an array if your app supports multi windows, this is the time - // when you should delete the corresponding element. - mainWindow = null + Menu.setApplicationMenu(null) + win.loadURL(`file://${__dirname}/index.html#local_token=${pxt.globalConfig.localToken}`) + win.on('closed', () => { + win = null }) } -// This method will be called when Electron has finished -// initialization and is ready to create browser windows. -// Some APIs can only be used after this event occurs. -app.on('ready', createWindow) +app.on('ready', startServerAndCreateWindow) -// Quit when all windows are closed. -app.on('window-all-closed', function () { - // On OS X it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q +app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) -app.on('activate', function () { - // On OS X it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (mainWindow === null) { +app.on('activate', () => { + if (win === null) { createWindow() } }) - -// In this file you can include the rest of your app's specific main process -// code. You can also put them in separate files and require them here. \ No newline at end of file diff --git a/clients/electron/package.json b/clients/electron/package.json index c5e949fe..f9633774 100644 --- a/clients/electron/package.json +++ b/clients/electron/package.json @@ -1,19 +1,14 @@ { - "name": "codethemicrobit", - "version": "0.1.0", - "description": "A Blocks / JavaScript editor for the micro:bit", - "main": "main.js", - "scripts": { - "start": "electron ." - }, + "name" : "code-the-microbit", + "version" : "1.0.0", + "description": "Blocks / Javascript editor", "author": "Microsoft", - "license": "MIT", - "devDependencies": { - "electron-prebuilt": "^1.2.0" + "main" : "main.js", + "scripts": { + "start": "node_modules/.bin/electron ." }, - "dependencies": { - "typescript": "1.8.7", - "pxt-core": "*", - "pxt-microbit": "*" + "devDependencies": { + "electron": "*", + "pxt-microbit": "*" } -} \ No newline at end of file +} diff --git a/docs/browsers.md b/docs/browsers.md index 3aeece82..e3ae501a 100644 --- a/docs/browsers.md +++ b/docs/browsers.md @@ -99,3 +99,6 @@ latest version of OS X then you'll be using the latest version of Safari. * Click 'About Safari' ![](/static/configurations/safari-version.png) + +IT administrators should check which browser versions are supported +[here](/browsers/technical). diff --git a/docs/browsers/linux.md b/docs/browsers/linux.md index 4f5d8bd3..87218dda 100644 --- a/docs/browsers/linux.md +++ b/docs/browsers/linux.md @@ -1,6 +1,16 @@ -# Unsupported configuration +# Recommended browser for Linux -As you are using Linux, it is recommended that you use Mozilla Firefox or Google -Chrome. +As you are using Linux, it is recommended that you use [Mozilla +Firefox][firefox] or [Google Chrome][chrome]. -Please see [here](/browsers) for more information. +Please see [here][technical] for technical information on which browsers are +supported, or [here][versions] to check which version you are using. + +[edge]: https://www.microsoft.com/en-us/windows/microsoft-edge +[ie]: https://www.microsoft.com/en-us/download/internet-explorer.aspx +[firefox]: https://www.mozilla.org/en-US/firefox/new/ +[chrome]: https://www.google.com/chrome/ +[opera]: https://www.opera.com +[safari]: http://www.apple.com/safari/ +[technical]: /browsers/technical +[versions]: /browsers diff --git a/docs/browsers/mac.md b/docs/browsers/mac.md index 61932f28..e0ed04b5 100644 --- a/docs/browsers/mac.md +++ b/docs/browsers/mac.md @@ -1,6 +1,18 @@ -# Unsupported configuration +# Recommended browser for Mac -As you are using OS X, it is recommended that you use Safari. Alternatively, -Google Chrome and Mozilla Firefox are also supported. +As you are using a Mac, it is recommended that you use [Safari][]. Alternatively, +[Google Chrome][chrome] and [Mozilla Firefox][firefox] are also supported. -Please see [here](/browsers) for more information. +You cannot use Safari in private browsing mode when using the editor. + +Please see [here][technical] for technical information on which browsers are +supported, or [here][versions] to check which version you are using. + +[edge]: https://www.microsoft.com/en-us/windows/microsoft-edge +[ie]: https://www.microsoft.com/en-us/download/internet-explorer.aspx +[firefox]: https://www.mozilla.org/en-US/firefox/new/ +[chrome]: https://www.google.com/chrome/ +[opera]: https://www.opera.com +[safari]: http://www.apple.com/safari/ +[technical]: /browsers/technical +[versions]: /browsers diff --git a/docs/browsers/technical.md b/docs/browsers/technical.md new file mode 100644 index 00000000..5dac2f0f --- /dev/null +++ b/docs/browsers/technical.md @@ -0,0 +1,36 @@ +# Technical information about browser support + +[codethemicrobit.com][] requires that you use a recent version of a modern +browser, such as Microsoft Edge, Google Chrome, Mozilla Firefox, Safari, Opera, +or IE11. This is because the editor uses modern web technologies such as [web +workers][] to enable compiling [TypeScript][] in the browser, or the using the +same [Monaco][] editor that powers [Visual Studio Code][]. + +[codethemicrobit.com]: https://codethemicrobit.com +[web workers]: http://www.w3.org/TR/workers/ +[typescript]: http://www.typescriptlang.org +[monaco]: https://microsoft.github.io/monaco-editor/ +[visual studio code]: http://code.visualstudio.com + +Most modern browsers automatically update themselves, but in some environments +such as schools these automatic updates are disabled for security. **We +strongly recommend that you use the most recent version of any of these +browsers**, but if you can't then you must use at least: + +| Browser | Minimum version | Release date | Windows | Mac | +| ----------------- | --------------- | -------------- | ----------- | ---------- | +| Edge | 12 | March 2015 | Windows 10+ | N/A | +| Internet Explorer | 11 | October 2013 | Windows 7+ | N/A | +| Mozilla Firefox | 31 ESR | July 2014 | Windows XP+ | OS X 10.6+ | +| Google Chrome | 38 | October 2014 | Windows XP+ | OS X 10.6+ | +| Safari | 9 | September 2015 | N/A | OS X 10.9+ | +| Opera | 21 | May 2014 | Windows 7+ | OS X 10.9+ | + + +Please see our information for which browsers are recommended for [Windows][], +[Mac][], [Linux][], or [Raspberry Pi][]. + +[Windows]: /browsers/windows +[Mac]: /browsers/mac +[Linux]: /browsers/linux +[Raspberry Pi]: /raspberry-pi diff --git a/docs/browsers/windows.md b/docs/browsers/windows.md index 386b65c7..6996a04a 100644 --- a/docs/browsers/windows.md +++ b/docs/browsers/windows.md @@ -1,8 +1,18 @@ -# Unsupported configuration +# Recommended browser for Windows -As you are using Windows, it is recommended that you use Microsoft Edge. If you -are running a version of Windows prior to Windows 10, you can use Internet -Explorer 11. Alternatively, Google Chrome and Mozilla Firefox are also -supported. +We recommend [Microsoft Edge][edge] if you are running Windows 10, but users on +Windows 7 or higher can use [Internet Explorer 11][ie] or recent versions of +[Mozilla Firefox][firefox], [Google Chrome][chrome], or [Opera][opera]. -Please see [here](/browsers) for more information. + +Please see [here][technical] for technical information on which browsers are +supported, or [here][versions] to check which version you are using. + +[edge]: https://www.microsoft.com/en-us/windows/microsoft-edge +[ie]: https://www.microsoft.com/en-us/download/internet-explorer.aspx +[firefox]: https://www.mozilla.org/en-US/firefox/new/ +[chrome]: https://www.google.com/chrome/ +[opera]: https://www.opera.com +[safari]: http://www.apple.com/safari/ +[technical]: /browsers/technical +[versions]: /browsers diff --git a/docs/docs.md b/docs/docs.md index 5c3c848c..b2527bb7 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -21,6 +21,7 @@ ### More questions? * [Frequently Asked Question](/faq) +* [Embedding project](/share) * [Help Translate](/translate) * [Release notes](/release-notes) diff --git a/docs/faq.md b/docs/faq.md index 758bf860..74bb5828 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -18,7 +18,8 @@ to reopen your latest project. You can also open previous project stored locally The project source is also stored in each compiled ``.hex`` file. Drag and drop the ``.hex`` file into the web editor to load the project. -To share your project with others, you can use the **Embed** feature. It stores your project in the cloud and creates a URL that you can share with others. +To share your project with others, you can use the [Embed Project...](/share). +It stores your project in the cloud and creates a URL that you can share with others. If you are using [Visual Studio Code](/code), all your programs are stored as files on your computer and you can use your favorite source control system as needed. diff --git a/docs/share.md b/docs/share.md new file mode 100644 index 00000000..599a6eed --- /dev/null +++ b/docs/share.md @@ -0,0 +1,27 @@ +# Sharing your project + +Once you have a cool project, it is possible to save it in the cloud and share it or embed it to your web site. + +### Instructions + +* Click on **More...** then click **Embed Project...** +* Click on the **Publish** button + +The embed dialog will provide you with various options to embed your project in your web site. + +### Project URL + +This URL will point to a web page that contains that project. + +* see the "happy" project: https://codethemicrobit.com/pyirlbpsei + +### Embedding into a blog or web site + +* Copy the HTML and paste it into your HTML source. + + +### ~hint + +**Developers:** This page supports OEmbed as well + +### ~ diff --git a/libs/microbit-radio/radio.cpp b/libs/microbit-radio/radio.cpp index 83ff0eb9..7b4dac5a 100644 --- a/libs/microbit-radio/radio.cpp +++ b/libs/microbit-radio/radio.cpp @@ -141,7 +141,6 @@ namespace radio { */ //% help=radio/received-number-at //% weight=45 debug=true - //% blockId=radio_datagram_received_number_at block="radio receive number|at %VALUE" blockGap=8 int receivedNumberAt(int index) { if (radioEnable() != MICROBIT_OK) return 0; if (0 <= index && index < packet.length() / 4) { diff --git a/libs/microbit-radio/shims.d.ts b/libs/microbit-radio/shims.d.ts index 1d27d7b7..5a85fbff 100644 --- a/libs/microbit-radio/shims.d.ts +++ b/libs/microbit-radio/shims.d.ts @@ -46,8 +46,7 @@ declare namespace radio { * @param index index of the number to read from 0 to 3. 1 eg */ //% help=radio/received-number-at - //% weight=45 debug=true - //% blockId=radio_datagram_received_number_at block="radio receive number|at %VALUE" blockGap=8 shim=radio::receivedNumberAt + //% weight=45 debug=true shim=radio::receivedNumberAt function receivedNumberAt(index: number): number; /** diff --git a/libs/microbit/control.ts b/libs/microbit/control.ts index 7334212a..d6d14894 100644 --- a/libs/microbit/control.ts +++ b/libs/microbit/control.ts @@ -8,6 +8,7 @@ namespace control { * Returns the value of a C++ runtime constant */ //% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8 + //% shim=TD_ID export function eventSourceId(id: EventBusSource): number { return id; } @@ -15,6 +16,7 @@ namespace control { * Returns the value of a C++ runtime constant */ //% weight=1 weight=19 blockId="control_event_value_id" block="%id" + //% shim=TD_ID export function eventValueId(id: EventBusValue): number { return id; } diff --git a/libs/microbit/music.ts b/libs/microbit/music.ts index 75709fa5..2a87e741 100644 --- a/libs/microbit/music.ts +++ b/libs/microbit/music.ts @@ -135,7 +135,7 @@ namespace music { */ //% help=music/play-tone weight=90 //% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8 - //% parts="speaker" + //% parts="headphone" export function playTone(frequency: number, ms: number): void { pins.analogSetPitchPin(AnalogPin.P0); pins.analogPitch(frequency, ms); @@ -147,7 +147,7 @@ namespace music { */ //% help=music/ring-tone weight=80 //% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8 - //% parts="speaker" + //% parts="headphone" export function ringTone(frequency: number): void { pins.analogSetPitchPin(AnalogPin.P0); pins.analogPitch(frequency, 0); @@ -159,7 +159,7 @@ namespace music { */ //% help=music/rest weight=79 //% blockId=device_rest block="rest(ms)|%duration=device_beat" - //% parts="speaker" + //% parts="headphone" export function rest(ms: number): void { playTone(0, ms); } @@ -171,7 +171,6 @@ namespace music { */ //% weight=50 help=music/note-frequency //% blockId=device_note block="%note" - //% parts="speaker" //% shim=TD_ID export function noteFrequency(name: Note): number { return name; @@ -186,7 +185,6 @@ namespace music { */ //% help=music/beat weight=49 //% blockId=device_beat block="%fraction|beat" - //% parts="speaker" export function beat(fraction?: BeatFraction): number { init(); if (fraction == null) fraction = BeatFraction.Whole; @@ -203,7 +201,6 @@ namespace music { */ //% help=music/tempo weight=40 //% blockId=device_tempo block="tempo (bpm)" blockGap=8 - //% parts="speaker" export function tempo(): number { init(); return beatsPerMinute; @@ -215,7 +212,6 @@ namespace music { */ //% help=music/change-tempo weight=39 //% blockId=device_change_tempo block="change tempo by (bpm)|%value" blockGap=8 - //% parts="speaker" export function changeTempoBy(bpm: number): void { init(); setTempo(beatsPerMinute + bpm); @@ -227,7 +223,6 @@ namespace music { */ //% help=music/set-tempo weight=38 //% blockId=device_set_tempo block="set tempo to (bpm)|%value" - //% parts="speaker" export function setTempo(bpm: number): void { init(); if (bpm > 0) { diff --git a/libs/microbit/parts/headphone.svg b/libs/microbit/parts/headphone.svg new file mode 100644 index 00000000..fa4fc1e0 --- /dev/null +++ b/libs/microbit/parts/headphone.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/libs/microbit/pxt.json b/libs/microbit/pxt.json index d7b15adb..be53b812 100644 --- a/libs/microbit/pxt.json +++ b/libs/microbit/pxt.json @@ -29,6 +29,7 @@ "buffer.cpp", "pxtparts.json", "parts/speaker.svg", + "parts/headphone.svg", "_locales/fr/microbit-jsdoc-strings.json" ], "public": true, diff --git a/libs/microbit/pxtparts.json b/libs/microbit/pxtparts.json index 63cf9a5e..4afc3f78 100644 --- a/libs/microbit/pxtparts.json +++ b/libs/microbit/pxtparts.json @@ -101,10 +101,32 @@ {"pinIndices": [5, 6, 7, 8, 9]} ] }, + "headphone": { + "numberOfPins": 2, + "visual": { + "image": "parts/headphone.svg", + "width": 142, + "height": 180, + "pinDistance": 20, + "pinLocations": [ + {"x": 17, "y": 11}, + {"x": 55, "y": 50} + ] + }, + "pinDefinitions": [ + {"target": "P0", "style": "croc", "orientation": "Y"}, + {"target": "ground", "style": "croc", "orientation": "Y"} + ], + "instantiation": {"kind": "singleton"}, + "assembly": [ + {"part": true, "pinIndices": [0]}, + {"pinIndices": [1]} + ] + }, "speaker": { "numberOfPins": 2, "visual": { - "image": "/parts/speaker.svg", + "image": "parts/speaker.svg", "width": 500, "height": 500, "pinDistance": 70, diff --git a/package.json b/package.json index 4837821f..283f124f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.4.11", + "version": "0.4.15", "description": "micro:bit target for PXT", "keywords": [ "JavaScript", @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.4.13" + "pxt-core": "0.4.21" } } diff --git a/sim/state/misc.ts b/sim/state/misc.ts index 5a271efe..96f3700a 100644 --- a/sim/state/misc.ts +++ b/sim/state/misc.ts @@ -116,6 +116,28 @@ namespace pxsim.pins { } } +namespace pxsim.devices { + export function tellCameraTo(action: number) { + // TODO + } + export function tellRemoteControlTo(action: number) { + // TODO + } + export function raiseAlertTo(action: number) { + // TODO + } + export function onSignalStrengthChanged(action: number) { + // TODO + } + export function signalStrength() : number { + // TODO + return 0; + } + export function onGamepadButton(button: number, body: RefAction) { + // TODO + } +} + namespace pxsim.bluetooth { export function startIOPinService(): void { // TODO