Compare commits

...

11 Commits

Author SHA1 Message Date
6455da6adb 0.2.78 2016-04-18 22:55:03 -07:00
4e88ba4ef2 Bump pxt-core to 0.2.82 2016-04-18 22:55:01 -07:00
0c7d49256d don't use blockStatement anymore 2016-04-18 13:31:05 -07:00
c2883d00ee use registerwithdal in simulator 2016-04-18 10:46:44 -07:00
7da483f258 fixing links 2016-04-18 09:47:34 -07:00
6cbc6a53b2 more missing simulator functions 2016-04-18 09:47:27 -07:00
5e23bc96ca don't expose storage in blocks 2016-04-18 09:21:11 -07:00
4169663a8b fixing broken links 2016-04-18 08:33:09 -07:00
4795c58e97 initial blocks for storage 2016-04-16 07:45:04 -07:00
8fb96934ca panic when radio does not start 2016-04-15 22:41:30 -07:00
cd91504c1f fix help urls 2016-04-15 16:54:44 -07:00
42 changed files with 162 additions and 64 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ temp
projects
win10/app/bin
win10/app/bld
win10/*.opendb
*.user
*.sw?

View File

@ -33,7 +33,7 @@ basic.showString(s)
### Lessons
[answering machine](/lessons/answering-machine), [rock paper scissors](/lessons/rock-paper-scissors), [love meter](/lessons/love-meter), [digital pet](/lessons/digital-pet)
[answering machine](/lessons/answering-machine), [rock paper scissors](/lessons/rock-paper-scissors), [love meter](/lessons/love-meter)
### See also

View File

@ -19,5 +19,4 @@ devices.onGamepadButton(MesDpadButtonInfo.ADown, () => {})
### See Also
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [on notified](/reference/devices/on-notified), [signal strength](/reference/devices/signal-strength), [on signal strength changed](/reference/devices/on-signal-strength-changed)
[tell remote control to](/reference/devices/tell-remote-control-to), [raise alert to](/reference/devices/raise-alert-to), [signal strength](/reference/devices/signal-strength), [on signal strength changed](/reference/devices/on-signal-strength-changed)

View File

@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
![](/static/mb/tell-camera-to-0.png)
### KindScript
### JavaScript
```
export function tellCameraTo(event: string)

View File

@ -10,7 +10,7 @@ The functions in the antenna namespace allow the BBC micro:bit to communicate wi
![](/static/mb/tell-microphone-to-0.png)
### KindScript
### JavaScript
```
export function tellMicrophoneTo(event: string)

View File

@ -14,7 +14,7 @@ The set of supported events will depend on the remote device and the BBC micro:b
![](/static/mb/tell-remote-control-to-0.png)
### KindScript
### JavaScript
```
export function tellRemoteControlTo(event: string)

View File

@ -1,16 +1,12 @@
# Change
The game library
### Change
Sprite will change the x position by this number
## Block Editor
### Block Editor
![](/static/mb/change-0.png)
## KindScript
### JavaScript
Sprite will change the x position by this number

View File

@ -4,7 +4,7 @@ The clear function for images.
Turn off all the pixels in an [Image](/reference/images/image).
### KindScript
### JavaScript
```
export function clear(img: micro_bit.Image)

View File

@ -55,5 +55,5 @@ export function startCountdown(ms: number)
### Lessons
[bop it](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)
[game of chance](/lessons/game-of-chance), [game counter](/lessons/game-counter)

View File

@ -4,7 +4,7 @@ The pixel function.
Get the state of a pixel in an [Image](/reference/images/image).
### KindScript
### JavaScript
```
export function pixel(_this: micro_bit.Image, x: number, y: number) : boolean

View File

@ -4,7 +4,7 @@ The plot frame function.
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen)
### KindScript
### JavaScript
```
export function plotFrame(_this: micro_bit.Image, index: number)

View File

@ -4,7 +4,7 @@ The plot image function.
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen)
### KindScript
### JavaScript
```
export function plotImage(_this: micro_bit.Image, xOffset: number)

View File

@ -8,7 +8,7 @@ Scrolls the frames within an [Image](/reference/images/image) on the [LED screen
![](/static/mb/scroll-image-0.png)
### KindScript
### JavaScript
```
export function scrollImage(_this: micro_bit.Image, xOffsetPerStep: number, interval: number)

View File

@ -4,7 +4,7 @@ The set pixel function. #set pixel.
Set the on/off state of pixel in an [Image](/reference/images/image).
### KindScript
### JavaScript
```
export function setPixel(_this: micro_bit.Image, x: number, y: number, value: boolean)

View File

@ -4,7 +4,7 @@ The show frame function.
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen)
### KindScript
### JavaScript
```
export function showFrame(img: micro_bit.Image, frame: number)

View File

@ -4,12 +4,6 @@ The show image function.
Show an [Image](/reference/images/image) on the [LED screen](/device/screen), followed by a 400ms pause.
### Block Editor
![](/static/mb/show-image-0.png)
### KindScript
```
export function showImage(_this: micro_bit.Image, xOffset: number)
```
@ -20,7 +14,7 @@ export function showImage(_this: micro_bit.Image, xOffset: number)
### Create image and show image
Use the [image editor](/reference/images/image) to create images using the [create image](/reference/image/create-image) function, and then use `show image` like this:
Use the [image editor](/reference/images/image) to create images using the [create image](/reference/images/create-image) function, and then use `show image` like this:
```
let img = images.createImage(`

View File

@ -4,10 +4,8 @@ The width function.
Get the width of an [Image](/reference/images/image) in columns.
### KindScript
```
export function width(_this: micro_bit.Image) : number
```sig
images.createImage().width();
```
### Parameters

View File

@ -45,5 +45,5 @@ basic.forever(() => {
### See also
[compass-heading](/input/compass-heading), [lightlevel](/input/lightlevel)
[compass-heading](/reference/input/compass-heading), [lightlevel](/reference/input/lightlevel)

View File

@ -37,5 +37,5 @@ basic.forever(() => {
### See also
[on button pressed](/input/on-button-pressed), [if](/reference/logic/if), [forever](/basic/forever)
[on button pressed](/reference/input/on-button-pressed), [if](/reference/logic/if), [forever](/reference/basic/forever)

View File

@ -26,5 +26,5 @@ basic.forever(() => {
### See also
[acceleration](/reference/input/acceleration), [compass-heading](/input/compass-heading)
[acceleration](/reference/input/acceleration), [compass-heading](/reference/input/compass-heading)

View File

@ -28,5 +28,5 @@ basic.forever(() => {
### See also
[compass heading](/input/compass-heading)
[compass heading](/reference/input/compass-heading)

View File

@ -28,5 +28,5 @@ input.onPinPressed(TouchPin.P0, () => {
### See also
[BBC micro:bit pins](/device/pins), [pin is pressed](/input/pin-is-pressed), [analog read pin](/pins/analog-read-pin), [analog write pin](/pins/analog-write-pin), [digital read pin](/pins/digital-read-pin), [digital write pin](/pins/digital-write-pin)
[BBC micro:bit pins](/device/pins), [pin is pressed](/reference/input/pin-is-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)

View File

@ -32,5 +32,5 @@ basic.forever(() => {
### See also
[BBC micro:bit pins](/device/pins), [on pin pressed](/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)
[BBC micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin)

View File

@ -2,8 +2,6 @@
Display an [Image](/reference/images/image) on the BBC micro:bit's [LED screen](/device/screen). NOTE: `basic -> plot image` has been replaced by `basic -> show leds`.
### KindScript syntax
```sig
basic.plotLeds(`
. . . . .

View File

@ -24,5 +24,5 @@ for (let k = 0; k < 4; k++) {
### See also
[while](/reference/loops/while), [if](/blocks/if)
[while](/reference/loops/while), [if](/reference/logic/if)

View File

@ -39,5 +39,5 @@ The following example uses a while loop to make a diagonal line on the LED scree
### See also
[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/blocks/if), [forever](/reference/basic/forever)
[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/reference/logic/if), [forever](/reference/basic/forever)

View File

@ -31,5 +31,5 @@ radio.onDataReceived(() => {
### See also
[receive number](/reference/radio/receive-number), [send number](/radio/send-number), [set group](/reference/radio/set-group)
[receive number](/reference/radio/receive-number), [send number](/reference/radio/send-number), [set group](/reference/radio/set-group)

View File

@ -30,5 +30,5 @@ radio.onDataReceived(() => {
### See also
[receive number](/input/receive-number), [on data received](/reference/radio/on-data-received)
[receive number](/reference/input/receive-number), [on data received](/reference/radio/on-data-received)

View File

@ -32,7 +32,7 @@ The next six blocks represent comparison operators that yield a Boolean value. M
42 >= 0;
```
Boolean values and operators are often used with an [if](/blocks/if) or [while](/reference/loops/while) statement to determine which code will execute next. For example:
Boolean values and operators are often used with an [if](/reference/logic/if) or [while](/reference/loops/while) statement to determine which code will execute next. For example:
### Functions that return a Boolean
@ -104,5 +104,5 @@ See the documentation on [Numbers](/reference/types/number) for more information
### See also
[if](/blocks/if), [while](/reference/loops/while), [number](/reference/types/number)
[if](/reference/logic/if), [while](/reference/loops/while), [number](/reference/types/number)

View File

@ -20,7 +20,7 @@ The following arithmetic operators work on numbers and return a [Number](/refere
* subtraction: `1 - 3 `
* multiplication: `3 * 2`
* integer division: `7 / 3`
* modulo is available through the [math library](/blocks/math)
* modulo is available through the [math library](/reference/math)
### Relational operators
@ -47,7 +47,7 @@ Some functions return a number, which you can store in a variable. For example t
### Math functions
The [math library](/blocks/math) includes math related functions. In the [Block Editor](/blocks/editor), click `math` on the Code Keyboard to see the math functions. For example, the `absolute` function returns the returns the absolute value of input parameter `x`:
The [math library](/reference/math) includes math related functions. In the [Block Editor](/blocks/editor), click `math` on the Code Keyboard to see the math functions. For example, the `absolute` function returns the returns the absolute value of input parameter `x`:
![](/static/mb/blocks/number-3.png)
@ -57,5 +57,5 @@ The [math library](/blocks/math) includes math related functions. In the [Block
### See also
[math library](/blocks/math), [var](/reference/variables/var), [Boolean](/reference/types/boolean), [show number](/reference/basic/show-number)
[math library](/reference/math), [var](/reference/variables/var), [Boolean](/reference/types/boolean), [show number](/reference/basic/show-number)

View File

@ -28,7 +28,7 @@ let num1 = 42
````
### Notes
* You can use the assignment operator with variables of each of the supported [types](/blocks/types).
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
### Lessons
@ -36,5 +36,5 @@ let num1 = 42
### See also
[variable](/reference/variables/var), [types](/blocks/types)
[variable](/reference/variables/var), [types](/reference/types)

View File

@ -32,9 +32,9 @@ basic.showNumber(x);
### Notes
* You can use the assignment operator with variables of each of the supported [types](/blocks/types).
* You can use the assignment operator with variables of each of the supported [types](/reference/types).
### See also
[variable](/reference/variables/var), [types](/blocks/types)
[variable](/reference/variables/var), [types](/reference/types)

View File

@ -13,7 +13,10 @@ namespace radio {
int radioEnable() {
int r = uBit.radio.enable();
if (r != MICROBIT_OK) return r;
if (r != MICROBIT_OK) {
uBit.panic(43);
return r;
}
if (!radioEnabled) {
uBit.radio.setGroup(pxt::programHash());
radioEnabled = true;

View File

@ -151,7 +151,7 @@ namespace control {
* Raises an event in the event bus.
*/
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
//% blockExternalInputs=1 blockStatement=1
//% blockExternalInputs=1
void onEvent(int src, int value, Action handler) {
registerWithDal(src, value, handler);
}

