2.1.28, initiation update to PXT v5.28.24 (#54)
This commit is contained in:
		
				
					committed by
					
						
						Peli de Halleux
					
				
			
			
				
	
			
			
			
						parent
						
							38a964516e
						
					
				
				
					commit
					5c114a0c57
				
			@@ -1,26 +0,0 @@
 | 
			
		||||
# microbit-chrome
 | 
			
		||||
Prototype chrome addon that exposes the micro:bit's serial output to webpages. 
 | 
			
		||||
* watch the [demo video](https://vimeo.com/146207766)
 | 
			
		||||
 | 
			
		||||
# Installation
 | 
			
		||||
See [developer.chrome.com](https://developer.chrome.com/extensions/getstarted#unpacked)
 | 
			
		||||
for instructions on how to install the local version into your chrome browser.
 | 
			
		||||
 | 
			
		||||
# Requirements
 | 
			
		||||
* Chrome 48 or later.
 | 
			
		||||
 | 
			
		||||
# Sample page
 | 
			
		||||
The `demo.html` webpage goes along with the
 | 
			
		||||
https://github.com/Microsoft/microbit-touchdevelop/blob/master/examples/tcs34725.cpp
 | 
			
		||||
program. Run `http-server` from this directory, then visit
 | 
			
		||||
http://localhost:8080/demo.html
 | 
			
		||||
(keep in mind that pages served from `file://` cannot open ports).
 | 
			
		||||
 | 
			
		||||
# Building
 | 
			
		||||
 | 
			
		||||
Open a command prompt and run the following commands.
 | 
			
		||||
 | 
			
		||||
````
 | 
			
		||||
npm install
 | 
			
		||||
typings update
 | 
			
		||||
````
 | 
			
		||||
@@ -1,67 +0,0 @@
 | 
			
		||||
var connections = [];
 | 
			
		||||
// A list of "ports", i.e. connected clients (such as web pages). Multiple web
 | 
			
		||||
// pages can connect to our service: they all receive the same data.
 | 
			
		||||
var ports = [];
 | 
			
		||||
function byPath(path) {
 | 
			
		||||
    return connections.filter(function (x) { return x.path == path; });
 | 
			
		||||
}
 | 
			
		||||
function byId(id) {
 | 
			
		||||
    return connections.filter(function (x) { return x.id == id; });
 | 
			
		||||
}
 | 
			
		||||
function onReceive(data, id) {
 | 
			
		||||
    if (ports.length == 0)
 | 
			
		||||
        return;
 | 
			
		||||
    var view = new DataView(data);
 | 
			
		||||
    var decoder = new TextDecoder("utf-8");
 | 
			
		||||
    var decodedString = decoder.decode(view);
 | 
			
		||||
    ports.forEach(function (port) { return port.postMessage({
 | 
			
		||||
        type: "serial",
 | 
			
		||||
        data: decodedString,
 | 
			
		||||
        id: id
 | 
			
		||||
    }); });
 | 
			
		||||
}
 | 
			
		||||
function findNewDevices() {
 | 
			
		||||
    chrome.serial.getDevices(function (serialPorts) {
 | 
			
		||||
        serialPorts.forEach(function (serialPort) {
 | 
			
		||||
            if (byPath(serialPort.path).length == 0 &&
 | 
			
		||||
                serialPort.displayName == "mbed Serial Port") {
 | 
			
		||||
                chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
 | 
			
		||||
                    // In case the [connect] operation takes more than five seconds...
 | 
			
		||||
                    if (info && byPath(serialPort.path).length == 0)
 | 
			
		||||
                        connections.push({
 | 
			
		||||
                            id: info.connectionId,
 | 
			
		||||
                            path: serialPort.path
 | 
			
		||||
                        });
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
function main() {
 | 
			
		||||
    // Register new clients in the [ports] global variable.
 | 
			
		||||
    chrome.runtime.onConnectExternal.addListener(function (port) {
 | 
			
		||||
        if (/^(micro:bit|touchdevelop|yelm|pxt|codemicrobit|codethemicrobit|pxt.microbit.org)$/.test(port.name)) {
 | 
			
		||||
            ports.push(port);
 | 
			
		||||
            port.onDisconnect.addListener(function () {
 | 
			
		||||
                ports = ports.filter(function (x) { return x != port; });
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
    // When receiving data for one of the connections that we're tracking, forward
 | 
			
		||||
    // it to all connected clients.
 | 
			
		||||
    chrome.serial.onReceive.addListener(function (info) {
 | 
			
		||||
        if (byId(info.connectionId).length > 0)
 | 
			
		||||
            onReceive(info.data, info.connectionId);
 | 
			
		||||
    });
 | 
			
		||||
    // When it looks like we've been disconnected, drop the corresponding
 | 
			
		||||
    // connection object from the [connections] global variable.
 | 
			
		||||
    chrome.serial.onReceiveError.addListener(function (info) {
 | 
			
		||||
        if (info.error == "system_error" || info.error == "disconnected" || info.error == "device_lost")
 | 
			
		||||
            connections = connections.filter(function (x) { return x.id != info.connectionId; });
 | 
			
		||||
    });
 | 
			
		||||
    // Probe serial connections at regular intervals. In case we find an mbed port
 | 
			
		||||
    // we haven't yet connected to, connect to it.
 | 
			
		||||
    setInterval(findNewDevices, 5000);
 | 
			
		||||
    findNewDevices();
 | 
			
		||||
}
 | 
			
		||||
document.addEventListener("DOMContentLoaded", main);
 | 
			
		||||
@@ -1,92 +0,0 @@
 | 
			
		||||
// A list of: {
 | 
			
		||||
//   id: number;
 | 
			
		||||
//   path: string;
 | 
			
		||||
// } where [id] is the [connectionId] (internal to Chrome) and [path] is the
 | 
			
		||||
// OS' name for the device (e.g. "COM4").
 | 
			
		||||
interface Connection {
 | 
			
		||||
  id: string;
 | 
			
		||||
  path: string;
 | 
			
		||||
}
 | 
			
		||||
let connections: Connection[] = [];
 | 
			
		||||
 | 
			
		||||
// A list of "ports", i.e. connected clients (such as web pages). Multiple web
 | 
			
		||||
// pages can connect to our service: they all receive the same data.
 | 
			
		||||
let ports = [];
 | 
			
		||||
 | 
			
		||||
interface Message {
 | 
			
		||||
  type: string;
 | 
			
		||||
  data: string;
 | 
			
		||||
  id: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function byPath(path: string): Connection[] {
 | 
			
		||||
  return connections.filter((x) => x.path == path);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function byId(id: string): Connection[] {
 | 
			
		||||
  return connections.filter((x) => x.id == id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function onReceive(data, id: string) {
 | 
			
		||||
  if (ports.length == 0) return;
 | 
			
		||||
 | 
			
		||||
  let view = new DataView(data);
 | 
			
		||||
  let decoder = new TextDecoder("utf-8");
 | 
			
		||||
  let decodedString = decoder.decode(view);
 | 
			
		||||
  ports.forEach(port => port.postMessage(<Message>{
 | 
			
		||||
    type: "serial",
 | 
			
		||||
    data: decodedString,
 | 
			
		||||
    id: id,
 | 
			
		||||
  }));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function findNewDevices() {
 | 
			
		||||
  chrome.serial.getDevices(function (serialPorts) {
 | 
			
		||||
    serialPorts.forEach(function (serialPort) {
 | 
			
		||||
      if (byPath(serialPort.path).length == 0 &&
 | 
			
		||||
        serialPort.displayName == "mbed Serial Port") {
 | 
			
		||||
        chrome.serial.connect(serialPort.path, { bitrate: 115200 }, function (info) {
 | 
			
		||||
          // In case the [connect] operation takes more than five seconds...
 | 
			
		||||
          if (info && byPath(serialPort.path).length == 0)
 | 
			
		||||
            connections.push({
 | 
			
		||||
              id: info.connectionId,
 | 
			
		||||
              path: serialPort.path
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function main() {
 | 
			
		||||
  // Register new clients in the [ports] global variable.
 | 
			
		||||
  chrome.runtime.onConnectExternal.addListener(function (port) {
 | 
			
		||||
    if (/^(micro:bit|touchdevelop|yelm|pxt|codemicrobit|codethemicrobit|pxt.microbit.org)$/.test(port.name)) {
 | 
			
		||||
      ports.push(port);
 | 
			
		||||
      port.onDisconnect.addListener(function () {
 | 
			
		||||
        ports = ports.filter(function (x) { return x != port });
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  // When receiving data for one of the connections that we're tracking, forward
 | 
			
		||||
  // it to all connected clients.
 | 
			
		||||
  chrome.serial.onReceive.addListener(function (info) {
 | 
			
		||||
    if (byId(info.connectionId).length > 0)
 | 
			
		||||
      onReceive(info.data, info.connectionId);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  // When it looks like we've been disconnected, drop the corresponding
 | 
			
		||||
  // connection object from the [connections] global variable.
 | 
			
		||||
  chrome.serial.onReceiveError.addListener(function (info) {
 | 
			
		||||
    if (info.error == "system_error" || info.error == "disconnected" || info.error == "device_lost")
 | 
			
		||||
      connections = connections.filter((x) => x.id != info.connectionId);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  // Probe serial connections at regular intervals. In case we find an mbed port
 | 
			
		||||
  // we haven't yet connected to, connect to it.
 | 
			
		||||
  setInterval(findNewDevices, 5000);
 | 
			
		||||
  findNewDevices();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
document.addEventListener("DOMContentLoaded", main);
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 2.6 KiB  | 
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 2.6 KiB  | 
@@ -1,30 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
  "app": {
 | 
			
		||||
    "background": {
 | 
			
		||||
      "scripts": [ "background.js" ]
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  "manifest_version": 2,
 | 
			
		||||
  "name": "pxt.microbit.org",
 | 
			
		||||
  "version": "0.7.0",
 | 
			
		||||
  "author": "Microsoft Corporation",
 | 
			
		||||
  "short_name": "pxt.microbit.org",
 | 
			
		||||
 | 
			
		||||
  "description": "Extension for https://pxt.microbit.org.",
 | 
			
		||||
  "homepage_url": "https://pxt.microbit.org",
 | 
			
		||||
  "offline_enabled": "true",
 | 
			
		||||
  "icons": {
 | 
			
		||||
    "48": "logo48.png",
 | 
			
		||||
    "128": "logo128.png"
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  "permissions": [
 | 
			
		||||
    "serial",
 | 
			
		||||
    "usb"
 | 
			
		||||
  ],
 | 
			
		||||
 | 
			
		||||
  "externally_connectable": {
 | 
			
		||||
    "matches": [ "*://localhost/*", "https://pxt.microbit.org/*", "https://*.microbit.org/*" ]
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 138 KiB  | 
@@ -1,7 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
    "compiler-options": {
 | 
			
		||||
        "target": "ES5",
 | 
			
		||||
        "module": "amd",
 | 
			
		||||
        "sourceMap": false
 | 
			
		||||
    }
 | 
			
		||||
 }
 | 
			
		||||
							
								
								
									
										2
									
								
								clients/electron/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								clients/electron/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,2 +0,0 @@
 | 
			
		||||
node_modules
 | 
			
		||||
projects
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
# 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`.
 | 
			
		||||
@@ -1,15 +0,0 @@
 | 
			
		||||
<!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>
 | 
			
		||||
@@ -1,39 +0,0 @@
 | 
			
		||||
const {app, BrowserWindow, Menu} = require('electron')
 | 
			
		||||
const pxt = require('pxt-core')
 | 
			
		||||
const path = require('path')
 | 
			
		||||
 | 
			
		||||
let win
 | 
			
		||||
 | 
			
		||||
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"
 | 
			
		||||
  })
 | 
			
		||||
  Menu.setApplicationMenu(null)
 | 
			
		||||
  win.loadURL(`file://${__dirname}/index.html#local_token=${pxt.globalConfig.localToken}`)
 | 
			
		||||
  win.on('closed', () => {
 | 
			
		||||
    win = null
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
app.on('ready', startServerAndCreateWindow)
 | 
			
		||||
 | 
			
		||||
app.on('window-all-closed', () => {
 | 
			
		||||
  if (process.platform !== 'darwin') {
 | 
			
		||||
    app.quit()
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
app.on('activate', () => {
 | 
			
		||||
  if (win === null) {
 | 
			
		||||
    createWindow()
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
@@ -1,14 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
  "name"    : "code-the-microbit",
 | 
			
		||||
  "version" : "1.0.0",
 | 
			
		||||
  "description": "Blocks / Javascript editor",
 | 
			
		||||
  "author": "Microsoft",
 | 
			
		||||
  "main"    : "main.js",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
      "start": "node_modules/.bin/electron ."
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
      "electron": "*",
 | 
			
		||||
      "pxt-microbit": "*"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 37 KiB  | 
										
											Binary file not shown.
										
									
								
							@@ -124,7 +124,7 @@
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (void)launchEditor:(id)sender {
 | 
			
		||||
    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://pxt.microbit.org/"]];
 | 
			
		||||
    [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://makecode.microbit.org/"]];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
# micro:bit uploader for OS X
 | 
			
		||||
# @boardname@ uploader for OS X
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
This project is a clone of the [Windows
 | 
			
		||||
uploader](https://pxt.microbit.org/uploader), but for OS X. Once launched,
 | 
			
		||||
uploader](https://makecode.microbit.org/uploader), but for OS X. Once launched,
 | 
			
		||||
the app runs in your menu bar and will automatically deploy any HEX files to
 | 
			
		||||
your `micro:bit`. Like the Windows version, it is compatible with any browser
 | 
			
		||||
that can run [pxt.microbit.org](http://pxt.microbit.org).
 | 
			
		||||
your `@boardname@`. Like the Windows version, it is compatible with any browser
 | 
			
		||||
that can run @homeurl@.
 | 
			
		||||
 | 
			
		||||
## Install the built version
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@ namespace Microsoft.MicroBit
 | 
			
		||||
        private void openEditor()
 | 
			
		||||
        {
 | 
			
		||||
            // lanch editor
 | 
			
		||||
            try { Process.Start("https://pxt.microbit.org#uploader"); } catch (Exception) { }
 | 
			
		||||
            try { Process.Start("https://makecode.microbit.org#uploader"); } catch (Exception) { }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void initializeFileWatch()
 | 
			
		||||
@@ -236,7 +236,7 @@ namespace Microsoft.MicroBit
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                Process.Start("https://pxt.microbit.org/uploader");
 | 
			
		||||
                Process.Start("https://makecode.microbit.org/uploader");
 | 
			
		||||
            }
 | 
			
		||||
            catch (IOException) { }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user