This commit is contained in:
Brahma Giri Abhijith Chatra 2016-09-21 16:34:06 -07:00
commit c04ddbb459
22 changed files with 225 additions and 95 deletions

2
clients/electron/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
projects

View File

@ -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`.

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>code the micro:bit</title>
</head>
<body>
<webview id="webview" style="position:absolute; left:0; top:0; right:0; bottom:0"/>
<script>
const webview = document.getElementById("webview")
const url = `http://localhost:3232/${window.location.hash}`
webview.src = url
</script>
</body>
</html>

View File

@ -1,67 +1,39 @@
const electron = require('electron') const {app, BrowserWindow, Menu} = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
// pxt toolchain
const pxt = require('pxt-core') const pxt = require('pxt-core')
const path = require('path')
// Keep a global reference of the window object, if you don't, the window will let win
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow() { const cliPath = path.join(process.cwd(), "node_modules/pxt-microbit")
console.log('starting app...')
// Create the browser window. function startServerAndCreateWindow() {
mainWindow = new BrowserWindow({ pxt.mainCli(cliPath, ["serve", "-no-browser"])
width: 800, height: 600, createWindow()
webPreferences: { }
nodeIntegration: false,
} function createWindow () {
win = new BrowserWindow({
width: 800,
height: 600,
title: "code the micro:bit"
}) })
Menu.setApplicationMenu(null)
ts.pxt.Util.debug = true; win.loadURL(`file://${__dirname}/index.html#local_token=${pxt.globalConfig.localToken}`)
pxt.mainCli("C:/gh/pxt-microbit/clients/electron/node_modules/pxt-microbit", ["serve", "-just"]); win.on('closed', () => {
win = null
// 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
}) })
} }
// This method will be called when Electron has finished app.on('ready', startServerAndCreateWindow)
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed. app.on('window-all-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
if (process.platform !== 'darwin') { if (process.platform !== 'darwin') {
app.quit() app.quit()
} }
}) })
app.on('activate', function () { app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the if (win === null) {
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow() 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.

View File

@ -1,19 +1,14 @@
{ {
"name": "codethemicrobit", "name" : "code-the-microbit",
"version": "0.1.0", "version" : "1.0.0",
"description": "A Blocks / JavaScript editor for the micro:bit", "description": "Blocks / Javascript editor",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"author": "Microsoft", "author": "Microsoft",
"license": "MIT", "main" : "main.js",
"devDependencies": { "scripts": {
"electron-prebuilt": "^1.2.0" "start": "node_modules/.bin/electron ."
}, },
"dependencies": { "devDependencies": {
"typescript": "1.8.7", "electron": "*",
"pxt-core": "*",
"pxt-microbit": "*" "pxt-microbit": "*"
} }
} }

View File

@ -99,3 +99,6 @@ latest version of OS X then you'll be using the latest version of Safari.
* Click 'About Safari' * Click 'About Safari'
![](/static/configurations/safari-version.png) ![](/static/configurations/safari-version.png)
IT administrators should check which browser versions are supported
[here](/browsers/technical).

View File

@ -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 As you are using Linux, it is recommended that you use [Mozilla
Chrome. 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

View File

@ -1,6 +1,18 @@
# Unsupported configuration # Recommended browser for Mac
As you are using OS X, it is recommended that you use Safari. Alternatively, As you are using a Mac, it is recommended that you use [Safari][]. Alternatively,
Google Chrome and Mozilla Firefox are also supported. [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

View File

@ -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

View File

@ -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 We recommend [Microsoft Edge][edge] if you are running Windows 10, but users on
are running a version of Windows prior to Windows 10, you can use Internet Windows 7 or higher can use [Internet Explorer 11][ie] or recent versions of
Explorer 11. Alternatively, Google Chrome and Mozilla Firefox are also [Mozilla Firefox][firefox], [Google Chrome][chrome], or [Opera][opera].
supported.
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

View File

@ -21,6 +21,7 @@
### More questions? ### More questions?
* [Frequently Asked Question](/faq) * [Frequently Asked Question](/faq)
* [Embedding project](/share)
* [Help Translate](/translate) * [Help Translate](/translate)
* [Release notes](/release-notes) * [Release notes](/release-notes)

View File

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

27
docs/share.md Normal file
View File

@ -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
### ~

View File

@ -141,7 +141,6 @@ namespace radio {
*/ */
//% help=radio/received-number-at //% help=radio/received-number-at
//% weight=45 debug=true //% weight=45 debug=true
//% blockId=radio_datagram_received_number_at block="radio receive number|at %VALUE" blockGap=8
int receivedNumberAt(int index) { int receivedNumberAt(int index) {
if (radioEnable() != MICROBIT_OK) return 0; if (radioEnable() != MICROBIT_OK) return 0;
if (0 <= index && index < packet.length() / 4) { if (0 <= index && index < packet.length() / 4) {

View File

@ -46,8 +46,7 @@ declare namespace radio {
* @param index index of the number to read from 0 to 3. 1 eg * @param index index of the number to read from 0 to 3. 1 eg
*/ */
//% help=radio/received-number-at //% help=radio/received-number-at
//% weight=45 debug=true //% weight=45 debug=true shim=radio::receivedNumberAt
//% blockId=radio_datagram_received_number_at block="radio receive number|at %VALUE" blockGap=8 shim=radio::receivedNumberAt
function receivedNumberAt(index: number): number; function receivedNumberAt(index: number): number;
/** /**

View File

@ -8,6 +8,7 @@ namespace control {
* Returns the value of a C++ runtime constant * Returns the value of a C++ runtime constant
*/ */
//% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8 //% weight=2 weight=19 blockId="control_event_source_id" block="%id" blockGap=8
//% shim=TD_ID
export function eventSourceId(id: EventBusSource): number { export function eventSourceId(id: EventBusSource): number {
return id; return id;
} }
@ -15,6 +16,7 @@ namespace control {
* Returns the value of a C++ runtime constant * Returns the value of a C++ runtime constant
*/ */
//% weight=1 weight=19 blockId="control_event_value_id" block="%id" //% weight=1 weight=19 blockId="control_event_value_id" block="%id"
//% shim=TD_ID
export function eventValueId(id: EventBusValue): number { export function eventValueId(id: EventBusValue): number {
return id; return id;
} }

View File

@ -135,7 +135,7 @@ namespace music {
*/ */
//% help=music/play-tone weight=90 //% help=music/play-tone weight=90
//% blockId=device_play_note block="play|tone %note=device_note|for %duration=device_beat" icon="\uf025" blockGap=8 //% 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 { export function playTone(frequency: number, ms: number): void {
pins.analogSetPitchPin(AnalogPin.P0); pins.analogSetPitchPin(AnalogPin.P0);
pins.analogPitch(frequency, ms); pins.analogPitch(frequency, ms);
@ -147,7 +147,7 @@ namespace music {
*/ */
//% help=music/ring-tone weight=80 //% help=music/ring-tone weight=80
//% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8 //% blockId=device_ring block="ring tone (Hz)|%note=device_note" icon="\uf025" blockGap=8
//% parts="speaker" //% parts="headphone"
export function ringTone(frequency: number): void { export function ringTone(frequency: number): void {
pins.analogSetPitchPin(AnalogPin.P0); pins.analogSetPitchPin(AnalogPin.P0);
pins.analogPitch(frequency, 0); pins.analogPitch(frequency, 0);
@ -159,7 +159,7 @@ namespace music {
*/ */
//% help=music/rest weight=79 //% help=music/rest weight=79
//% blockId=device_rest block="rest(ms)|%duration=device_beat" //% blockId=device_rest block="rest(ms)|%duration=device_beat"
//% parts="speaker" //% parts="headphone"
export function rest(ms: number): void { export function rest(ms: number): void {
playTone(0, ms); playTone(0, ms);
} }
@ -171,7 +171,6 @@ namespace music {
*/ */
//% weight=50 help=music/note-frequency //% weight=50 help=music/note-frequency
//% blockId=device_note block="%note" //% blockId=device_note block="%note"
//% parts="speaker"
//% shim=TD_ID //% shim=TD_ID
export function noteFrequency(name: Note): number { export function noteFrequency(name: Note): number {
return name; return name;
@ -186,7 +185,6 @@ namespace music {
*/ */
//% help=music/beat weight=49 //% help=music/beat weight=49
//% blockId=device_beat block="%fraction|beat" //% blockId=device_beat block="%fraction|beat"
//% parts="speaker"
export function beat(fraction?: BeatFraction): number { export function beat(fraction?: BeatFraction): number {
init(); init();
if (fraction == null) fraction = BeatFraction.Whole; if (fraction == null) fraction = BeatFraction.Whole;
@ -203,7 +201,6 @@ namespace music {
*/ */
//% help=music/tempo weight=40 //% help=music/tempo weight=40
//% blockId=device_tempo block="tempo (bpm)" blockGap=8 //% blockId=device_tempo block="tempo (bpm)" blockGap=8
//% parts="speaker"
export function tempo(): number { export function tempo(): number {
init(); init();
return beatsPerMinute; return beatsPerMinute;
@ -215,7 +212,6 @@ namespace music {
*/ */
//% help=music/change-tempo weight=39 //% help=music/change-tempo weight=39
//% blockId=device_change_tempo block="change tempo by (bpm)|%value" blockGap=8 //% blockId=device_change_tempo block="change tempo by (bpm)|%value" blockGap=8
//% parts="speaker"
export function changeTempoBy(bpm: number): void { export function changeTempoBy(bpm: number): void {
init(); init();
setTempo(beatsPerMinute + bpm); setTempo(beatsPerMinute + bpm);
@ -227,7 +223,6 @@ namespace music {
*/ */
//% help=music/set-tempo weight=38 //% help=music/set-tempo weight=38
//% blockId=device_set_tempo block="set tempo to (bpm)|%value" //% blockId=device_set_tempo block="set tempo to (bpm)|%value"
//% parts="speaker"
export function setTempo(bpm: number): void { export function setTempo(bpm: number): void {
init(); init();
if (bpm > 0) { if (bpm > 0) {

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="142" height="180" viewBox="0 0 142 180"><rect ry=".3" rx="1" y="58.615" x="-8.878" height="23.571" width="17.143" transform="rotate(-45)" fill="#b3b3b3"/><rect ry=".3" rx="1" y="32.043" x="-8.878" height="23.571" width="17.143" transform="rotate(-45)" fill="#b3b3b3"/><path d="M.346 7.296c-.394.39-.31 4.797-.18 4.898l13.404 10.18c.117.12.337 4.76.73 4.368l5.506-5.56.01.01 6.51-6.444c.39-.392-4.25-.614-4.366-.73L11.777.612c-.1-.132-4.51-.215-4.898.18L4.087 3.636l-.01-.01-3.73 3.67z" fill="#b3b3b3"/><rect ry="6.85" rx="4.571" y="84.758" x="-20.128" height="75.571" width="39.643" transform="rotate(-45)"/><rect ry=".374" rx="1.038" y="29.442" x="-8.925" height="2.228" width="17.238" transform="rotate(-45)" fill="#fff"/><rect ry=".374" rx="1.038" y="55.939" x="-8.925" height="2.228" width="17.238" transform="rotate(-45)" fill="#fff"/><rect ry=".374" rx="1.038" y="82.392" x="-8.925" height="2.228" width="17.238" transform="rotate(-45)" fill="#fff"/><rect ry="2.317" rx="2.183" y="158.876" x="-9.774" height="25.568" width="18.935" transform="rotate(-45)"/><path d="M128.588 128.82s14.97 11.165 7.547 26.35c-8.426 17.24-25.57 20.653-25.57 20.653" fill="none" stroke="#000" stroke-width="6.6" stroke-linecap="round" stroke-linejoin="round"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -29,6 +29,7 @@
"buffer.cpp", "buffer.cpp",
"pxtparts.json", "pxtparts.json",
"parts/speaker.svg", "parts/speaker.svg",
"parts/headphone.svg",
"_locales/fr/microbit-jsdoc-strings.json" "_locales/fr/microbit-jsdoc-strings.json"
], ],
"public": true, "public": true,

View File

@ -101,10 +101,32 @@
{"pinIndices": [5, 6, 7, 8, 9]} {"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": { "speaker": {
"numberOfPins": 2, "numberOfPins": 2,
"visual": { "visual": {
"image": "/parts/speaker.svg", "image": "parts/speaker.svg",
"width": 500, "width": 500,
"height": 500, "height": 500,
"pinDistance": 70, "pinDistance": 70,

View File

@ -1,6 +1,6 @@
{ {
"name": "pxt-microbit", "name": "pxt-microbit",
"version": "0.4.11", "version": "0.4.15",
"description": "micro:bit target for PXT", "description": "micro:bit target for PXT",
"keywords": [ "keywords": [
"JavaScript", "JavaScript",
@ -29,6 +29,6 @@
"typescript": "^1.8.7" "typescript": "^1.8.7"
}, },
"dependencies": { "dependencies": {
"pxt-core": "0.4.13" "pxt-core": "0.4.21"
} }
} }

View File

@ -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 { namespace pxsim.bluetooth {
export function startIOPinService(): void { export function startIOPinService(): void {
// TODO // TODO