View File

@ -281,5 +281,7 @@ declare namespace serial {
Int32BE = 10,
// UInt32,
}
declare namespace storage {
}
// Auto-generated. Do not edit. Really.

View File

@ -26,7 +26,8 @@
"pins.ts",
"serial.cpp",
"serial.ts",
"buffer.cpp"
"buffer.cpp",
"storage.cpp"
],
"public": true,
"dependencies": {},

View File

@ -7,7 +7,7 @@ namespace serial {
* Prints a line of text to the serial
* @param value to send over serial
*/
//% help=/reference/serial/write-line
//% help=/serial/write-line
//% blockId=serial_writeline block="serial|write %text"
export function writeLine(text: string): void {
writeString(text);
@ -27,6 +27,7 @@ namespace serial {
* @param value to write
*/
//% weight=80
//% help=/serial/write-value
//% blockId=serial_writevalue block="serial|write %name|= %value"
export function writeValue(name: string, value: number): void {
writeString(name);

View File

@ -340,7 +340,7 @@ declare namespace control {
* Raises an event in the event bus.
*/
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source|with value %value=control_event_value"
//% blockExternalInputs=1 blockStatement=1 shim=control::onEvent
//% blockExternalInputs=1 shim=control::onEvent
function onEvent(src: number, value: number, handler: () => void): void;
}
@ -585,4 +585,37 @@ declare interface Buffer {
write(dstOffset: number, src: Buffer): void;
}
/**
* This allows reading and writing of small blocks of data to FLASH memory.
*/
//% weight=10 color=#cc6600
declare namespace storage {
/**
* Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs
* have to be rewritten as well.
*/
//% shim=storage::putBuffer
function putBuffer(key: string, buffer: Buffer): void;
/**
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
*/
//% shim=storage::getBuffer
function getBuffer(key: string): Buffer;
/**
* Removes an entry identified by the key.
*/
//% shim=storage::remove
function remove(key: string): void;
/**
* The number of entries in the key value store
*/
//% shim=storage::size
function size(): number;
}
// Auto-generated. Do not edit. Really.

43
libs/microbit/storage.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "ksbit.h"
/**
* This allows reading and writing of small blocks of data to FLASH memory.
*/
//% weight=10 color=#cc6600
namespace storage {
/**
* Writes the key and buffer pair into FLASH. This operation is rather costly as all the key/value pairs
* have to be rewritten as well.
*/
//%
void putBuffer(StringData* key, Buffer buffer) {
uBit.storage.put(ManagedString(key), ManagedBuffer(buffer).getBytes());
}
/**
* Gets the buffer at the given key if any. If no key is available, empty buffer is returned.
*/
//%
Buffer getBuffer(StringData* key) {
KeyValuePair* pv = uBit.storage.get(ManagedString(key));
if (pv == NULL) return ManagedBuffer().leakData();
return ManagedBuffer(pv->value, sizeof(pv->value)).leakData();
}
/**
* Removes an entry identified by the key.
*/
//%
void remove(StringData * key) {
uBit.storage.remove(ManagedString(key));
}
/**
* The number of entries in the key value store
*/
//%
int size() {
return uBit.storage.size();
}
}

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.77",
"version": "0.2.78",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",
@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.2.81"
"pxt-core": "0.2.82"
}
}

View File

@ -201,7 +201,7 @@ namespace pxsim.basic {
else ImageMethods.scrollImage(createImageFromString(s + ' '), interval, 1);
}
}
export function showLeds(leds: Image, delay: number): void {
showAnimation(leds, delay);
}
@ -250,7 +250,7 @@ namespace pxsim.input {
b.usesButtonAB = true;
runtime.queueDisplayUpdate();
}
b.bus.listen(button, DAL.MICROBIT_BUTTON_EVT_CLICK, handler);
pxt.registerWithDal(button, DAL.MICROBIT_BUTTON_EVT_CLICK, handler);
}
export function buttonIsPressed(button: number): boolean {
@ -273,7 +273,7 @@ namespace pxsim.input {
b.useShake = true;
runtime.queueDisplayUpdate();
}
b.bus.listen(DAL.MICROBIT_ID_GESTURE, gesture, handler);
pxt.registerWithDal(DAL.MICROBIT_ID_GESTURE, gesture, handler);
}
export function onPinPressed(pinId: number, handler: RefAction) {
@ -424,7 +424,7 @@ namespace pxsim.radio {
}
export function onBroadcastMessageReceived(msg: number, handler: RefAction): void {
board().bus.listen(DAL.MES_BROADCAST_GENERAL_ID, msg, handler);
pxt.registerWithDal(DAL.MES_BROADCAST_GENERAL_ID, msg, handler);
}
export function setGroup(id: number): void {
@ -452,7 +452,7 @@ namespace pxsim.radio {
}
export function onDataReceived(handler: RefAction): void {
board().bus.listen(DAL.MICROBIT_ID_RADIO, DAL.MICROBIT_RADIO_EVT_DATAGRAM, handler);
pxt.registerWithDal(DAL.MICROBIT_ID_RADIO, DAL.MICROBIT_RADIO_EVT_DATAGRAM, handler);
}
}
@ -564,6 +564,34 @@ namespace pxsim.ImageMethods {
runtime.queueDisplayUpdate()
}
export function height(leds: Image) : number {
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
return Image.height;
}
export function width(leds: Image) : number {
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
return leds.width;
}
export function plotFrame(leds: Image, frame: number) {
ImageMethods.plotImage(leds, frame * Image.height);
}
export function showFrame(leds: Image, frame: number) {
ImageMethods.showImage(leds, frame * Image.height);
}
export function pixel(leds: Image, x: number, y: number) : number {
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
return leds.get(x,y);
}
export function setPixel(leds: Image, x: number, y: number, v:number) {
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);
leds.set(x,y,v);
}
export function clear(leds: Image) {
if (!leds) panic(PanicCode.MICROBIT_NULL_DEREFERENCE);

View File

@ -611,6 +611,7 @@ namespace pxsim {
}
export class Image {
public static height: number = 5;
public width: number;
public data: number[];
constructor(width: number, data: number[]) {