Compare commits

...

81 Commits

Author SHA1 Message Date
47f1eadd27 0.6.37 2016-12-13 12:33:39 -08:00
8c06277a92 Bump pxt-core to 0.5.100 2016-12-13 12:33:37 -08:00
395f482f11 Merge pull request #322 from Microsoft/pr/monacotoolbox
Pr/monacotoolbox
2016-12-13 12:29:42 -08:00
bbd21a84d6 annotating apis to support toolbox 2016-12-13 12:14:32 -08:00
fcf680e9bd automatically detect/add missing package references in project 2016-12-12 10:42:02 -08:00
8ac848c812 Merge branch 'master' into pr/monacotoolbox 2016-12-12 08:39:45 +11:00
dd591af224 Turning flag for monaco toolbox on 2016-12-11 09:01:08 +13:00
e5a7a81198 Better monaco flyout contrast 2016-12-11 08:52:02 +13:00
7a5228a5d0 Reverting toolbox color 2016-12-11 06:52:08 +13:00
fe5c8e520a monaco draggable block 2016-12-11 06:34:11 +13:00
96d354a8a8 Merge pull request #316 from OwenBrotherwood/patch-1
Correction for max. length of advertised url to 17
2016-12-09 15:13:12 -08:00
02480b1c54 updated master to 0.6.36 2016-12-09 13:51:23 -08:00
4fd321cccf 0.6.36 2016-12-09 13:43:41 -08:00
4641c9456f Bump pxt-core to 0.5.99 2016-12-09 13:43:37 -08:00
498b5ec095 0.6.35 2016-12-09 11:57:34 -08:00
912be2ddfd Bump pxt-core to 0.5.98 2016-12-09 11:57:32 -08:00
6d7f8c5841 0.6.34 2016-12-09 11:15:51 -08:00
a782f4731a Bump pxt-core to 0.5.97 2016-12-09 11:15:48 -08:00
6e067bffd5 using built-deploy deployment features
deploy to drives has been migrated to PXT
2016-12-08 21:10:46 -08:00
4a4007ba41 fixing uploader link 2016-12-08 12:33:31 -08:00
c9db08a2c6 0.6.33 2016-12-08 12:18:56 -08:00
5ec303b95c Bump pxt-core to 0.5.96 2016-12-08 12:18:53 -08:00
3d0523a298 fix for roll/pitch in simulator.
fix for https://github.com/Microsoft/pxt/issues/893
2016-12-08 12:14:34 -08:00
3469ad6f8d Added note about protocol encoding. 2016-12-08 12:01:35 -08:00
d791738d84 fixing y values in accelerometer simulator
fix for https://github.com/Microsoft/pxt/issues/893
2016-12-08 11:57:17 -08:00
355c341d36 0.6.32 2016-12-08 10:56:49 -08:00
1adb4a2bac Bump pxt-core to 0.5.95 2016-12-08 10:56:46 -08:00
03c0339e9a fixing docs snippets 2016-12-08 09:16:27 -08:00
1649811015 expose "delete" in blocks.
fix for https://github.com/Microsoft/pxt/issues/870
2016-12-08 08:54:05 -08:00
14f16f9b2c expose game.setScore in blocks
fix for https://github.com/Microsoft/pxt/issues/881
2016-12-08 08:51:18 -08:00
66d3c6c7e8 fix for https://github.com/Microsoft/pxt/issues/549 2016-12-08 08:28:28 -08:00
7f27432222 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-12-08 00:12:49 -08:00
870b26a85a updated lessons to use radio 2016-12-08 00:10:00 -08:00
aa6cb58dca Merge pull request #320 from Microsoft/delete
Placement new occurances need explicit delete
2016-12-07 18:09:35 -08:00
6398a42dad Placement new occurances need explicit delete 2016-12-07 18:00:03 -08:00
cfc3eae77c adding monacotoolboxbuttons margin 2016-12-07 17:03:28 -08:00
438b745d32 Merge branch 'master' into pr/monacotoolbox 2016-12-07 17:02:07 -08:00
21473f5b9b Fixing array deallocation leak (#317)
* Fixing array deallocation leak

* Moving delete down to the individual destroy methods
2016-12-07 15:44:35 -08:00
c85b6f9507 using calibrated powers for Eddystone 2016-12-07 11:37:33 -08:00
019b00209e moving blocks to advanced 2016-12-07 09:49:19 -08:00
6c11dbcdf4 added setTransmitPower in BLE 2016-12-07 09:05:03 -08:00
91197c5cec updated BLE settings 2016-12-07 08:07:08 -08:00
9e5d9787c7 linking to pxt issue tracker 2016-12-06 21:51:51 -08:00
1c11a4823b adjusting the blockly flyout opacity. 2016-12-06 21:48:21 -08:00
d457c3e8d0 exposing delete in blocks 2016-12-06 16:19:35 -08:00
2ae21efb7b Moving blockly toolbox button margins to target. 2016-12-06 15:06:16 -08:00
30211aa006 Correction for max. length of advertised url to 17
https://github.com/google/eddystone/tree/master/eddystone-url#frame-specification states 1-17
When one makes a general google for the max length, some have written 18 and some 17 :(
The difference could lie in the https://github.com/google/eddystone/tree/master/eddystone-url#url-scheme-prefix which adds an extra byte but it's use is to in someway allow for more bytes in the 1-17.
The implementation in the micro:bit Lancaster is unknown as to how the url-scheme-prefix is or is not used: there does not seem to be a scheme for "Just take the 1-17" for the url.

At the moment, "play it safe" and write 17 ?
2016-12-06 20:51:44 +01:00
485a42758c 0.6.31 2016-12-06 11:32:24 -08:00
0da5a5a349 Bump pxt-core to 0.5.91 2016-12-06 11:32:22 -08:00
efca68672a Support for monaco toolbox 2016-12-06 00:34:42 -08:00
41ce2f66fa removing add package less variable 2016-12-05 23:55:46 -08:00
9393fc166e Styling add package and undo blockly buttons 2016-12-05 21:24:57 -08:00
cfb4382941 support for monaco toolbox 2016-12-05 19:01:14 -08:00
aaca24ff5b using add package color less variable 2016-12-05 18:09:23 -08:00
0ce9be1a2b removing toolbox right border. 2016-12-05 17:59:20 -08:00
a88eb7fe02 Changing main menu color, primary color and adding tiny borders around blockly toolbox 2016-12-05 17:30:04 -08:00
06e4f7fb5c Updated BLE project settings 2016-12-05 15:33:40 -08:00
1b36485208 0.6.30 2016-12-05 15:10:13 -08:00
3b54cefa95 Merge branch 'master' of https://github.com/Microsoft/pxt-microbit 2016-12-05 15:02:51 -08:00
52857c9541 added beacon configuration 2016-12-05 15:02:39 -08:00
d10c2a20bd More IE fixes. Using important to override blocky related CSS. 2016-12-05 13:43:57 -08:00
e2482cdf91 0.6.29 2016-12-05 13:22:06 -08:00
c045d87e4c Bump pxt-core to 0.5.90 2016-12-05 13:22:03 -08:00
34e23934b0 better bluetooth settings 2016-12-05 13:02:11 -08:00
354196e01e missing block annotation on led.enable 2016-12-05 09:17:42 -08:00
bb2e8d0aef 'devices' depends on 'bluetooth' 2016-12-05 09:05:54 -08:00
90f4e895d4 0.6.28 2016-12-03 23:22:42 -08:00
58c554caa6 Bump pxt-core to 0.5.88 2016-12-03 23:22:40 -08:00
6c688a7e59 Fix Edge / IE issue where the blockly toolbox background isn't respected. 2016-12-02 18:33:42 -08:00
71244065bb 0.6.27 2016-12-02 13:20:00 -08:00
bbb1bc3dd7 Merge pull request #314 from Microsoft/pr/theming
Theming the microbit target
2016-12-02 13:18:10 -08:00
806d0e2cff 0.6.26 2016-12-02 12:58:15 -08:00
e0c4af1cae Bump pxt-core to 0.5.87 2016-12-02 12:58:13 -08:00
475821564e fixing justworks support 2016-12-02 09:45:59 -08:00
9d65dd605b Monaco editor theming. 2016-12-01 22:05:37 -08:00
67eec44411 Minor fixes. 2016-12-01 21:58:16 -08:00
280b555f86 Theming the microbit target 2016-12-01 18:35:10 -08:00
2fcd32de0d 0.6.25 2016-11-30 23:36:40 -08:00
78694e86a2 0.6.24 2016-11-30 16:07:34 -08:00
aeaa3d7bc1 updated localization files 2016-11-30 16:07:04 -08:00
af8ce3fccf allow for double, breve note durations 2016-11-30 16:06:17 -08:00
38 changed files with 628 additions and 318 deletions

View File

@ -7,6 +7,10 @@ PXT ([Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt
[![Build Status](https://travis-ci.org/Microsoft/pxt-microbit.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-microbit) [![Build Status](https://travis-ci.org/Microsoft/pxt-microbit.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-microbit)
## Issue tracking
All issue tracking for this repo happens at https://github.com/Microsoft/pxt, see you there!
## Local server ## Local server
The local server allows to run the editor and the documentation from your computer. The local server allows to run the editor and the documentation from your computer.

View File

@ -1,60 +0,0 @@
/// <reference path="../node_modules/pxt-core/typings/node/node.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtlib.d.ts" />
import * as fs from "fs";
import * as path from "path";
import * as child_process from "child_process";
let writeFileAsync: any = Promise.promisify(fs.writeFile)
let execAsync: (cmd: string, options?: { cwd?: string }) => Promise<Buffer> = Promise.promisify(child_process.exec)
let readDirAsync = Promise.promisify(fs.readdir)
export function deployCoreAsync(res: ts.pxtc.CompileResult) {
return getBitDrivesAsync()
.then(drives => {
if (drives.length == 0) {
console.log("cannot find any drives to deploy to");
return Promise.resolve(0);
}
console.log(`copy ${ts.pxtc.BINARY_HEX} to ` + drives.join(", "));
let writeHexFile = (filename: string) => {
return writeFileAsync(filename + ts.pxtc.BINARY_HEX, res.outfiles[ts.pxtc.BINARY_HEX])
.then(() => console.log("wrote hex file to " + filename));
};
return Promise.map(drives, d => writeHexFile(d))
.then(() => drives.length);
});
}
function getBitDrivesAsync(): Promise<string[]> {
if (process.platform == "win32") {
const rx = new RegExp("^([A-Z]:).* " + pxt.appTarget.compile.deployDrives)
return execAsync("wmic PATH Win32_LogicalDisk get DeviceID, VolumeName, FileSystem")
.then(buf => {
let res: string[] = []
buf.toString("utf8").split(/\n/).forEach(ln => {
let m = rx.exec(ln)
if (m) {
res.push(m[1] + "/")
}
})
return res
})
}
else if (process.platform == "darwin") {
const rx = new RegExp(pxt.appTarget.compile.deployDrives)
return readDirAsync("/Volumes")
.then(lst => lst.filter(s => rx.test(s)).map(s => "/Volumes/" + s + "/"))
} else if (process.platform == "linux") {
const rx = new RegExp(pxt.appTarget.compile.deployDrives)
const user = process.env["USER"]
return readDirAsync(`/media/${user}`)
.then(lst => lst.filter(s => rx.test(s)).map(s => `/media/${user}/${s}/`))
} else {
return Promise.resolve([])
}
}

View File

@ -1,3 +1,6 @@
/// <reference path="../node_modules/pxt-core/typings/node/node.d.ts"/>
/// <reference path="../node_modules/pxt-core/built/pxtlib.d.ts" />
import * as path from "path"; import * as path from "path";
export let pxtCore = require("pxt-core"); export let pxtCore = require("pxt-core");
// require.resolve() gives path to [pxt dir]/built/pxt.js, so move up twice to get pxt root dir // require.resolve() gives path to [pxt dir]/built/pxt.js, so move up twice to get pxt root dir

View File

@ -1,3 +1,3 @@
{ {
"appref": "v0.6.13" "appref": "v0.6.36"
} }

View File

@ -10,12 +10,10 @@ Welcome! This guided tutorial will show you how to program a script that display
### ~ ### ~
## Step 1 ## Step 1
Create a loop that will continuously update the reading of the compass. Create a loop that will continuously update the reading of the compass.
```blocks ```blocks
basic.forever(() => { basic.forever(() => {

View File

@ -2,8 +2,7 @@
### ~avatar avatar ### ~avatar avatar
Use the LEDs to display a flashing heart, and then create Use the LEDs to display a flashing heart!
an animation of a broken heart. :(
### ~ ### ~
@ -38,19 +37,19 @@ basic.clearScreen();
## Step 3 ## Step 3
Put a [forever loop](/reference/basic/forever) around it. Put a [forever loop](/reference/basic/forever) around it to repeat the animation.
```blocks ```blocks
basic.forever(() => { basic.forever(() => {
basic.showLeds(` basic.showLeds(`
. # . # . . # . # .
# # # # # # # # # #
# # # # # # # # # #
. # # # . . # # # .
. . # . .` . . # . .`
); );
basic.pause(500); basic.pause(500);
basic.clearScreen(); basic.clearScreen();
}) })
``` ```
@ -60,45 +59,50 @@ Add a [pause](/reference/basic/pause) to wait after clearing the screen.
```blocks ```blocks
basic.forever(() => { basic.forever(() => {
basic.showLeds(` basic.showLeds(`
. # . # . . # . # .
# # # # # # # # # #
# # # # # # # # # #
. # # # . . # # # .
. . # . .` . . # . .`
); );
basic.pause(500); basic.pause(500);
basic.clearScreen(); basic.clearScreen();
basic.pause(500); basic.pause(500);
}) })
``` ```
## Step 5 ## Send your heartbeats over radio!
Add a second image of a broken heart. Do you have a second @boardname@ at hand? You could use radio and send your heartbeats to other
@boardname@ and show a heart when you receive one.
* move the code in the **forever** inside
a [on data packet received](/reference/radio/on-data-packet-received) handler.
The handler will run whenever a message is received from another @boardname@.
* use [send number](/reference/radio/send-number) and [pause](/reference/basic/pause)
to broadcast a packet of data every second.
```blocks ```blocks
basic.forever(() => { basic.forever(() => {
basic.showLeds(` radio.sendNumber(0)
. # . # . basic.pause(1000)
# # # # # })
# # # # # radio.onDataPacketReceived(({receivedNumber}) => {
. # # # . basic.showLeds(`
. . # . .` . # . # .
); # # # # #
basic.pause(500); # # # # #
basic.clearScreen(); . # # # .
basic.pause(500); . . # . .`);
basic.showLeds(` basic.pause(500)
. # . # . basic.clearScreen()
# . # # # basic.pause(500)
# . . . #
. # # # .
. . # . .`
);
basic.pause(500);
basic.clearScreen();
basic.pause(500);
}) })
``` ```
Download the .hex file onto both @boardname@ and try it out!
```package
radio
```

View File

@ -12,8 +12,8 @@ Use [show leds](/reference/basic/show-leds) to make a smiley face:
```blocks ```blocks
basic.showLeds(` basic.showLeds(`
. # . # . # # . # #
. # . # . # # . # #
. . . . . . . . . .
# . . . # # . . . #
. # # # .` . # # # .`
@ -22,56 +22,93 @@ basic.showLeds(`
## Step 2 ## Step 2
Add an input block for when [button A is pressed](/reference/input/button-is-pressed), and put a Add an input block for when [button A is pressed](/reference/input/button-is-pressed),
frowny face inside it: and **move** the smiley face inside it:
```blocks ```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`
);
input.onButtonPressed(Button.A, () => { input.onButtonPressed(Button.A, () => {
basic.showLeds(` basic.showLeds(`
. # . # . # # . # #
. # . # . # # . # #
. . . . .
. # # # .
# . . . #`
);
});
```
## Step 3
Now add blocks so that when [button B is pressed](/reference/input/button-is-pressed), a smiley appears:
```blocks
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .`
);
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . .
. # # # .
# . . . #`
);
});
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
. # . # .
. # . # .
. . . . . . . . . .
# . . . # # . . . #
. # # # .` . # # # .`
); );
}); });
``` ```
Try pressing button A!
## Step 3
Now add blocks so that when [button B is pressed](/reference/input/on-button-pressed),
a frowney appears:
```blocks
input.onButtonPressed(Button.A, () => {
basic.showLeds(`
# # . # #
# # . # #
. . . . .
# . . . #
. # # # .`
);
});
input.onButtonPressed(Button.B, () => {
basic.showLeds(`
# # . # #
# # . # #
. . . . .
. # # # .
# . . . #`
);
});
```
Try pressing ``A`` or ``B``!
## Send your smileys over radio
Do you have a second @boardname@ at hand? You could use radio and send your smileys or frownies to other
@boardname@.
Since radio can send numbers, we decide that ``0`` is the code for displaying a smiley
and ``1`` is the code for a frowney.
Change your code as follows:
* [radio send number](/reference/radio/send-number) sends a number
to any other @boardname@ in range
* [radio on data packet received](/reference/radio/on-data-packet-received) runs code
when data is received over radio
```blocks
input.onButtonPressed(Button.A, () => {
radio.sendNumber(0)
})
input.onButtonPressed(Button.B, () => {
radio.sendNumber(1)
})
radio.onDataPacketReceived(({receivedNumber}) => {
if (receivedNumber == 0) {
basic.showLeds(`
# # . # #
# # . # #
. . . . .
# . . . #
. # # # .
`)
} else {
basic.showLeds(`
# # . # #
# # . # #
. . . . .
. # # # .
# . . . #
`)
}
})
```
```package
radio
```

View File

@ -19,6 +19,7 @@ bluetooth.startMagnetometerService();
bluetooth.startTemperatureService(); bluetooth.startTemperatureService();
bluetooth.onBluetoothConnected(() => {}); bluetooth.onBluetoothConnected(() => {});
bluetooth.onBluetoothDisconnected(() => {}); bluetooth.onBluetoothDisconnected(() => {});
bluetooth.setTransmitPower(7);
``` ```
## UART ## UART

View File

@ -18,18 +18,18 @@ Read more at https://lancaster-university.github.io/microbit-docs/ble/eddystone/
## ~ ## ~
```sig ```sig
bluetooth.advertiseUrl("https://pxt.microbit.org/", 7); bluetooth.advertiseUrl("https://pxt.microbit.org/", 7, true);
``` ```
### Parameters ### Parameters
* ``url`` - a [string](/reference/types/string) containing the URL to broadcast, at most 18 characters long * ``url`` - a [string](/reference/types/string) containing the URL to broadcast, at most 17 characters long, excluding the protocol (eg: ``https://``) which gets encoded as 1 byte.
* ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range). * ``power`` - a [number](/reference/types/number) representing the power level between 0 (short) and 7 (maximum range).
### Example: Broadcast a secret code ### Example: Broadcast a secret code
```blocks ```blocks
bluetooth.advertiseUrl("https://pxt.io?secret=42", 7); bluetooth.advertiseUrl("https://pxt.io?secret=42", 7, true);
``` ```
## See Also ## See Also
@ -38,4 +38,4 @@ bluetooth.advertiseUrl("https://pxt.io?secret=42", 7);
```package ```package
bluetooth bluetooth
``` ```

View File

@ -0,0 +1,26 @@
# Bluetooth Set Transmit Power
### ~hint
![](/static/bluetooth/Bluetooth_SIG.png)
For another device like a smartphone to use any of the Bluetooth "services" which the @boardname@ has, it must first be [paired with the @boardname@](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the @boardname@ and exchange data relating to many of the @boardname@'s features.
### ~
Change the output power level of the transmitter to the given value.
```sig
bluetooth.setTransmitPower(7);
```
### Parameters
* `power`: a [number](/reference/types/number) in the range ``0..7``, where ``0`` is the lowest power and ``7`` is the highest.
### See also
[About Bluetooth](/reference/bluetooth/about-bluetooth), [@boardname@ Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [@boardname@ Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on @boardname@ resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com)
```package
bluetooth
```

View File

@ -0,0 +1,28 @@
# Serial Read Until
Read a text from the serial port until a delimiter is found.
```sig
serial.readUntil(",");
```
### Returns
* a [string](/reference/types/string) containing input from the serial port, such as a response typed by a user
### Example
The following example reads strings separated by commands (``,``).
```blocks
basic.forever(() => {
let answer = serial.readUntil(",");
serial.writeLine(answer);
});
```
### See also
[serial](/device/serial),
[serial write line](/reference/serial/write-line),
[serial write value](/reference/serial/write-value)

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -38,7 +38,7 @@ That's it!
### Installation Instructions ### Installation Instructions
* Download the [Microsoft.Uploader.Microbit.zip](https://pxt.microbit.org/microbit-uploader.zip) file to your local computer. * Download the [Microsoft.Uploader.Microbit.zip](https://www.touchdevelop.com/microbituploader.zip) file to your local computer.
* Unzip the .zip file to your desktop. * Unzip the .zip file to your desktop.
* Launch the Microsoft.Uploader.exe file before working on your @boardname@. * Launch the Microsoft.Uploader.exe file before working on your @boardname@.

View File

@ -1,12 +1,15 @@
{ {
"bluetooth": "Support for additional Bluetooth services.", "bluetooth": "Support for additional Bluetooth services.",
"bluetooth.advertiseUrl": "Advertise an Eddystone URL", "bluetooth.advertiseUrl": "Advertise an Eddystone URL",
"bluetooth.advertiseUrl|param|power": "power level between 0 and 7, e.g.: 7", "bluetooth.advertiseUrl|param|connectable": "true to keep bluetooth connectable for other services, false otherwise.",
"bluetooth.advertiseUrl|param|url": "the url to transmit. Must be no longer than the supported eddystone url length", "bluetooth.advertiseUrl|param|power": "power level between 0 and 7, eg: 7",
"bluetooth.advertiseUrl|param|url": "the url to transmit. Must be no longer than the supported eddystone url length, eg: \"https://pxt.io/\"",
"bluetooth.onBluetoothConnected": "Register code to run when the micro:bit is connected to over Bluetooth", "bluetooth.onBluetoothConnected": "Register code to run when the micro:bit is connected to over Bluetooth",
"bluetooth.onBluetoothConnected|param|body": "Code to run when a Bluetooth connection is established", "bluetooth.onBluetoothConnected|param|body": "Code to run when a Bluetooth connection is established",
"bluetooth.onBluetoothDisconnected": "Register code to run when a bluetooth connection to the micro:bit is lost", "bluetooth.onBluetoothDisconnected": "Register code to run when a bluetooth connection to the micro:bit is lost",
"bluetooth.onBluetoothDisconnected|param|body": "Code to run when a Bluetooth connection is lost", "bluetooth.onBluetoothDisconnected|param|body": "Code to run when a Bluetooth connection is lost",
"bluetooth.setTransmitPower": "Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).",
"bluetooth.setTransmitPower|param|power": "power level between 0 (minimal) and 7 (maximum), eg: 7.",
"bluetooth.startAccelerometerService": "Starts the Bluetooth accelerometer service", "bluetooth.startAccelerometerService": "Starts the Bluetooth accelerometer service",
"bluetooth.startButtonService": "Starts the Bluetooth button service", "bluetooth.startButtonService": "Starts the Bluetooth button service",
"bluetooth.startIOPinService": "Starts the Bluetooth IO pin service.", "bluetooth.startIOPinService": "Starts the Bluetooth IO pin service.",

View File

@ -1,7 +1,8 @@
{ {
"bluetooth.advertiseUrl|block": "bluetooth advertise url %url|with power %power", "bluetooth.advertiseUrl|block": "bluetooth advertise url %url|with power %power|connectable %connectable",
"bluetooth.onBluetoothConnected|block": "on bluetooth connected", "bluetooth.onBluetoothConnected|block": "on bluetooth connected",
"bluetooth.onBluetoothDisconnected|block": "on bluetooth disconnected", "bluetooth.onBluetoothDisconnected|block": "on bluetooth disconnected",
"bluetooth.setTransmitPower|block": "bluetooth set transmit power %power",
"bluetooth.startAccelerometerService|block": "bluetooth accelerometer service", "bluetooth.startAccelerometerService|block": "bluetooth accelerometer service",
"bluetooth.startButtonService|block": "bluetooth button service", "bluetooth.startButtonService|block": "bluetooth button service",
"bluetooth.startIOPinService|block": "bluetooth io pin service", "bluetooth.startIOPinService|block": "bluetooth io pin service",

View File

@ -121,18 +121,30 @@ namespace bluetooth {
} }
const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10}; const int8_t CALIBRATED_POWERS[] = {-49, -37, -33, -28, -25, -20, -15, -10};
/** /**
* Advertise an Eddystone URL * Advertise an Eddystone URL
* @param url the url to transmit. Must be no longer than the supported eddystone url length * @param url the url to transmit. Must be no longer than the supported eddystone url length, eg: "https://pxt.io/"
* @param power power level between 0 and 7, e.g.: 7 * @param power power level between 0 and 7, eg: 7
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
*/ */
//% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power" //% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power|connectable %connectable"
//% parts=bluetooth weight=11 blockGap=8 //% parts=bluetooth weight=11 blockGap=8
//% help=bluetooth/advertise-url //% help=bluetooth/advertise-url blockExternalInputs=1
void advertiseUrl(StringData* url, int power) { void advertiseUrl(StringData* url, int power, bool connectable) {
int8_t level = CALIBRATED_POWERS[min(7, max(0, power))]; power = min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power));
uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level); int8_t level = CALIBRATED_POWERS[power];
uBit.bleManager.advertiseEddystoneUrl(ManagedString(url), level, connectable);
uBit.bleManager.setTransmitPower(power);
}
/**
* Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).
* @param power power level between 0 (minimal) and 7 (maximum), eg: 7.
*/
//% parts=bluetooth weight=5 help=bluetooth/set-transmit-power advanced=true
//% blockId=bluetooth_settransmitpower block="bluetooth set transmit power %power"
void setTransmitPower(int power) {
uBit.bleManager.setTransmitPower(min(MICROBIT_BLE_POWER_LEVELS-1, max(0, power)));
} }
/** /**
@ -140,7 +152,7 @@ namespace bluetooth {
*/ */
//% blockId=eddystone_stop_advertising block="bluetooth stop advertising" //% blockId=eddystone_stop_advertising block="bluetooth stop advertising"
//% parts=bluetooth weight=10 //% parts=bluetooth weight=10
//% help=bluetooth/stop-advertising //% help=bluetooth/stop-advertising advanced=true
void stopAdvertising() { void stopAdvertising() {
uBit.bleManager.stopAdvertising(); uBit.bleManager.stopAdvertising();
} }

View File

@ -24,7 +24,6 @@
"microbit-dal": { "microbit-dal": {
"bluetooth": { "bluetooth": {
"private_addressing": 0, "private_addressing": 0,
"whitelist": 1,
"advertising_timeout": 0, "advertising_timeout": 0,
"tx_power": 6, "tx_power": 6,
"dfu_service": 1, "dfu_service": 1,
@ -32,33 +31,49 @@
"device_info_service": 1, "device_info_service": 1,
"eddystone_url": 1, "eddystone_url": 1,
"eddystone_uid": 0, "eddystone_uid": 0,
"pairing_mode": 1,
"open": 0, "open": 0,
"security_level": "SECURITY_MODE_ENCRYPTION_WITH_MITM" "pairing_mode": 1,
"whitelist": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM"
} }
}, },
"gatt_table_size": "0x700" "gatt_table_size": "0x700"
}, },
"userConfigs": [ "userConfigs": [
{ {
"description": "No pairing: Anyone can connect via Bluetooth.", "description": "Unsecure: Anyone can connect via Bluetooth.",
"config": { "config": {
"microbit-dal": { "microbit-dal": {
"bluetooth": { "bluetooth": {
"open": 1, "open": 1,
"pairing_mode": null, "pairing_mode": 0,
"whitelist": 0,
"security_level": null "security_level": null
} }
} }
} }
}, },
{ {
"description": "Passkey pairing: Button press and 6 digit key to pair via Bluetooth.", "description": "JustWorks pairing (default): Button press to pair.",
"config": {
"microbit-dal": {
"bluetooth": {
"open": null,
"pairing_mode": null,
"whitelist": null,
"security_level": null
}
}
}
},
{
"description": "Passkey pairing: Button press and 6 digit key to pair.",
"config": { "config": {
"microbit-dal": { "microbit-dal": {
"bluetooth": { "bluetooth": {
"open": 0, "open": 0,
"pairing_mode": 1, "pairing_mode": 1,
"whitelist": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_WITH_MITM" "security_level": "SECURITY_MODE_ENCRYPTION_WITH_MITM"
} }
} }

View File

@ -83,20 +83,29 @@ declare namespace bluetooth {
/** /**
* Advertise an Eddystone URL * Advertise an Eddystone URL
* @param url the url to transmit. Must be no longer than the supported eddystone url length * @param url the url to transmit. Must be no longer than the supported eddystone url length, eg: "https://pxt.io/"
* @param power power level between 0 and 7, e.g.: 7 * @param power power level between 0 and 7, eg: 7
* @param connectable true to keep bluetooth connectable for other services, false otherwise.
*/ */
//% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power" //% blockId=eddystone_advertise_url block="bluetooth advertise url %url|with power %power|connectable %connectable"
//% parts=bluetooth weight=11 blockGap=8 //% parts=bluetooth weight=11 blockGap=8
//% help=bluetooth/advertise-url shim=bluetooth::advertiseUrl //% help=bluetooth/advertise-url blockExternalInputs=1 shim=bluetooth::advertiseUrl
function advertiseUrl(url: string, power: number): void; function advertiseUrl(url: string, power: number, connectable: boolean): void;
/**
* Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).
* @param power power level between 0 (minimal) and 7 (maximum), eg: 7.
*/
//% parts=bluetooth weight=5 help=bluetooth/set-transmit-power advanced=true
//% blockId=bluetooth_settransmitpower block="bluetooth set transmit power %power" shim=bluetooth::setTransmitPower
function setTransmitPower(power: number): void;
/** /**
* Stops advertising Eddystone end points * Stops advertising Eddystone end points
*/ */
//% blockId=eddystone_stop_advertising block="bluetooth stop advertising" //% blockId=eddystone_stop_advertising block="bluetooth stop advertising"
//% parts=bluetooth weight=10 //% parts=bluetooth weight=10
//% help=bluetooth/stop-advertising shim=bluetooth::stopAdvertising //% help=bluetooth/stop-advertising advanced=true shim=bluetooth::stopAdvertising
function stopAdvertising(): void; function stopAdvertising(): void;
} }

View File

@ -85,7 +85,7 @@
"game.setLife": "Sets the current life value", "game.setLife": "Sets the current life value",
"game.setLife|param|value": "TODO", "game.setLife|param|value": "TODO",
"game.setScore": "Sets the current score value", "game.setScore": "Sets the current score value",
"game.setScore|param|value": "TODO", "game.setScore|param|value": "new score value.",
"game.showScore": "Displays the score on the screen.", "game.showScore": "Displays the score on the screen.",
"game.startCountdown": "Starts a game countdown timer", "game.startCountdown": "Starts a game countdown timer",
"game.startCountdown|param|ms": "countdown duration in milliseconds, eg: 10000", "game.startCountdown|param|ms": "countdown duration in milliseconds, eg: 10000",
@ -97,26 +97,28 @@
"input.acceleration": "Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)", "input.acceleration": "Get the acceleration value in milli-gravitys (when the board is laying flat with the screen up, x=0, y=0 and z=-1024)",
"input.acceleration|param|dimension": "TODO", "input.acceleration|param|dimension": "TODO",
"input.buttonIsPressed": "Get the button state (pressed or not) for ``A`` and ``B``.", "input.buttonIsPressed": "Get the button state (pressed or not) for ``A`` and ``B``.",
"input.buttonIsPressed|param|button": "the button to query the request, eg: Button.A",
"input.calibrate": "Obsolete, compass calibration is automatic.", "input.calibrate": "Obsolete, compass calibration is automatic.",
"input.compassHeading": "Get the current compass heading in degrees.", "input.compassHeading": "Get the current compass heading in degrees.",
"input.lightLevel": "Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.", "input.lightLevel": "Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.",
"input.magneticForce": "Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.", "input.magneticForce": "Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.",
"input.magneticForce|param|dimension": "TODO", "input.magneticForce|param|dimension": "TODO",
"input.onButtonPressed": "Do something when a button (``A``, ``B`` or both ``A+B``) is pressed", "input.onButtonPressed": "Do something when a button (``A``, ``B`` or both ``A+B``) is pressed",
"input.onButtonPressed|param|body": "TODO", "input.onButtonPressed|param|body": "code to run when event is raised",
"input.onButtonPressed|param|button": "TODO", "input.onButtonPressed|param|button": "the button that needs to be pressed",
"input.onGesture": "Do something when when a gesture is done (like shaking the micro:bit).", "input.onGesture": "Do something when when a gesture is done (like shaking the micro:bit).",
"input.onGesture|param|body": "TODO", "input.onGesture|param|body": "code to run when gesture is raised",
"input.onGesture|param|gesture": "the type of gesture to track, eg: Gesture.Shake",
"input.onLogoDown": "Attaches code to run when the logo is oriented downwards and the board is vertical.", "input.onLogoDown": "Attaches code to run when the logo is oriented downwards and the board is vertical.",
"input.onLogoDown|param|body": "TODO", "input.onLogoDown|param|body": "TODO",
"input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.", "input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.",
"input.onLogoUp|param|body": "TODO", "input.onLogoUp|param|body": "TODO",
"input.onPinPressed": "Do something when a pin is pressed.", "input.onPinPressed": "Do something when a pin is pressed.",
"input.onPinPressed|param|body": "the code to run when the pin is pressed", "input.onPinPressed|param|body": "the code to run when the pin is pressed",
"input.onPinPressed|param|name": "the pin that needs to be pressed", "input.onPinPressed|param|name": "the pin that needs to be pressed, eg: TouchPin.P0",
"input.onPinReleased": "Do something when a pin is released.", "input.onPinReleased": "Do something when a pin is released.",
"input.onPinReleased|param|body": "the code to run when the pin is released", "input.onPinReleased|param|body": "the code to run when the pin is released",
"input.onPinReleased|param|name": "the pin that needs to be released", "input.onPinReleased|param|name": "the pin that needs to be released, eg: TouchPin.P0",
"input.onScreenDown": "Attaches code to run when the screen is facing down.", "input.onScreenDown": "Attaches code to run when the screen is facing down.",
"input.onScreenDown|param|body": "TODO", "input.onScreenDown|param|body": "TODO",
"input.onScreenUp": "Attaches code to run when the screen is facing up.", "input.onScreenUp": "Attaches code to run when the screen is facing up.",
@ -124,7 +126,7 @@
"input.onShake": "Attaches code to run when the device is shaken.", "input.onShake": "Attaches code to run when the device is shaken.",
"input.onShake|param|body": "TODO", "input.onShake|param|body": "TODO",
"input.pinIsPressed": "Get the pin state (pressed or not). Requires to hold the ground to close the circuit.", "input.pinIsPressed": "Get the pin state (pressed or not). Requires to hold the ground to close the circuit.",
"input.pinIsPressed|param|name": "pin used to detect the touch", "input.pinIsPressed|param|name": "pin used to detect the touch, eg: TouchPin.P0",
"input.rotation": "The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.", "input.rotation": "The pitch or roll of the device, rotation along the ``x-axis`` or ``y-axis``, in degrees.",
"input.rotation|param|kind": "TODO", "input.rotation|param|kind": "TODO",
"input.runningTime": "Gets the number of milliseconds elapsed since power on.", "input.runningTime": "Gets the number of milliseconds elapsed since power on.",
@ -166,7 +168,7 @@
"music.changeTempoBy": "Change the tempo by the specified amount", "music.changeTempoBy": "Change the tempo by the specified amount",
"music.changeTempoBy|param|bpm": "The change in beats per minute to the tempo, eg: 20", "music.changeTempoBy|param|bpm": "The change in beats per minute to the tempo, eg: 20",
"music.noteFrequency": "Gets the frequency of a note.", "music.noteFrequency": "Gets the frequency of a note.",
"music.noteFrequency|param|name": "the note name", "music.noteFrequency|param|name": "the note name, eg: Note.C",
"music.playTone": "Plays a tone through pin ``P0`` for the given duration.", "music.playTone": "Plays a tone through pin ``P0`` for the given duration.",
"music.playTone|param|frequency": "pitch of the tone to play in Hertz (Hz)", "music.playTone|param|frequency": "pitch of the tone to play in Hertz (Hz)",
"music.playTone|param|ms": "tone duration in milliseconds (ms)", "music.playTone|param|ms": "tone duration in milliseconds (ms)",
@ -182,21 +184,21 @@
"pins.analogPitch|param|frequency": "frequency to modulate in Hz.", "pins.analogPitch|param|frequency": "frequency to modulate in Hz.",
"pins.analogPitch|param|ms": "duration of the pitch in milli seconds.", "pins.analogPitch|param|ms": "duration of the pitch in milli seconds.",
"pins.analogReadPin": "Read the connector value as analog, that is, as a value comprised between 0 and 1023.", "pins.analogReadPin": "Read the connector value as analog, that is, as a value comprised between 0 and 1023.",
"pins.analogReadPin|param|name": "pin to write to", "pins.analogReadPin|param|name": "pin to write to, eg: AnalogPin.P0",
"pins.analogSetPeriod": "Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.\nIf this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.", "pins.analogSetPeriod": "Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.\nIf this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.",
"pins.analogSetPeriod|param|micros": "period in micro seconds. eg:20000", "pins.analogSetPeriod|param|micros": "period in micro seconds. eg:20000",
"pins.analogSetPeriod|param|name": "analog pin to set period to", "pins.analogSetPeriod|param|name": "analog pin to set period to, eg: AnalogPin.P0",
"pins.analogSetPitchPin": "Sets the pin used when using `analog pitch` or music.", "pins.analogSetPitchPin": "Sets the pin used when using `analog pitch` or music.",
"pins.analogSetPitchPin|param|name": "pin to modulate pitch from", "pins.analogSetPitchPin|param|name": "pin to modulate pitch from",
"pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.", "pins.analogWritePin": "Set the connector value as analog. Value must be comprised between 0 and 1023.",
"pins.analogWritePin|param|name": "pin name to write to", "pins.analogWritePin|param|name": "pin name to write to, eg: AnalogPin.P0",
"pins.analogWritePin|param|value": "value to write to the pin between ``0`` and ``1023``. eg:1023,0", "pins.analogWritePin|param|value": "value to write to the pin between ``0`` and ``1023``. eg:1023,0",
"pins.createBuffer": "Create a new zero-initialized buffer.", "pins.createBuffer": "Create a new zero-initialized buffer.",
"pins.createBuffer|param|size": "number of bytes in the buffer", "pins.createBuffer|param|size": "number of bytes in the buffer",
"pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1", "pins.digitalReadPin": "Read the specified pin or connector as either 0 or 1",
"pins.digitalReadPin|param|name": "pin to read from", "pins.digitalReadPin|param|name": "pin to read from, eg: DigitalPin.P0",
"pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.", "pins.digitalWritePin": "Set a pin or connector value to either 0 or 1.",
"pins.digitalWritePin|param|name": "pin to write to", "pins.digitalWritePin|param|name": "pin to write to, eg: DigitalPin.P0",
"pins.digitalWritePin|param|value": "value to set on the pin, 1 eg,0", "pins.digitalWritePin|param|value": "value to set on the pin, 1 eg,0",
"pins.i2cReadBuffer": "Read `size` bytes from a 7-bit I2C `address`.", "pins.i2cReadBuffer": "Read `size` bytes from a 7-bit I2C `address`.",
"pins.i2cReadNumber": "Read one number from 7-bit I2C address.", "pins.i2cReadNumber": "Read one number from 7-bit I2C address.",
@ -209,19 +211,21 @@
"pins.map|param|toLow": "the lower bound of the value's target range", "pins.map|param|toLow": "the lower bound of the value's target range",
"pins.map|param|value": "value to map in ranges", "pins.map|param|value": "value to map in ranges",
"pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.", "pins.onPulsed": "Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.",
"pins.onPulsed|param|name": "digital pin to register to, eg: DigitalPin.P0",
"pins.onPulsed|param|pulse": "the value of the pulse, eg: PulseValue.High",
"pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.", "pins.pulseDuration": "Gets the duration of the last pulse in micro-seconds. This function should be called from a ``onPulsed`` handler.",
"pins.pulseIn": "Returns the duration of a pulse in microseconds", "pins.pulseIn": "Returns the duration of a pulse in microseconds",
"pins.pulseIn|param|name": "the pin which measures the pulse", "pins.pulseIn|param|name": "the pin which measures the pulse, eg: DigitalPin.P0",
"pins.pulseIn|param|value": "the value of the pulse (default high)", "pins.pulseIn|param|value": "the value of the pulse, eg: PulseValue.High",
"pins.servoSetPulse": "Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.", "pins.servoSetPulse": "Configures this IO pin as an analog/pwm output, configures the period to be 20 ms, and sets the pulse width, based on the value it is given **microseconds** or `1/1000` milliseconds.",
"pins.servoSetPulse|param|micros": "pulse duration in micro seconds, eg:1500", "pins.servoSetPulse|param|micros": "pulse duration in micro seconds, eg:1500",
"pins.servoSetPulse|param|name": "pin name", "pins.servoSetPulse|param|name": "pin name",
"pins.servoWritePin": "Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).", "pins.servoWritePin": "Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).",
"pins.servoWritePin|param|name": "pin to write to", "pins.servoWritePin|param|name": "pin to write to, eg: AnalogPin.P0",
"pins.servoWritePin|param|value": "angle or rotation speed, eg:180,90,0", "pins.servoWritePin|param|value": "angle or rotation speed, eg:180,90,0",
"pins.setPull": "Configures the pull of this pin.", "pins.setPull": "Configures the pull of this pin.",
"pins.setPull|param|name": "pin to set the pull mode on", "pins.setPull|param|name": "pin to set the pull mode on, eg: DigitalPin.P0",
"pins.setPull|param|pull": "one of the mbed pull configurations: PullUp, PullDown, PullNone ", "pins.setPull|param|pull": "one of the mbed pull configurations, eg: PinPullMode.PullUp",
"pins.sizeOf": "Get the size in bytes of specified number format.", "pins.sizeOf": "Get the size in bytes of specified number format.",
"pins.spiWrite": "Write to the SPI slave and return the response", "pins.spiWrite": "Write to the SPI slave and return the response",
"pins.spiWrite|param|value": "Data to be sent to the SPI slave", "pins.spiWrite|param|value": "Data to be sent to the SPI slave",
@ -232,8 +236,9 @@
"serial.readUntil": "Reads a line of text from the serial port and returns the buffer when the delimiter is met.", "serial.readUntil": "Reads a line of text from the serial port and returns the buffer when the delimiter is met.",
"serial.readUntil|param|delimiter": "text delimiter that separates each text chunk", "serial.readUntil|param|delimiter": "text delimiter that separates each text chunk",
"serial.redirect": "Dynamically configuring the serial instance to use pins other than USBTX and USBRX.", "serial.redirect": "Dynamically configuring the serial instance to use pins other than USBTX and USBRX.",
"serial.redirect|param|rx": "the new reception pin", "serial.redirect|param|rate": "the new baud rate. eg: 115200",
"serial.redirect|param|tx": "the new transmission pins", "serial.redirect|param|rx": "the new reception pin, eg: SerialPin.P1",
"serial.redirect|param|tx": "the new transmission pins, eg: SerialPin.P0",
"serial.writeLine": "Prints a line of text to the serial", "serial.writeLine": "Prints a line of text to the serial",
"serial.writeNumber": "Prints a numeric value to the serial", "serial.writeNumber": "Prints a numeric value to the serial",
"serial.writeString": "Sends a piece of text through Serial connection.", "serial.writeString": "Sends a piece of text through Serial connection.",

View File

@ -9,6 +9,8 @@
"AcceleratorRange.TwoG|block": "2g", "AcceleratorRange.TwoG|block": "2g",
"BaudRate.BaudRate115200|block": "115200", "BaudRate.BaudRate115200|block": "115200",
"BaudRate.BaudRate9600|block": "9600", "BaudRate.BaudRate9600|block": "9600",
"BeatFraction.Breve|block": "4",
"BeatFraction.Double|block": "2",
"BeatFraction.Eighth|block": "1/8", "BeatFraction.Eighth|block": "1/8",
"BeatFraction.Half|block": "1/2", "BeatFraction.Half|block": "1/2",
"BeatFraction.Quarter|block": "1/4", "BeatFraction.Quarter|block": "1/4",
@ -108,6 +110,7 @@
"game.createSprite|block": "create sprite at|x: %x|y: %y", "game.createSprite|block": "create sprite at|x: %x|y: %y",
"game.gameOver|block": "game over", "game.gameOver|block": "game over",
"game.score|block": "score", "game.score|block": "score",
"game.setScore|block": "set score %points",
"game.startCountdown|block": "start countdown|(ms) %duration", "game.startCountdown|block": "start countdown|(ms) %duration",
"game|block": "game", "game|block": "game",
"images.createBigImage|block": "create big image", "images.createBigImage|block": "create big image",
@ -120,7 +123,7 @@
"input.magneticForce|block": "magnetic force (µT)|%NAME", "input.magneticForce|block": "magnetic force (µT)|%NAME",
"input.onButtonPressed|block": "on button|%NAME|pressed", "input.onButtonPressed|block": "on button|%NAME|pressed",
"input.onGesture|block": "on |%NAME", "input.onGesture|block": "on |%NAME",
"input.onPinPressed|block": "on pin %NAME|pressed", "input.onPinPressed|block": "on pin %name|pressed",
"input.onPinReleased|block": "on pin %NAME|released", "input.onPinReleased|block": "on pin %NAME|released",
"input.pinIsPressed|block": "pin %NAME|is pressed", "input.pinIsPressed|block": "pin %NAME|is pressed",
"input.rotation|block": "rotation (°)|%NAME", "input.rotation|block": "rotation (°)|%NAME",
@ -129,6 +132,7 @@
"input.temperature|block": "temperature (°C)", "input.temperature|block": "temperature (°C)",
"input|block": "input", "input|block": "input",
"led.brightness|block": "brightness", "led.brightness|block": "brightness",
"led.enable|block": "led enable %on",
"led.plotBarGraph|block": "plot bar graph of %value |up to %high", "led.plotBarGraph|block": "plot bar graph of %value |up to %high",
"led.plot|block": "plot|x %x|y %y", "led.plot|block": "plot|x %x|y %y",
"led.point|block": "point|x %x|y %y", "led.point|block": "point|x %x|y %y",

View File

@ -40,7 +40,7 @@ namespace game {
* @param x sprite horizontal coordinate, eg: 2 * @param x sprite horizontal coordinate, eg: 2
* @param y sprite vertical coordinate, eg: 2 * @param y sprite vertical coordinate, eg: 2
*/ */
//% weight=60 //% weight=60 blockGap=8
//% blockId=game_create_sprite block="create sprite at|x: %x|y: %y" //% blockId=game_create_sprite block="create sprite at|x: %x|y: %y"
//% parts="ledmatrix" //% parts="ledmatrix"
export function createSprite(x: number, y: number): LedSprite { export function createSprite(x: number, y: number): LedSprite {
@ -146,8 +146,9 @@ namespace game {
/** /**
* Sets the current score value * Sets the current score value
* @param value TODO * @param value new score value.
*/ */
//% blockId=game_set_score block="set score %points" blockGap=8
//% weight=10 help=game/set-score //% weight=10 help=game/set-score
export function setScore(value: number): void { export function setScore(value: number): void {
_score = Math.max(0, value); _score = Math.max(0, value);
@ -589,7 +590,7 @@ namespace game {
/** /**
* Turns on the sprite (on by default) * Turns on the sprite (on by default)
* @param this TODO * @param this the sprite
*/ */
public on(): void { public on(): void {
this.setBrightness(255); this.setBrightness(255);
@ -597,7 +598,7 @@ namespace game {
/** /**
* Turns off the sprite (on by default) * Turns off the sprite (on by default)
* @param this TODO * @param this the sprite
*/ */
public off(): void { public off(): void {
this.setBrightness(0); this.setBrightness(0);
@ -605,8 +606,8 @@ namespace game {
/** /**
* Set the ``brightness`` of a sprite * Set the ``brightness`` of a sprite
* @param this TODO * @param this the sprite
* @param brightness TODO * @param brightness the brightness from 0 (off) to 255 (on), eg: 255.
*/ */
//% parts="ledmatrix" //% parts="ledmatrix"
public setBrightness(brightness: number): void { public setBrightness(brightness: number): void {
@ -616,8 +617,9 @@ namespace game {
/** /**
* Reports the ``brightness` of a sprite on the LED screen * Reports the ``brightness` of a sprite on the LED screen
* @param this TODO * @param this the sprite
*/ */
//% parts="ledmatrix"
public brightness(): number { public brightness(): number {
let r: number; let r: number;
return this._brightness; return this._brightness;
@ -625,8 +627,8 @@ namespace game {
/** /**
* Changes the ``y`` position by the given amount * Changes the ``y`` position by the given amount
* @param this TODO * @param this the sprite
* @param value TODO * @param value the value to change brightness
*/ */
public changeBrightnessBy(value: number): void { public changeBrightnessBy(value: number): void {
this.setBrightness(this._brightness + value); this.setBrightness(this._brightness + value);
@ -643,10 +645,12 @@ namespace game {
/** /**
* Deletes the sprite from the game engine. All further operation of the sprite will not have any effect. * Deletes the sprite from the game engine. All further operation of the sprite will not have any effect.
* @param sprite TODO * @param this sprite to delete
*/ */
public delete(sprite: LedSprite): void { //% weight=59
sprites.removeElement(sprite); //% blockId="game_delete_sprite" block="delete %this"
public delete(): void {
sprites.removeElement(this);
} }
/** /**

View File

@ -111,8 +111,8 @@ enum class Gesture {
namespace input { namespace input {
/** /**
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed * Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
* @param button TODO * @param button the button that needs to be pressed
* @param body TODO * @param body code to run when event is raised
*/ */
//% help=input/on-button-pressed weight=85 blockGap=8 //% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192" //% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
@ -123,7 +123,8 @@ namespace input {
/** /**
* Do something when when a gesture is done (like shaking the micro:bit). * Do something when when a gesture is done (like shaking the micro:bit).
* @param body TODO * @param gesture the type of gesture to track, eg: Gesture.Shake
* @param body code to run when gesture is raised
*/ */
//% help=input/on-gesture weight=84 blockGap=8 //% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135" //% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
@ -138,11 +139,11 @@ namespace input {
/** /**
* Do something when a pin is pressed. * Do something when a pin is pressed.
* @param name the pin that needs to be pressed * @param name the pin that needs to be pressed, eg: TouchPin.P0
* @param body the code to run when the pin is pressed * @param body the code to run when the pin is pressed
*/ */
//% help=input/on-pin-pressed weight=83 //% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %NAME|pressed" icon="\uf094" //% blockId=device_pin_event block="on pin %name|pressed" icon="\uf094"
void onPinPressed(TouchPin name, Action body) { void onPinPressed(TouchPin name, Action body) {
auto pin = getPin((int)name); auto pin = getPin((int)name);
if (!pin) return; if (!pin) return;
@ -154,7 +155,7 @@ namespace input {
/** /**
* Do something when a pin is released. * Do something when a pin is released.
* @param name the pin that needs to be released * @param name the pin that needs to be released, eg: TouchPin.P0
* @param body the code to run when the pin is released * @param body the code to run when the pin is released
*/ */
//% help=input/on-pin-released weight=6 blockGap=8 //% help=input/on-pin-released weight=6 blockGap=8
@ -171,6 +172,7 @@ namespace input {
/** /**
* Get the button state (pressed or not) for ``A`` and ``B``. * Get the button state (pressed or not) for ``A`` and ``B``.
* @param button the button to query the request, eg: Button.A
*/ */
//% help=input/button-is-pressed weight=60 //% help=input/button-is-pressed weight=60
//% block="button|%NAME|is pressed" //% block="button|%NAME|is pressed"
@ -189,7 +191,7 @@ namespace input {
/** /**
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit. * Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
* @param name pin used to detect the touch * @param name pin used to detect the touch, eg: TouchPin.P0
*/ */
//% help=input/pin-is-pressed weight=58 //% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094" //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094"

View File

@ -95,7 +95,7 @@ namespace led {
/** /**
* Turns on or off the display * Turns on or off the display
*/ */
//% help=led/enable blockId=device_led_enable icon="\uf04d" //% help=led/enable blockId=device_led_enable block="led enable %on" icon="\uf04d"
//% advanced=true parts="ledmatrix" //% advanced=true parts="ledmatrix"
void enable(bool on) { void enable(bool on) {
if (on) uBit.display.enable(); if (on) uBit.display.enable();

View File

@ -119,7 +119,11 @@ enum BeatFraction {
//% block="1/8" //% block="1/8"
Eighth = 8, Eighth = 8,
//% block="1/16" //% block="1/16"
Sixteenth = 16 Sixteenth = 16,
//% block="2"
Double = 32,
//% block="4",
Breve = 64
} }
/** /**
@ -166,7 +170,7 @@ namespace music {
/** /**
* Gets the frequency of a note. * Gets the frequency of a note.
* @param name the note name * @param name the note name, eg: Note.C
*/ */
//% weight=50 help=music/note-frequency //% weight=50 help=music/note-frequency
//% blockId=device_note block="%note" //% blockId=device_note block="%note"
@ -188,11 +192,15 @@ namespace music {
init(); init();
if (fraction == null) fraction = BeatFraction.Whole; if (fraction == null) fraction = BeatFraction.Whole;
let beat = 60000 / beatsPerMinute; let beat = 60000 / beatsPerMinute;
if (fraction == BeatFraction.Whole) return beat; switch (fraction) {
else if (fraction == BeatFraction.Half) return beat / 2; case BeatFraction.Half: return beat / 2;
else if (fraction == BeatFraction.Quarter) return beat / 4 case BeatFraction.Quarter: return beat / 4;
else if (fraction == BeatFraction.Eighth) return beat / 8; case BeatFraction.Eighth: return beat / 8;
else return beat / 16; case BeatFraction.Sixteenth: return beat / 16;
case BeatFraction.Double: return beat * 2;
case BeatFraction.Breve: return beat * 4;
default: return beat;
}
} }
/** /**

View File

@ -92,7 +92,7 @@ namespace pins {
/** /**
* Read the specified pin or connector as either 0 or 1 * Read the specified pin or connector as either 0 or 1
* @param name pin to read from * @param name pin to read from, eg: DigitalPin.P0
*/ */
//% help=pins/digital-read-pin weight=30 //% help=pins/digital-read-pin weight=30
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 //% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8
@ -102,7 +102,7 @@ namespace pins {
/** /**
* Set a pin or connector value to either 0 or 1. * Set a pin or connector value to either 0 or 1.
* @param name pin to write to * @param name pin to write to, eg: DigitalPin.P0
* @param value value to set on the pin, 1 eg,0 * @param value value to set on the pin, 1 eg,0
*/ */
//% help=pins/digital-write-pin weight=29 //% help=pins/digital-write-pin weight=29
@ -113,7 +113,7 @@ namespace pins {
/** /**
* Read the connector value as analog, that is, as a value comprised between 0 and 1023. * Read the connector value as analog, that is, as a value comprised between 0 and 1023.
* @param name pin to write to * @param name pin to write to, eg: AnalogPin.P0
*/ */
//% help=pins/analog-read-pin weight=25 //% help=pins/analog-read-pin weight=25
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" //% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8"
@ -123,7 +123,7 @@ namespace pins {
/** /**
* Set the connector value as analog. Value must be comprised between 0 and 1023. * Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name pin name to write to * @param name pin name to write to, eg: AnalogPin.P0
* @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0 * @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0
*/ */
//% help=pins/analog-write-pin weight=24 //% help=pins/analog-write-pin weight=24
@ -135,7 +135,7 @@ namespace pins {
/** /**
* Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds. * Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.
* If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect. * If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.
* @param name analog pin to set period to * @param name analog pin to set period to, eg: AnalogPin.P0
* @param micros period in micro seconds. eg:20000 * @param micros period in micro seconds. eg:20000
*/ */
//% help=pins/analog-set-period weight=23 blockGap=8 //% help=pins/analog-set-period weight=23 blockGap=8
@ -146,6 +146,8 @@ namespace pins {
/** /**
* Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``. * Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.
* @param name digital pin to register to, eg: DigitalPin.P0
* @param pulse the value of the pulse, eg: PulseValue.High
*/ */
//% help=pins/on-pulsed weight=22 blockGap=8 advanced=true //% help=pins/on-pulsed weight=22 blockGap=8 advanced=true
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse"
@ -169,8 +171,8 @@ namespace pins {
/** /**
* Returns the duration of a pulse in microseconds * Returns the duration of a pulse in microseconds
* @param name the pin which measures the pulse * @param name the pin which measures the pulse, eg: DigitalPin.P0
* @param value the value of the pulse (default high) * @param value the value of the pulse, eg: PulseValue.High
* @param maximum duration in micro-seconds * @param maximum duration in micro-seconds
*/ */
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value" //% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
@ -198,7 +200,7 @@ namespace pins {
/** /**
* Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement). * Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).
* @param name pin to write to * @param name pin to write to, eg: AnalogPin.P0
* @param value angle or rotation speed, eg:180,90,0 * @param value angle or rotation speed, eg:180,90,0
*/ */
//% help=pins/servo-write-pin weight=20 //% help=pins/servo-write-pin weight=20
@ -260,8 +262,8 @@ namespace pins {
/** /**
* Configures the pull of this pin. * Configures the pull of this pin.
* @param name pin to set the pull mode on * @param name pin to set the pull mode on, eg: DigitalPin.P0
* @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp
*/ */
//% help=pins/set-pull weight=3 advanced=true //% help=pins/set-pull weight=3 advanced=true
//% blockId=device_set_pull block="set pull|pin %pin|to %pull" //% blockId=device_set_pull block="set pull|pin %pin|to %pull"

View File

@ -79,7 +79,7 @@ namespace pxt {
intcheck(vtable->methods[0] == &RefRecord_destroy, ERR_SIZE, 3); intcheck(vtable->methods[0] == &RefRecord_destroy, ERR_SIZE, 3);
intcheck(vtable->methods[1] == &RefRecord_print, ERR_SIZE, 4); intcheck(vtable->methods[1] == &RefRecord_print, ERR_SIZE, 4);
void *ptr = ::operator new(vtable->numbytes); void *ptr = ::operator new(vtable->numbytes);
RefRecord *r = new (ptr) RefRecord(PXT_VTABLE_TO_INT(vtable)); RefRecord *r = new (ptr) RefRecord(PXT_VTABLE_TO_INT(vtable));
memset(r->fields, 0, vtable->numbytes - sizeof(RefRecord)); memset(r->fields, 0, vtable->numbytes - sizeof(RefRecord));
@ -117,7 +117,6 @@ namespace pxt {
void RefObject::destroy() { void RefObject::destroy() {
((RefObjectMethod)getVTable()->methods[0])(this); ((RefObjectMethod)getVTable()->methods[0])(this);
delete this;
} }
void RefObject::print() { void RefObject::print() {
@ -132,6 +131,9 @@ namespace pxt {
if (refmask[i]) decr(r->fields[i]); if (refmask[i]) decr(r->fields[i]);
r->fields[i] = 0; r->fields[i] = 0;
} }
//RefRecord is allocated using placement new
r->~RefRecord();
::operator delete(r);
} }
void RefRecord_print(RefRecord *r) void RefRecord_print(RefRecord *r)
@ -242,6 +244,7 @@ namespace pxt {
this->data[i] = 0; this->data[i] = 0;
} }
this->data.resize(0); this->data.resize(0);
delete this;
} }
void RefCollection::print() void RefCollection::print()
@ -258,6 +261,9 @@ namespace pxt {
decr(fields[i]); decr(fields[i]);
fields[i] = 0; fields[i] = 0;
} }
//RefAction is allocated using placement new
this->~RefAction();
::operator delete(this);
} }
void RefAction::print() void RefAction::print()
@ -272,6 +278,7 @@ namespace pxt {
void RefLocal::destroy() void RefLocal::destroy()
{ {
delete this;
} }
PXT_VTABLE_CTOR(RefLocal) { PXT_VTABLE_CTOR(RefLocal) {
@ -290,6 +297,7 @@ namespace pxt {
void RefRefLocal::destroy() void RefRefLocal::destroy()
{ {
decr(v); decr(v);
delete this;
} }
PXT_VTABLE_BEGIN(RefMap, 0, RefMapMarker) PXT_VTABLE_BEGIN(RefMap, 0, RefMapMarker)
@ -304,6 +312,7 @@ namespace pxt {
data[i].val = 0; data[i].val = 0;
} }
data.resize(0); data.resize(0);
delete this;
} }
int RefMap::findIdx(uint32_t key) { int RefMap::findIdx(uint32_t key) {
@ -328,7 +337,7 @@ namespace pxt {
for(std::set<RefObject*>::iterator itr = allptrs.begin();itr!=allptrs.end();itr++) for(std::set<RefObject*>::iterator itr = allptrs.begin();itr!=allptrs.end();itr++)
{ {
(*itr)->print(); (*itr)->print();
} }
printf("\n"); printf("\n");
} }
#else #else
@ -341,16 +350,16 @@ namespace pxt {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
map<pair<int, int>, Action> handlersMap; map<pair<int, int>, Action> handlersMap;
MicroBitEvent lastEvent; MicroBitEvent lastEvent;
// We have the invariant that if [dispatchEvent] is registered against the DAL // We have the invariant that if [dispatchEvent] is registered against the DAL
// for a given event, then [handlersMap] contains a valid entry for that // for a given event, then [handlersMap] contains a valid entry for that
// event. // event.
void dispatchEvent(MicroBitEvent e) { void dispatchEvent(MicroBitEvent e) {
lastEvent = e; lastEvent = e;
Action curr = handlersMap[{ e.source, e.value }]; Action curr = handlersMap[{ e.source, e.value }];
if (curr) if (curr)
runAction1(curr, e.value); runAction1(curr, e.value);
@ -383,7 +392,7 @@ namespace pxt {
create_fiber((void(*)(void*))runAction0, (void*)a, fiberDone); create_fiber((void(*)(void*))runAction0, (void*)a, fiberDone);
} }
} }
void error(ERROR code, int subcode) void error(ERROR code, int subcode)
{ {
@ -435,10 +444,10 @@ namespace pxt {
// unique group for radio based on source hash // unique group for radio based on source hash
// ::touch_develop::micro_bit::radioDefaultGroup = programHash(); // ::touch_develop::micro_bit::radioDefaultGroup = programHash();
// repeat error 4 times and restart as needed // repeat error 4 times and restart as needed
microbit_panic_timeout(4); microbit_panic_timeout(4);
int32_t ver = *pc++; int32_t ver = *pc++;
checkStr(ver == 0x4209, ":( Bad runtime version"); checkStr(ver == 0x4209, ":( Bad runtime version");
@ -467,6 +476,6 @@ namespace pxt {
{ {
exec_binary((int32_t*)functionsAndBytecode); exec_binary((int32_t*)functionsAndBytecode);
} }
} }
// vim: ts=2 sw=2 expandtab // vim: ts=2 sw=2 expandtab

View File

@ -83,9 +83,9 @@ namespace serial {
/** /**
* Dynamically configuring the serial instance to use pins other than USBTX and USBRX. * Dynamically configuring the serial instance to use pins other than USBTX and USBRX.
* @param tx the new transmission pins * @param tx the new transmission pins, eg: SerialPin.P0
* @param rx the new reception pin * @param rx the new reception pin, eg: SerialPin.P1
* @param baud the new baud rate. eg: 115200 * @param rate the new baud rate. eg: 115200
*/ */
//% weight=10 //% weight=10
//% help=serial/redirect-to //% help=serial/redirect-to

46
libs/core/shims.d.ts vendored
View File

@ -216,8 +216,8 @@ declare namespace input {
/** /**
* Do something when a button (``A``, ``B`` or both ``A+B``) is pressed * Do something when a button (``A``, ``B`` or both ``A+B``) is pressed
* @param button TODO * @param button the button that needs to be pressed
* @param body TODO * @param body code to run when event is raised
*/ */
//% help=input/on-button-pressed weight=85 blockGap=8 //% help=input/on-button-pressed weight=85 blockGap=8
//% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192" //% blockId=device_button_event block="on button|%NAME|pressed" icon="\uf192"
@ -226,7 +226,8 @@ declare namespace input {
/** /**
* Do something when when a gesture is done (like shaking the micro:bit). * Do something when when a gesture is done (like shaking the micro:bit).
* @param body TODO * @param gesture the type of gesture to track, eg: Gesture.Shake
* @param body code to run when gesture is raised
*/ */
//% help=input/on-gesture weight=84 blockGap=8 //% help=input/on-gesture weight=84 blockGap=8
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135" //% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
@ -235,16 +236,16 @@ declare namespace input {
/** /**
* Do something when a pin is pressed. * Do something when a pin is pressed.
* @param name the pin that needs to be pressed * @param name the pin that needs to be pressed, eg: TouchPin.P0
* @param body the code to run when the pin is pressed * @param body the code to run when the pin is pressed
*/ */
//% help=input/on-pin-pressed weight=83 //% help=input/on-pin-pressed weight=83
//% blockId=device_pin_event block="on pin %NAME|pressed" icon="\uf094" shim=input::onPinPressed //% blockId=device_pin_event block="on pin %name|pressed" icon="\uf094" shim=input::onPinPressed
function onPinPressed(name: TouchPin, body: () => void): void; function onPinPressed(name: TouchPin, body: () => void): void;
/** /**
* Do something when a pin is released. * Do something when a pin is released.
* @param name the pin that needs to be released * @param name the pin that needs to be released, eg: TouchPin.P0
* @param body the code to run when the pin is released * @param body the code to run when the pin is released
*/ */
//% help=input/on-pin-released weight=6 blockGap=8 //% help=input/on-pin-released weight=6 blockGap=8
@ -254,6 +255,7 @@ declare namespace input {
/** /**
* Get the button state (pressed or not) for ``A`` and ``B``. * Get the button state (pressed or not) for ``A`` and ``B``.
* @param button the button to query the request, eg: Button.A
*/ */
//% help=input/button-is-pressed weight=60 //% help=input/button-is-pressed weight=60
//% block="button|%NAME|is pressed" //% block="button|%NAME|is pressed"
@ -264,7 +266,7 @@ declare namespace input {
/** /**
* Get the pin state (pressed or not). Requires to hold the ground to close the circuit. * Get the pin state (pressed or not). Requires to hold the ground to close the circuit.
* @param name pin used to detect the touch * @param name pin used to detect the touch, eg: TouchPin.P0
*/ */
//% help=input/pin-is-pressed weight=58 //% help=input/pin-is-pressed weight=58
//% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094" //% blockId="device_pin_is_pressed" block="pin %NAME|is pressed" icon="\uf094"
@ -497,7 +499,7 @@ declare namespace led {
/** /**
* Turns on or off the display * Turns on or off the display
*/ */
//% help=led/enable blockId=device_led_enable icon="\uf04d" //% help=led/enable blockId=device_led_enable block="led enable %on" icon="\uf04d"
//% advanced=true parts="ledmatrix" shim=led::enable //% advanced=true parts="ledmatrix" shim=led::enable
function enable(on: boolean): void; function enable(on: boolean): void;
@ -512,7 +514,7 @@ declare namespace pins {
/** /**
* Read the specified pin or connector as either 0 or 1 * Read the specified pin or connector as either 0 or 1
* @param name pin to read from * @param name pin to read from, eg: DigitalPin.P0
*/ */
//% help=pins/digital-read-pin weight=30 //% help=pins/digital-read-pin weight=30
//% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 shim=pins::digitalReadPin //% blockId=device_get_digital_pin block="digital read|pin %name" blockGap=8 shim=pins::digitalReadPin
@ -520,7 +522,7 @@ declare namespace pins {
/** /**
* Set a pin or connector value to either 0 or 1. * Set a pin or connector value to either 0 or 1.
* @param name pin to write to * @param name pin to write to, eg: DigitalPin.P0
* @param value value to set on the pin, 1 eg,0 * @param value value to set on the pin, 1 eg,0
*/ */
//% help=pins/digital-write-pin weight=29 //% help=pins/digital-write-pin weight=29
@ -529,7 +531,7 @@ declare namespace pins {
/** /**
* Read the connector value as analog, that is, as a value comprised between 0 and 1023. * Read the connector value as analog, that is, as a value comprised between 0 and 1023.
* @param name pin to write to * @param name pin to write to, eg: AnalogPin.P0
*/ */
//% help=pins/analog-read-pin weight=25 //% help=pins/analog-read-pin weight=25
//% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" shim=pins::analogReadPin //% blockId=device_get_analog_pin block="analog read|pin %name" blockGap="8" shim=pins::analogReadPin
@ -537,7 +539,7 @@ declare namespace pins {
/** /**
* Set the connector value as analog. Value must be comprised between 0 and 1023. * Set the connector value as analog. Value must be comprised between 0 and 1023.
* @param name pin name to write to * @param name pin name to write to, eg: AnalogPin.P0
* @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0 * @param value value to write to the pin between ``0`` and ``1023``. eg:1023,0
*/ */
//% help=pins/analog-write-pin weight=24 //% help=pins/analog-write-pin weight=24
@ -547,7 +549,7 @@ declare namespace pins {
/** /**
* Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds. * Configures the Pulse-width modulation (PWM) of the analog output to the given value in **microseconds** or `1/1000` milliseconds.
* If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect. * If this pin is not configured as an analog output (using `analog write pin`), the operation has no effect.
* @param name analog pin to set period to * @param name analog pin to set period to, eg: AnalogPin.P0
* @param micros period in micro seconds. eg:20000 * @param micros period in micro seconds. eg:20000
*/ */
//% help=pins/analog-set-period weight=23 blockGap=8 //% help=pins/analog-set-period weight=23 blockGap=8
@ -556,6 +558,8 @@ declare namespace pins {
/** /**
* Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``. * Configures this pin to a digital input, and generates events where the timestamp is the duration that this pin was either ``high`` or ``low``.
* @param name digital pin to register to, eg: DigitalPin.P0
* @param pulse the value of the pulse, eg: PulseValue.High
*/ */
//% help=pins/on-pulsed weight=22 blockGap=8 advanced=true //% help=pins/on-pulsed weight=22 blockGap=8 advanced=true
//% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" shim=pins::onPulsed //% blockId=pins_on_pulsed block="on|pin %pin|pulsed %pulse" shim=pins::onPulsed
@ -571,8 +575,8 @@ declare namespace pins {
/** /**
* Returns the duration of a pulse in microseconds * Returns the duration of a pulse in microseconds
* @param name the pin which measures the pulse * @param name the pin which measures the pulse, eg: DigitalPin.P0
* @param value the value of the pulse (default high) * @param value the value of the pulse, eg: PulseValue.High
* @param maximum duration in micro-seconds * @param maximum duration in micro-seconds
*/ */
//% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value" //% blockId="pins_pulse_in" block="pulse in (µs)|pin %name|pulsed %value"
@ -581,7 +585,7 @@ declare namespace pins {
/** /**
* Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement). * Writes a value to the servo, controlling the shaft accordingly. On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with ``0`` being full-speed in one direction, ``180`` being full speed in the other, and a value near ``90`` being no movement).
* @param name pin to write to * @param name pin to write to, eg: AnalogPin.P0
* @param value angle or rotation speed, eg:180,90,0 * @param value angle or rotation speed, eg:180,90,0
*/ */
//% help=pins/servo-write-pin weight=20 //% help=pins/servo-write-pin weight=20
@ -617,8 +621,8 @@ declare namespace pins {
/** /**
* Configures the pull of this pin. * Configures the pull of this pin.
* @param name pin to set the pull mode on * @param name pin to set the pull mode on, eg: DigitalPin.P0
* @param pull one of the mbed pull configurations: PullUp, PullDown, PullNone * @param pull one of the mbed pull configurations, eg: PinPullMode.PullUp
*/ */
//% help=pins/set-pull weight=3 advanced=true //% help=pins/set-pull weight=3 advanced=true
//% blockId=device_set_pull block="set pull|pin %pin|to %pull" shim=pins::setPull //% blockId=device_set_pull block="set pull|pin %pin|to %pull" shim=pins::setPull
@ -685,9 +689,9 @@ declare namespace serial {
/** /**
* Dynamically configuring the serial instance to use pins other than USBTX and USBRX. * Dynamically configuring the serial instance to use pins other than USBTX and USBRX.
* @param tx the new transmission pins * @param tx the new transmission pins, eg: SerialPin.P0
* @param rx the new reception pin * @param rx the new reception pin, eg: SerialPin.P1
* @param baud the new baud rate. eg: 115200 * @param rate the new baud rate. eg: 115200
*/ */
//% weight=10 //% weight=10
//% help=serial/redirect-to //% help=serial/redirect-to

View File

@ -1,6 +1,6 @@
{ {
"name": "devices", "name": "devices",
"description": "The BLE specific services", "description": "Camera, remote control and other Bluetooth services",
"files": [ "files": [
"README.md", "README.md",
"enums.d.ts", "enums.d.ts",
@ -9,16 +9,8 @@
], ],
"public": true, "public": true,
"dependencies": { "dependencies": {
"core": "file:../core" "core": "file:../core",
}, "bluetooth": "file:../bluetooth"
"yotta": {
"config": {
"microbit-dal": {
"bluetooth": {
"enabled": 1
}
}
}
}, },
"installedVersion": "ljipgq" "installedVersion": "ljipgq"
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "pxt-microbit", "name": "pxt-microbit",
"version": "0.6.23", "version": "0.6.37",
"description": "micro:bit target for PXT", "description": "micro:bit target for PXT",
"keywords": [ "keywords": [
"JavaScript", "JavaScript",
@ -34,6 +34,6 @@
"semantic-ui-less": "^2.2.4" "semantic-ui-less": "^2.2.4"
}, },
"dependencies": { "dependencies": {
"pxt-core": "0.5.85" "pxt-core": "0.5.100"
} }
} }

View File

@ -43,11 +43,19 @@
"microbit-serial": "" "microbit-serial": ""
} }
}, },
{
"type": "missingPackage",
"map": {
"radio\\s*\\.": "radio",
"bluetooth\\s*\\.": "bluetooth",
"devices\\s*\\.": "devices"
}
},
{ {
"type": "api", "type": "api",
"map": { "map": {
"bluetooth\\.uartRead\\((.*?)\\)": "bluetooth.uartReadUntil($1)", "bluetooth\\s*\\.uartRead\\s*\\((.*?)\\)": "bluetooth.uartReadUntil($1)",
"bluetooth\\.uartWrite\\((.*?)\\)": "bluetooth.uartWriteUntil($1)" "bluetooth\\s*\\.uartWrite\\s*\\((.*?)\\)": "bluetooth.uartWriteUntil($1)"
} }
} }
] ]
@ -173,15 +181,16 @@
"appTheme": { "appTheme": {
"accentColor": "#5C005C", "accentColor": "#5C005C",
"logoUrl": "http://microbit.org/", "logoUrl": "http://microbit.org/",
"logo": "./static/logo.portrait.black.svg", "logo": "./static/logo.portrait.white.svg",
"docsLogo": "./static/logo.square.white.svg", "docsLogo": "./static/logo.square.white.svg",
"portraitLogo": "./static/logo.square.black.svg", "portraitLogo": "./static/logo.square.white.svg",
"footerLogo": "./static/logo.portrait.black.svg", "footerLogo": "./static/logo.portrait.black.svg",
"cardLogo": "./static/icons/apple-touch-icon.png", "cardLogo": "./static/icons/apple-touch-icon.png",
"appLogo": "./static/icons/apple-touch-icon.png", "appLogo": "./static/icons/apple-touch-icon.png",
"organization": "Microsoft", "organization": "Microsoft",
"organizationUrl": "https://pxt.io/", "organizationUrl": "https://pxt.io/",
"organizationLogo": "./static/Microsoft-logo_rgb_c-gray.png", "organizationLogo": "./static/Microsoft-logo_rgb_c-gray.png",
"organizationWideLogo": "./static/Microsoft-logo_rgb_c-white.png",
"homeUrl": "https://pxt.microbit.org/", "homeUrl": "https://pxt.microbit.org/",
"embedUrl": "https://pxt.microbit.org/", "embedUrl": "https://pxt.microbit.org/",
"privacyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839", "privacyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839",
@ -311,6 +320,17 @@
"browser": "*", "browser": "*",
"path": "/static/mb/device/usb-windows-sendto.jpg" "path": "/static/mb/device/usb-windows-sendto.jpg"
} }
] ],
"invertedMenu": true,
"coloredToolbox": true,
"monacoToolbox": true,
"blocklyOptions": {
"grid": {
"spacing": 45,
"length": 7,
"colour": "rgba(189, 195, 199, 0.30)",
"snap": false
}
}
} }
} }

View File

@ -23,15 +23,15 @@ namespace pxsim.input {
} }
export function rotation(kind: number): number { export function rotation(kind: number): number {
let b = board().accelerometerState; const b = board().accelerometerState;
let acc = b.accelerometer; const acc = b.accelerometer;
acc.activate(); acc.activate();
let x = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); const x = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
let y = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); const y = acc.getY(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
let z = acc.getX(MicroBitCoordinateSystem.NORTH_EAST_DOWN); const z = acc.getZ(MicroBitCoordinateSystem.NORTH_EAST_DOWN);
let roll = Math.atan2(y, z); const roll = Math.atan2(y, z);
let pitch = Math.atan(-x / (y * Math.sin(roll) + z * Math.cos(roll))); const pitch = Math.atan(-x / (y * Math.sin(roll) + z * Math.cos(roll)));
let r = 0; let r = 0;
switch (kind) { switch (kind) {

View File

@ -177,7 +177,8 @@ namespace pxsim.bluetooth {
export function onBluetoothDisconnected(a: RefAction) { export function onBluetoothDisconnected(a: RefAction) {
// TODO // TODO
} }
export function advertiseUrl(url: string, power: number) { } export function advertiseUrl(url: string, power: number, connectable: boolean) { }
export function stopAdvertising() { } export function stopAdvertising() { }
export function setTransmitPower(power: number) {}
} }

View File

@ -556,12 +556,12 @@ namespace pxsim.visuals {
private updateTilt() { private updateTilt() {
if (this.props.disableTilt) return; if (this.props.disableTilt) return;
let state = this.board; const state = this.board;
if (!state || !state.accelerometerState.accelerometer.isActive) return; if (!state || !state.accelerometerState.accelerometer.isActive) return;
let x = state.accelerometerState.accelerometer.getX(); const x = state.accelerometerState.accelerometer.getX();
let y = state.accelerometerState.accelerometer.getY(); const y = -state.accelerometerState.accelerometer.getY();
let af = 8 / 1023; const af = 8 / 1023;
this.element.style.transform = "perspective(30em) rotateX(" + y * af + "deg) rotateY(" + x * af + "deg)" this.element.style.transform = "perspective(30em) rotateX(" + y * af + "deg) rotateY(" + x * af + "deg)"
this.element.style.perspectiveOrigin = "50% 50% 50%"; this.element.style.perspectiveOrigin = "50% 50% 50%";
@ -704,7 +704,7 @@ namespace pxsim.visuals {
} }
let tiltDecayer = 0; let tiltDecayer = 0;
this.element.addEventListener(pointerEvents.move, (ev: MouseEvent) => { this.element.addEventListener(pointerEvents.move, (ev: MouseEvent) => {
let state = this.board; const state = this.board;
if (!state.accelerometerState.accelerometer.isActive) return; if (!state.accelerometerState.accelerometer.isActive) return;
if (tiltDecayer) { if (tiltDecayer) {
@ -712,14 +712,14 @@ namespace pxsim.visuals {
tiltDecayer = 0; tiltDecayer = 0;
} }
let bbox = this.element.getBoundingClientRect(); const bbox = this.element.getBoundingClientRect();
let ax = (ev.clientX - bbox.width / 2) / (bbox.width / 3); const ax = (ev.clientX - bbox.width / 2) / (bbox.width / 3);
let ay = (ev.clientY - bbox.height / 2) / (bbox.height / 3); const ay = (ev.clientY - bbox.height / 2) / (bbox.height / 3);
let x = - Math.max(- 1023, Math.min(1023, Math.floor(ax * 1023))); const x = - Math.max(- 1023, Math.min(1023, Math.floor(ax * 1023)));
let y = Math.max(- 1023, Math.min(1023, Math.floor(ay * 1023))); const y = - Math.max(- 1023, Math.min(1023, Math.floor(ay * 1023)));
let z2 = 1023 * 1023 - x * x - y * y; const z2 = 1023 * 1023 - x * x - y * y;
let z = Math.floor((z2 > 0 ? -1 : 1) * Math.sqrt(Math.abs(z2))); const z = Math.floor((z2 > 0 ? -1 : 1) * Math.sqrt(Math.abs(z2)));
state.accelerometerState.accelerometer.update(x, y, z); state.accelerometerState.accelerometer.update(x, y, z);
this.updateTilt(); this.updateTilt();

View File

@ -1,3 +1,12 @@
/******************************* /*******************************
User Variable Overrides User Variable Overrides
*******************************/ *******************************/
@invertedBackground: #3454D1;
/*******************************
PXT Theme Overrides
*******************************/
@mainMenuHeight: 5rem;
@mainMenuMinHeight: (@itemVerticalPadding * 2) + 2em;

View File

@ -1,3 +1,35 @@
/******************************* /*******************************
User Global Variables User Global Variables
*******************************/ *******************************/
@importGoogleFonts: true;
@fontName : 'Roboto';
@emSize : 14px;
@fontSize : 13px;
@primaryColor: @purple;
@teal: #3891A6;
@blue: #456990;
@red: #EF767A;
@pink: #F46197;
@yellow: #FDE74C;
/* Microbit.org colors */
@orange: #ff8b27;
@purple: #6633cc;
@green: #00ED00;
@pageBackground: #fff;
/*******************************
PXT Overrides
*******************************/
@mainMenuHeight: 5rem;
@mobileMenuHeight: 5rem;
@simulatorBackground: #FDFDFF;
@blocklySvgColor: #ecf0f1;

View File

@ -13,7 +13,142 @@
*******************************/ *******************************/
.download-button { .download-button {
&:extend(.ui all); &:extend(.ui.button all);
&:extend(.button all); &:extend(.purple all);
}
.download-button.download-button-full {
&:extend(.ui.inverted.purple.button all);
}
.download-button:hover {
&:extend(.green all); &:extend(.green all);
} color: black !important;
}
.play-button.play-button-full {
&:extend(.ui.inverted.button all);
}
.getting-started-btn {
&:extend(.ui.button all);
&:extend(.orange all);
}
#filelist {
background: #fff url(https://az742082.vo.msecnd.net/pub/psopafpj) 0 0 repeat !important;
}
/*******************************
Blockly
*******************************/
.blocklyTreeRow {
border-bottom: 1px solid #ecf0f1 !important;
margin-bottom: 0px !important;
}
/* Blockly toolbox font size same as the page font */
.blocklyTreeLabel {
font-family: @pageFont !important;
font-weight: 200;
}
.blocklyToolboxDiv, .monacoToolboxDiv {
background-color: white !important;
border-left: 1px solid #ecf0f1 !important;
}
.blocklyFlyoutBackground {
fill: #525A67 !important;
fill-opacity: 0.5 !important;
}
/* Remove shadow around blockly blocks */
.blocklyPathDark, .blocklyPathLight {
display: none;
}
.organization {
top: 1.6em;
}
/* Blockly Toolbox Buttons */
.blocklyToolboxButtons .blocklyAddPackageButton {
&:extend(.ui.inverted.pink.button all);
&:extend(.circular all);
}
.blocklyToolboxButtons .blocklyUndoButton {
&:extend(.ui.inverted.blue.button all);
&:extend(.circular all);
}
/*******************************
Monaco
*******************************/
.monaco-editor, .monaco-editor .inputarea {
background: #ecf0f1;
}
.monacoDraggableBlock {
background: #ecf0f1;
border: solid 3px #ecf0f1;
}
.monaco-editor-background {
background: #ecf0f1;
}
.monacoFlyout {
background: rgba(82, 90, 103, 0.5);
}
/* Mobile */
@media only screen and (max-width: @largestMobileScreen) {
#filelist {
background: transparent !important;
}
.organization {
top: auto;
}
}
/* Tablet */
@media only screen and (min-width: @tabletBreakpoint) and (max-width: @largestTabletScreen) {
.organization {
top: auto;
}
/* Blockly Toolbox buttons */
#blocklyToolboxButtons, #monacoToolboxButtons {
margin-right: 0.5rem;
margin-left: 0.5rem;
}
}
/* Small Monitor */
@media only screen and (min-width: @computerBreakpoint) and (max-width: @largestSmallMonitor) {
.organization {
top: auto;
}
/* Blockly Toolbox buttons */
#blocklyToolboxButtons, #monacoToolboxButtons {
margin-right: 1rem;
margin-left: 1rem;
}
}
/* Large Monitor */
@media only screen and (min-width: @largeMonitorBreakpoint) {
.blocklyTreeRow {
width: 230px;
padding-left: 1rem;
}
/* Blockly Toolbox buttons */
#blocklyToolboxButtons, #monacoToolboxButtons {
margin-right: 2rem;
margin-left: 2rem;
}
}

View File

@ -32,7 +32,7 @@
@input : 'pxt'; @input : 'pxt';
@label : 'pxt'; @label : 'pxt';
@list : 'pxt'; @list : 'pxt';
@loader : 'pxt'; @loader : 'pulsar';
@rail : 'pxt'; @rail : 'pxt';
@reveal : 'pxt'; @reveal : 'pxt';
@segment : 'pxt'; @segment : 'pxt';
@ -41,7 +41,7 @@
/* Collections */ /* Collections */
@breadcrumb : 'default'; @breadcrumb : 'default';
@form : 'default'; @form : 'default';
@grid : 'default'; @grid : 'pxt';
@menu : 'pxt'; @menu : 'pxt';
@message : 'default'; @message : 'default';
@table : 'default'; @table : 'default';
@ -52,7 +52,7 @@
@dimmer : 'default'; @dimmer : 'default';
@dropdown : 'default'; @dropdown : 'default';
@embed : 'default'; @embed : 'default';
@modal : 'default'; @modal : 'pxt';
@nag : 'default'; @nag : 'default';
@popup : 'default'; @popup : 'default';
@progress : 'default'; @progress : 'default';
@ -91,7 +91,9 @@
@fontPath : 'fonts'; @fontPath : 'fonts';
/*
@headerFont : 'Segoe UI', 'Helvetica Neue', Arial, Helvetica, sans-serif; @headerFont : 'Segoe UI', 'Helvetica Neue', Arial, Helvetica, sans-serif;
@pageFont : 'Segoe UI', 'Helvetica Neue', Arial, Helvetica, sans-serif; @pageFont : 'Segoe UI', 'Helvetica Neue', Arial, Helvetica, sans-serif;
*/
/* End Config */ /* End Config */