Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
c04538313d | |||
1039dc560e | |||
957c7ad848 | |||
5e7351a481 | |||
f0c089373b | |||
879a85bdbb | |||
7a9c2e0fe4 | |||
9656c1159a | |||
801117d6b0 | |||
c084bff334 | |||
18bf35f179 | |||
7e7dc91947 | |||
da79f643dc | |||
ea10cde3eb | |||
0a60b0ee37 | |||
b4bc985068 | |||
78f9af5bc2 | |||
e9410d17a6 | |||
ca8ef260d5 | |||
5ea5e9bb5b | |||
19c689a8c4 |
171
docs/camp.md
Normal file
@ -0,0 +1,171 @@
|
||||
# Getting started
|
||||
|
||||
Are you ready to build cool BBC micro:bit programs? For each challenge, reorder the blocks to recreate the program.
|
||||
|
||||
* If you haven't done so, open [https://m.pxt.io](/) and create a new **Blocks Editor** project
|
||||
|
||||
## Basic
|
||||
|
||||
### Show leds
|
||||
|
||||
Use the blocks below to draw a figure on the screen. You can redo the smiley face or try something else!
|
||||
|
||||
```shuffle
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
```
|
||||
|
||||
To transfer your code to the BBC micro:bit,
|
||||
* connect your micro:bit to the computer using the USB cable
|
||||
* click on **Download**
|
||||
* drag&drop the **.hex** file into the **MICROBIT** drive
|
||||
* wait till the yellow light is done blinking!
|
||||
|
||||
### Show animation Forever
|
||||
|
||||
Show one image after the other to create an animation.,
|
||||
|
||||
Reorder the blocks to make the micro:bit show a happy, then unhappy face.
|
||||
```shuffle
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #
|
||||
`)
|
||||
```
|
||||
|
||||
### Repeat forever
|
||||
|
||||
Use the ``forever`` block to repeat your code and have a continuous animation.
|
||||
|
||||
Unsuffle the blocks to create a happy, unhappy animation.... or changes the image to make it your own!
|
||||
```shuffle
|
||||
basic.forever(() => {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #
|
||||
`)
|
||||
});
|
||||
```
|
||||
|
||||
### Your turn now!
|
||||
|
||||
Use the blocks ``show leds`` and ``forever``
|
||||
to create your own custom awesome animation!
|
||||
|
||||
## Inputs
|
||||
|
||||
### Button A and B
|
||||
|
||||
Unshuffle the blocks so that the micro:bit shows "YES" when button A is pressed, and "NO" when B is pressed.
|
||||
The key idea is that all the blocks nested under `on button ... pressed` will run when that button is pressed.
|
||||
|
||||
```blocks
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("AAAAA");
|
||||
});
|
||||
```
|
||||
|
||||
Try to unshuffle those blocks:
|
||||
```shuffle
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("YES");
|
||||
});
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showString("NO");
|
||||
});
|
||||
```
|
||||
|
||||
### Shake
|
||||
|
||||
Using the data from the **accelerometer**, it is possible to detect that the BBC micro:bit is being shaken.
|
||||
|
||||
Unshuffle the code to display a frownie when shaken.
|
||||
```shuffle
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # # # .
|
||||
# . . . #`);
|
||||
});
|
||||
```
|
||||
|
||||
### Tilting
|
||||
|
||||
Aside from shake, it is also possible to detect tilt left and right, logo up and down or face up and down.
|
||||
Let's build a rock paper scissors game where you turn the micro:bit left to display paper, right to display scissors and down to display rock.
|
||||
|
||||
Unshuffle and try this code on the micro:bit itself!
|
||||
```shuffle
|
||||
input.onGesture(Gesture.TiltLeft, () => {
|
||||
basic.showLeds(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #`);
|
||||
});
|
||||
input.onGesture(Gesture.LogoDown, () => {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. # # # .
|
||||
. . . . .`);
|
||||
});
|
||||
input.onGesture(Gesture.TiltRight, () => {
|
||||
basic.showLeds(`
|
||||
# # . . #
|
||||
# # . # .
|
||||
. . # . .
|
||||
# # . # .
|
||||
# # . . #`);
|
||||
});
|
||||
```
|
||||
|
||||
### Pins
|
||||
|
||||
It is possible to use the pins (big metal bar at the bottom of the board) as button. Hold the ``GND`` button with one hand and press the ``0`` pin
|
||||
(called ``P0``) with the other hand to trigger a pin pressed.
|
||||
|
||||
Unshuffle the blocks to display a smiley when pin ``P0`` is pressed.
|
||||
```shuffle
|
||||
input.onPinPressed(TouchPin.P0, () => {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .`);
|
||||
});
|
||||
```
|
||||
|
||||
### Your turn now!
|
||||
|
||||
Use the scree, buttons, gestures, pins to create a fun game using the micro:bit.
|
BIN
docs/static/Microsoft-logo_rgb_c-gray.png
vendored
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
docs/static/favicon.png
vendored
Normal file
After Width: | Height: | Size: 9.3 KiB |
BIN
docs/static/icons/android-chrome-144x144.png
vendored
Normal file
After Width: | Height: | Size: 1011 B |
BIN
docs/static/icons/android-chrome-192x192.png
vendored
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
docs/static/icons/android-chrome-36x36.png
vendored
Normal file
After Width: | Height: | Size: 352 B |
BIN
docs/static/icons/android-chrome-48x48.png
vendored
Normal file
After Width: | Height: | Size: 450 B |
BIN
docs/static/icons/android-chrome-72x72.png
vendored
Normal file
After Width: | Height: | Size: 565 B |
BIN
docs/static/icons/android-chrome-96x96.png
vendored
Normal file
After Width: | Height: | Size: 724 B |
BIN
docs/static/icons/apple-touch-icon-114x114.png
vendored
Normal file
After Width: | Height: | Size: 757 B |
BIN
docs/static/icons/apple-touch-icon-120x120.png
vendored
Normal file
After Width: | Height: | Size: 752 B |
BIN
docs/static/icons/apple-touch-icon-144x144.png
vendored
Normal file
After Width: | Height: | Size: 917 B |
BIN
docs/static/icons/apple-touch-icon-152x152.png
vendored
Normal file
After Width: | Height: | Size: 958 B |
BIN
docs/static/icons/apple-touch-icon-180x180.png
vendored
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
docs/static/icons/apple-touch-icon-57x57.png
vendored
Normal file
After Width: | Height: | Size: 429 B |
BIN
docs/static/icons/apple-touch-icon-60x60.png
vendored
Normal file
After Width: | Height: | Size: 480 B |
BIN
docs/static/icons/apple-touch-icon-72x72.png
vendored
Normal file
After Width: | Height: | Size: 543 B |
BIN
docs/static/icons/apple-touch-icon-76x76.png
vendored
Normal file
After Width: | Height: | Size: 557 B |
BIN
docs/static/icons/apple-touch-icon-precomposed.png
vendored
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
docs/static/icons/apple-touch-icon.png
vendored
Normal file
After Width: | Height: | Size: 1.0 KiB |
12
docs/static/icons/browserconfig.xml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<browserconfig>
|
||||
<msapplication>
|
||||
<tile>
|
||||
<square70x70logo src="/static/icons/mstile-70x70.png"/>
|
||||
<square150x150logo src="/static/icons/mstile-150x150.png"/>
|
||||
<square310x310logo src="/static/icons/mstile-310x310.png"/>
|
||||
<wide310x150logo src="/static/icons/mstile-310x150.png"/>
|
||||
<TileColor>#9f00a7</TileColor>
|
||||
</tile>
|
||||
</msapplication>
|
||||
</browserconfig>
|
BIN
docs/static/icons/favicon-16x16.png
vendored
Normal file
After Width: | Height: | Size: 274 B |
BIN
docs/static/icons/favicon-32x32.png
vendored
Normal file
After Width: | Height: | Size: 382 B |
BIN
docs/static/icons/favicon-96x96.png
vendored
Normal file
After Width: | Height: | Size: 724 B |
BIN
docs/static/icons/favicon.ico
vendored
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
docs/static/icons/mstile-144x144.png
vendored
Normal file
After Width: | Height: | Size: 1011 B |
BIN
docs/static/icons/mstile-150x150.png
vendored
Normal file
After Width: | Height: | Size: 918 B |
BIN
docs/static/icons/mstile-310x150.png
vendored
Normal file
After Width: | Height: | Size: 971 B |
BIN
docs/static/icons/mstile-310x310.png
vendored
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
docs/static/icons/mstile-70x70.png
vendored
Normal file
After Width: | Height: | Size: 682 B |
59
docs/static/icons/safari-pinned-tab.svg
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="319.000000pt" height="319.000000pt" viewBox="0 0 319.000000 319.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
<metadata>
|
||||
Created by potrace 1.11, written by Peter Selinger 2001-2013
|
||||
</metadata>
|
||||
<g transform="translate(0.000000,319.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M145 2888 c-49 -17 -92 -55 -114 -101 -21 -43 -21 -46 -21 -1110 l0
|
||||
-1067 40 0 40 0 0 -135 c0 -78 4 -135 9 -135 6 0 11 90 13 218 3 207 4 218 26
|
||||
249 28 40 98 68 147 59 46 -9 102 -59 112 -99 5 -18 7 -127 5 -244 l-3 -212
|
||||
-107 -4 -107 -3 120 0 120 1 3 158 3 158 142 -3 142 -3 3 -157 c1 -87 7 -158
|
||||
12 -158 5 0 10 100 12 227 3 254 8 274 78 320 60 41 143 20 187 -46 22 -33 23
|
||||
-41 23 -267 0 -149 4 -234 10 -234 6 0 10 60 10 160 l0 160 190 0 190 0 0
|
||||
-161 c0 -104 3 -158 10 -154 6 4 10 93 10 233 0 207 2 230 20 259 40 67 112
|
||||
88 182 54 78 -38 83 -53 86 -319 2 -135 7 -232 13 -232 5 0 9 68 9 160 l0 160
|
||||
185 0 185 0 0 -154 c0 -93 4 -157 10 -161 7 -4 10 66 10 202 0 114 5 225 10
|
||||
245 34 121 169 154 249 63 l31 -36 0 -234 c0 -145 4 -236 10 -240 7 -4 10 50
|
||||
10 154 l0 161 150 0 150 0 0 -160 c0 -100 4 -160 10 -160 6 0 10 83 10 228 0
|
||||
263 4 280 81 320 51 27 104 24 151 -9 54 -39 58 -58 58 -294 0 -137 4 -215 10
|
||||
-215 6 0 10 53 10 140 l0 140 45 0 44 0 4 -77 c1 -43 4 435 5 1062 1 1092 1
|
||||
1142 -17 1180 -24 53 -55 83 -105 106 -39 18 -96 19 -1466 18 -967 0 -1435 -4
|
||||
-1455 -11z m1203 -635 l3 -73 -41 0 -40 0 0 76 0 75 38 -3 37 -3 3 -72z m587
|
||||
2 l0 -70 -37 -3 -38 -3 0 76 0 76 38 -3 37 -3 0 -70z m-880 -280 l0 -70 -40 0
|
||||
-40 0 -3 49 c-2 27 -1 60 3 73 5 21 11 24 43 21 l37 -3 0 -70z m589 59 c9 -23
|
||||
7 -107 -3 -122 -5 -8 -22 -12 -42 -10 l-34 3 -3 59 c-2 32 -1 65 2 72 8 20 72
|
||||
18 80 -2z m584 -61 l3 -73 -41 0 -40 0 0 68 c0 38 3 72 7 76 4 4 21 6 38 4
|
||||
l30 -3 3 -72z m-880 -5 l-3 -73 -35 0 -35 0 -3 73 -3 72 41 0 41 0 -3 -72z
|
||||
m570 -5 l3 -73 -41 0 -40 0 0 68 c0 38 3 72 7 76 4 4 21 6 38 4 l30 -3 3 -72z
|
||||
m-1388 -363 l0 -180 -185 0 -185 0 0 180 0 180 185 0 185 0 0 -180z m2500 0
|
||||
l0 -180 -180 0 -180 0 0 180 0 180 180 0 180 0 0 -180z m-1982 161 c9 -5 12
|
||||
-27 10 -72 l-3 -64 -40 0 -40 0 -3 58 c-2 35 2 64 9 73 13 15 47 18 67 5z
|
||||
m307 -66 l0 -70 -37 -3 -38 -3 0 76 0 76 38 -3 37 -3 0 -70z m873 -2 l3 -73
|
||||
-41 0 -40 0 0 68 c0 38 3 72 7 76 4 4 21 6 38 4 l30 -3 3 -72z m-590 -10 l3
|
||||
-73 -41 0 -40 0 0 68 c0 38 3 72 7 76 4 4 21 6 38 4 l30 -3 3 -72z m280 68 c9
|
||||
-5 12 -27 10 -72 l-3 -64 -40 0 -40 0 -3 64 c-3 67 4 81 43 81 11 0 26 -4 33
|
||||
-9z m-568 -341 l0 -70 -40 0 -40 0 0 70 0 70 40 0 40 0 0 -70z m590 0 l0 -70
|
||||
-40 0 -40 0 0 70 0 70 40 0 40 0 0 -70z m-292 -27 l3 -73 -41 0 -40 0 0 68 c0
|
||||
38 3 72 7 76 4 4 21 6 38 4 l30 -3 3 -72z m-3 -253 l0 -65 -42 -3 -43 -3 0 71
|
||||
0 71 43 -3 42 -3 0 -65z"/>
|
||||
<path d="M294 1689 c-25 -13 -54 -60 -54 -89 0 -55 47 -100 105 -100 42 0 75
|
||||
20 94 57 15 29 14 49 -4 88 -24 49 -88 69 -141 44z"/>
|
||||
<path d="M2779 1671 c-23 -23 -29 -38 -29 -71 0 -91 106 -135 171 -71 64 65
|
||||
20 171 -71 171 -33 0 -48 -6 -71 -29z"/>
|
||||
<path d="M845 836 c-88 -40 -106 -150 -34 -210 24 -20 41 -26 81 -26 44 0 54
|
||||
4 84 34 32 32 40 56 34 111 -7 70 -99 121 -165 91z"/>
|
||||
<path d="M1543 836 c-89 -40 -97 -178 -13 -221 66 -34 141 -10 175 55 19 37
|
||||
19 64 -1 105 -28 60 -101 87 -161 61z"/>
|
||||
<path d="M2255 836 c-86 -38 -105 -146 -35 -208 24 -23 40 -28 79 -28 143 0
|
||||
173 188 38 239 -36 14 -45 13 -82 -3z"/>
|
||||
<path d="M192 820 c-118 -72 -38 -255 98 -225 45 10 90 67 90 116 0 105 -99
|
||||
163 -188 109z"/>
|
||||
<path d="M2875 831 c-90 -40 -97 -169 -12 -221 122 -75 250 92 149 193 -32 31
|
||||
-98 45 -137 28z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.6 KiB |
@ -43,7 +43,7 @@ namespace radio {
|
||||
*/
|
||||
//% help=radio/send-number
|
||||
//% weight=60
|
||||
//% blockId=radio_datagram_send block="send number %MESSAGE" blockGap=8
|
||||
//% blockId=radio_datagram_send block="send number %value" blockGap=8
|
||||
void sendNumber(int value) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
uint32_t t = system_timer_current_time();
|
||||
@ -60,7 +60,7 @@ namespace radio {
|
||||
*/
|
||||
//% help=radio/send-value
|
||||
//% weight=59
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value"
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value" blockGap=8
|
||||
void sendValue(StringData* name, int value) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
|
||||
@ -81,6 +81,22 @@ namespace radio {
|
||||
uBit.radio.datagram.send(buf, 13 + len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a number over radio to any connected micro:bit in the group.
|
||||
*/
|
||||
//% help=radio/send-string
|
||||
//% weight=58
|
||||
//% blockId=radio_datagram_send_string block="send string %msg"
|
||||
void sendString(StringData* msg) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
|
||||
ManagedString s(msg);
|
||||
if (s.length() > MICROBIT_RADIO_MAX_PACKET_SIZE)
|
||||
s = s.substring(0, MICROBIT_RADIO_MAX_PACKET_SIZE);
|
||||
|
||||
uBit.radio.datagram.send(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a value sent with `stream value` and writes it
|
||||
* to the serial stream as JSON
|
||||
@ -159,7 +175,19 @@ namespace radio {
|
||||
packet = uBit.radio.datagram.recv();
|
||||
return receivedNumberAt(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the next packet as a string and returns it.
|
||||
*/
|
||||
//% blockId=radio_datagram_receive_string block="receive string" blockGap=8
|
||||
//% weight=44
|
||||
//% help=radio/receive-string
|
||||
StringData* receiveString() {
|
||||
if (radioEnable() != MICROBIT_OK) return ManagedString().leakData();
|
||||
packet = uBit.radio.datagram.recv();
|
||||
return ManagedString(packet).leakData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator.
|
||||
* namespace=radio
|
||||
|
20
libs/microbit-radio/shims.d.ts
vendored
@ -10,7 +10,7 @@ declare namespace radio {
|
||||
*/
|
||||
//% help=radio/send-number
|
||||
//% weight=60
|
||||
//% blockId=radio_datagram_send block="send number %MESSAGE" blockGap=8 shim=radio::sendNumber
|
||||
//% blockId=radio_datagram_send block="send number %value" blockGap=8 shim=radio::sendNumber
|
||||
function sendNumber(value: number): void;
|
||||
|
||||
/**
|
||||
@ -21,9 +21,17 @@ declare namespace radio {
|
||||
*/
|
||||
//% help=radio/send-value
|
||||
//% weight=59
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value" shim=radio::sendValue
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value" blockGap=8 shim=radio::sendValue
|
||||
function sendValue(name: string, value: number): void;
|
||||
|
||||
/**
|
||||
* Broadcasts a number over radio to any connected micro:bit in the group.
|
||||
*/
|
||||
//% help=radio/send-string
|
||||
//% weight=58
|
||||
//% blockId=radio_datagram_send_string block="send string %msg" shim=radio::sendString
|
||||
function sendString(msg: string): void;
|
||||
|
||||
/**
|
||||
* Reads a value sent with `stream value` and writes it
|
||||
* to the serial stream as JSON
|
||||
@ -58,6 +66,14 @@ declare namespace radio {
|
||||
//% blockId=radio_datagram_receive block="receive number" blockGap=8 shim=radio::receiveNumber
|
||||
function receiveNumber(): number;
|
||||
|
||||
/**
|
||||
* Reads the next packet as a string and returns it.
|
||||
*/
|
||||
//% blockId=radio_datagram_receive_string block="receive string" blockGap=8
|
||||
//% weight=44
|
||||
//% help=radio/receive-string shim=radio::receiveString
|
||||
function receiveString(): string;
|
||||
|
||||
/**
|
||||
* Gets the received signal strength indicator (RSSI) from the packet received by ``receive number``. Not supported in simulator.
|
||||
* namespace=radio
|
||||
|
28
libs/microbit/dal.d.ts
vendored
@ -86,7 +86,7 @@ declare const enum DAL {
|
||||
MICROBIT_DFU_HISTOGRAM_HEIGHT = 5,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitEventService.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitIOPinService.h
|
||||
MICROBIT_IO_PIN_SERVICE_PINCOUNT = 20,
|
||||
MICROBIT_IO_PIN_SERVICE_PINCOUNT = 19,
|
||||
MICROBIT_IO_PIN_SERVICE_DATA_SIZE = 10,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//bluetooth/MicroBitLEDService.h
|
||||
MICROBIT_BLE_MAXIMUM_SCROLLTEXT = 20,
|
||||
@ -208,6 +208,7 @@ declare const enum DAL {
|
||||
MMA8653_SAMPLE_RANGES = 3,
|
||||
MMA8653_SAMPLE_RATES = 8,
|
||||
MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE = 1,
|
||||
MICROBIT_ACCELEROMETER_EVT_NONE = 0,
|
||||
MICROBIT_ACCELEROMETER_EVT_TILT_UP = 1,
|
||||
MICROBIT_ACCELEROMETER_EVT_TILT_DOWN = 2,
|
||||
MICROBIT_ACCELEROMETER_EVT_TILT_LEFT = 3,
|
||||
@ -229,18 +230,6 @@ declare const enum DAL {
|
||||
MICROBIT_ACCELEROMETER_GESTURE_DAMPING = 10,
|
||||
MICROBIT_ACCELEROMETER_SHAKE_DAMPING = 10,
|
||||
MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD = 4,
|
||||
GESTURE_NONE = 0,
|
||||
GESTURE_UP = 1,
|
||||
GESTURE_DOWN = 2,
|
||||
GESTURE_LEFT = 3,
|
||||
GESTURE_RIGHT = 4,
|
||||
GESTURE_FACE_UP = 5,
|
||||
GESTURE_FACE_DOWN = 6,
|
||||
GESTURE_FREEFALL = 7,
|
||||
GESTURE_3G = 8,
|
||||
GESTURE_6G = 9,
|
||||
GESTURE_8G = 10,
|
||||
GESTURE_SHAKE = 11,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitButton.h
|
||||
MICROBIT_BUTTON_EVT_DOWN = 1,
|
||||
MICROBIT_BUTTON_EVT_UP = 2,
|
||||
@ -343,14 +332,22 @@ declare const enum DAL {
|
||||
IO_STATUS_ANALOG_IN = 0x04,
|
||||
IO_STATUS_ANALOG_OUT = 0x08,
|
||||
IO_STATUS_TOUCH_IN = 0x10,
|
||||
IO_STATUS_EVENTBUS_ENABLED = 0x80,
|
||||
IO_STATUS_EVENT_ON_EDGE = 0x20,
|
||||
IO_STATUS_EVENT_PULSE_ON_EDGE = 0x40,
|
||||
MICROBIT_PIN_MAX_OUTPUT = 1023,
|
||||
MICROBIT_PIN_MAX_SERVO_RANGE = 180,
|
||||
MICROBIT_PIN_DEFAULT_SERVO_RANGE = 2000,
|
||||
MICROBIT_PIN_DEFAULT_SERVO_CENTER = 1500,
|
||||
MICROBIT_PIN_EVENT_NONE = 0,
|
||||
MICROBIT_PIN_EVENT_ON_EDGE = 1,
|
||||
MICROBIT_PIN_EVENT_ON_PULSE = 2,
|
||||
MICROBIT_PIN_EVENT_ON_TOUCH = 3,
|
||||
MICROBIT_PIN_EVT_RISE = 2,
|
||||
MICROBIT_PIN_EVT_FALL = 3,
|
||||
MICROBIT_PIN_EVT_PULSE_HI = 4,
|
||||
MICROBIT_PIN_EVT_PULSE_LO = 5,
|
||||
PIN_CAPABILITY_DIGITAL = 0x01,
|
||||
PIN_CAPABILITY_ANALOG = 0x02,
|
||||
PIN_CAPABILITY_TOUCH = 0x04,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/MicroBitRadio.h
|
||||
MICROBIT_RADIO_STATUS_INITIALISED = 0x0001,
|
||||
MICROBIT_RADIO_BASE_ADDRESS = 0x75626974,
|
||||
@ -388,6 +385,7 @@ declare const enum DAL {
|
||||
MICROBIT_THERMOMETER_PERIOD = 1000,
|
||||
MICROBIT_THERMOMETER_EVT_UPDATE = 1,
|
||||
MICROBIT_THERMOMETER_ADDED_TO_IDLE = 2,
|
||||
// built/yt/yotta_modules/microbit-dal/inc//drivers/TimedInterruptIn.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//platform/yotta_cfg_mappings.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//types/ManagedString.h
|
||||
// built/yt/yotta_modules/microbit-dal/inc//types/ManagedType.h
|
||||
|
18
libs/microbit/enums.d.ts
vendored
@ -69,42 +69,42 @@ declare namespace basic {
|
||||
* Raised when shaken
|
||||
*/
|
||||
//% block=shake
|
||||
Shake = 11, // GESTURE_SHAKE
|
||||
Shake = 11, // MICROBIT_ACCELEROMETER_EVT_SHAKE
|
||||
/**
|
||||
* Raised when the logo is upward and the screen is vertical
|
||||
*/
|
||||
//% block="logo up"
|
||||
LogoUp = 1, // GESTURE_UP
|
||||
LogoUp = 1, // MICROBIT_ACCELEROMETER_EVT_TILT_UP
|
||||
/**
|
||||
* Raised when the logo is downward and the screen is vertical
|
||||
*/
|
||||
//% block="logo down"
|
||||
LogoDown = 2, // GESTURE_DOWN
|
||||
LogoDown = 2, // MICROBIT_ACCELEROMETER_EVT_TILT_DOWN
|
||||
/**
|
||||
* Raised when the screen is pointing down and the board is horizontal
|
||||
*/
|
||||
//% block="screen up"
|
||||
ScreenUp = 5, // GESTURE_FACE_UP
|
||||
ScreenUp = 5, // MICROBIT_ACCELEROMETER_EVT_FACE_UP
|
||||
/**
|
||||
* Raised when the screen is pointing up and the board is horizontal
|
||||
*/
|
||||
//% block="screen down"
|
||||
ScreenDown = 6, // GESTURE_FACE_DOWN
|
||||
ScreenDown = 6, // MICROBIT_ACCELEROMETER_EVT_FACE_DOWN
|
||||
/**
|
||||
* Raised when the screen is pointing left
|
||||
*/
|
||||
//% block="tilt left"
|
||||
TiltLeft = 3, // GESTURE_LEFT
|
||||
TiltLeft = 3, // MICROBIT_ACCELEROMETER_EVT_TILT_LEFT
|
||||
/**
|
||||
* Raised when the screen is pointing right
|
||||
*/
|
||||
//% block="tilt right"
|
||||
TiltRight = 4, // GESTURE_RIGHT
|
||||
TiltRight = 4, // MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT
|
||||
/**
|
||||
* Raised when the board is falling!
|
||||
*/
|
||||
//% block="free fall"
|
||||
FreeFall = 7, // GESTURE_FREEFALL
|
||||
FreeFall = 7, // MICROBIT_ACCELEROMETER_EVT_FREEFALL
|
||||
}
|
||||
declare namespace input {
|
||||
}
|
||||
@ -281,7 +281,5 @@ declare namespace serial {
|
||||
Int32BE = 10,
|
||||
// UInt32,
|
||||
}
|
||||
declare namespace storage {
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
@ -59,42 +59,42 @@ enum class Gesture {
|
||||
* Raised when shaken
|
||||
*/
|
||||
//% block=shake
|
||||
Shake = GESTURE_SHAKE,
|
||||
Shake = MICROBIT_ACCELEROMETER_EVT_SHAKE,
|
||||
/**
|
||||
* Raised when the logo is upward and the screen is vertical
|
||||
*/
|
||||
//% block="logo up"
|
||||
LogoUp = GESTURE_UP,
|
||||
LogoUp = MICROBIT_ACCELEROMETER_EVT_TILT_UP,
|
||||
/**
|
||||
* Raised when the logo is downward and the screen is vertical
|
||||
*/
|
||||
//% block="logo down"
|
||||
LogoDown = GESTURE_DOWN,
|
||||
LogoDown = MICROBIT_ACCELEROMETER_EVT_TILT_DOWN,
|
||||
/**
|
||||
* Raised when the screen is pointing down and the board is horizontal
|
||||
*/
|
||||
//% block="screen up"
|
||||
ScreenUp = GESTURE_FACE_UP,
|
||||
ScreenUp = MICROBIT_ACCELEROMETER_EVT_FACE_UP,
|
||||
/**
|
||||
* Raised when the screen is pointing up and the board is horizontal
|
||||
*/
|
||||
//% block="screen down"
|
||||
ScreenDown = GESTURE_FACE_DOWN,
|
||||
ScreenDown = MICROBIT_ACCELEROMETER_EVT_FACE_DOWN,
|
||||
/**
|
||||
* Raised when the screen is pointing left
|
||||
*/
|
||||
//% block="tilt left"
|
||||
TiltLeft = GESTURE_LEFT,
|
||||
TiltLeft = MICROBIT_ACCELEROMETER_EVT_TILT_LEFT,
|
||||
/**
|
||||
* Raised when the screen is pointing right
|
||||
*/
|
||||
//% block="tilt right"
|
||||
TiltRight = GESTURE_RIGHT,
|
||||
TiltRight = MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT,
|
||||
/**
|
||||
* Raised when the board is falling!
|
||||
*/
|
||||
//% block="free fall"
|
||||
FreeFall = GESTURE_FREEFALL
|
||||
FreeFall = MICROBIT_ACCELEROMETER_EVT_FREEFALL
|
||||
};
|
||||
|
||||
//% color=300 weight=99
|
||||
|
@ -11,7 +11,7 @@ namespace pins {
|
||||
* @param toLow the lower bound of the value's target range
|
||||
* @param toHigh the upper bound of the value's target range, eg: 4
|
||||
*/
|
||||
//% help=pins/map weight=15
|
||||
//% help=pins/map weight=3
|
||||
//% blockId=math_map block="map %value|from low %fromLow|from high %fromHigh|to low %toLow|to high %toHigh"
|
||||
export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {
|
||||
return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;
|
||||
@ -20,6 +20,8 @@ namespace pins {
|
||||
/**
|
||||
* Read one number from 7-bit I2C address.
|
||||
*/
|
||||
//% help=pins/i2c-read-number
|
||||
//% blockId=pins_i2c_readnumber block="i2c read number|at address %address|of format %format=i2c_sizeof" weight=7
|
||||
export function i2cReadNumber(address: number, format: NumberFormat): number {
|
||||
let buf = pins.i2cReadBuffer(address, pins.sizeOf(format))
|
||||
return buf.getNumber(format, 0)
|
||||
@ -28,6 +30,8 @@ namespace pins {
|
||||
/**
|
||||
* Write one number to a 7-bit I2C address.
|
||||
*/
|
||||
//% help=pins/i2c-write-number
|
||||
//% blockId=i2c_writenumber block="i2c write number|at address %address|with value %value|of format %format=i2c_sizeof" weight=6
|
||||
export function i2cWriteNumber(address: number, value: number, format: NumberFormat): void {
|
||||
let buf = createBuffer(pins.sizeOf(format))
|
||||
buf.setNumber(format, 0, value)
|
||||
@ -37,6 +41,7 @@ namespace pins {
|
||||
/**
|
||||
* Get the size in bytes of specified number format.
|
||||
*/
|
||||
//%
|
||||
export function sizeOf(format: NumberFormat) {
|
||||
switch (format) {
|
||||
case NumberFormat.Int8LE:
|
||||
|
@ -26,8 +26,7 @@
|
||||
"pins.ts",
|
||||
"serial.cpp",
|
||||
"serial.ts",
|
||||
"buffer.cpp",
|
||||
"storage.cpp"
|
||||
"buffer.cpp"
|
||||
],
|
||||
"public": true,
|
||||
"dependencies": {},
|
||||
|
33
libs/microbit/shims.d.ts
vendored
@ -597,37 +597,4 @@ 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.
|
||||
|
@ -1,43 +0,0 @@
|
||||
#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();
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-microbit",
|
||||
"version": "0.2.111",
|
||||
"version": "0.2.118",
|
||||
"description": "BBC micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.2.122"
|
||||
"pxt-core": "0.2.129"
|
||||
}
|
||||
}
|
||||
|
@ -53,17 +53,17 @@
|
||||
"deployDrives": "^MICROBIT"
|
||||
},
|
||||
"runtime": {
|
||||
"mathBlocks": true,
|
||||
"loopsBlocks": true,
|
||||
"logicBlocks": true,
|
||||
"variablesBlocks": true
|
||||
"mathBlocks": true,
|
||||
"loopsBlocks": true,
|
||||
"logicBlocks": true,
|
||||
"variablesBlocks": true
|
||||
},
|
||||
"simulator": {
|
||||
"autoRun": true,
|
||||
"aspectRatio": 1.22
|
||||
},
|
||||
"compileService": {
|
||||
"gittag": "v0.1.8",
|
||||
"gittag": "v0.1.9",
|
||||
"serviceId": "ws"
|
||||
},
|
||||
"serial": {
|
||||
@ -72,11 +72,13 @@
|
||||
"log": true
|
||||
},
|
||||
"appTheme": {
|
||||
"accentColor": "#5C2D91",
|
||||
"logoUrl": "https://m.pxt.io/about",
|
||||
"logo": "./static/microbit.simplified.svg",
|
||||
"docsLogo": "./static/microbit.simplified.svg",
|
||||
"portraitLogo":"./static/microbit.simplified.svg",
|
||||
"portraitLogo": "./static/microbit.simplified.svg",
|
||||
"footerLogo": "./static/microbit.simplified.svg",
|
||||
"organizationLogo": "./static/Microsoft-logo_rgb_c-gray.png",
|
||||
"homeUrl": "https://m.pxt.io/",
|
||||
"embedUrl": "https://m.pxt.io/",
|
||||
"koduUrl": "https://www.kodugamelab.com/bbc-microbit/",
|
||||
@ -102,4 +104,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -457,6 +457,10 @@ namespace pxsim.radio {
|
||||
board().radio.datagram.send([value]);
|
||||
}
|
||||
|
||||
export function sendString(msg: string): void {
|
||||
board().radio.datagram.send(msg);
|
||||
}
|
||||
|
||||
export function writeValueToSerial(): void {
|
||||
let b = board();
|
||||
let v = b.radio.datagram.recv().data[0];
|
||||
@ -468,11 +472,23 @@ namespace pxsim.radio {
|
||||
}
|
||||
|
||||
export function receiveNumber(): number {
|
||||
return board().radio.datagram.recv().data[0];
|
||||
let buffer = board().radio.datagram.recv().data;
|
||||
if (buffer instanceof Array) return buffer[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function receiveString(): string {
|
||||
let buffer = board().radio.datagram.recv().data;
|
||||
if (typeof buffer === "string") return <string>buffer;
|
||||
return "";
|
||||
}
|
||||
|
||||
export function receivedNumberAt(index: number): number {
|
||||
return board().radio.datagram.lastReceived.data[index] || 0;
|
||||
let buffer = board().radio.datagram.recv().data;
|
||||
if (buffer instanceof Array) return buffer[index] || 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function receivedSignalStrength(): number {
|
||||
|
@ -244,8 +244,9 @@ namespace pxsim.micro_bit {
|
||||
let state = this.board;
|
||||
if (!state || !state.usesHeading) return;
|
||||
if (!this.headInitialized) {
|
||||
let p = this.head.firstChild.nextSibling as SVGPathElement;
|
||||
p.setAttribute("d", "m269.9,50.134647l0,0l-39.5,0l0,0c-14.1,0.1 -24.6,10.7 -24.6,24.8c0,13.9 10.4,24.4 24.3,24.7l0,0l39.6,0c14.2,0 40.36034,-22.97069 40.36034,-24.85394c0,-1.88326 -26.06034,-24.54606 -40.16034,-24.64606m-0.2,39l0,0l-39.3,0c-7.7,-0.1 -14,-6.4 -14,-14.2c0,-7.8 6.4,-14.2 14.2,-14.2l39.1,0c7.8,0 14.2,6.4 14.2,14.2c0,7.9 -6.4,14.2 -14.2,14.2l0,0l0,0z");
|
||||
let p = svg.path(this.head, "sim-theme", "m269.9,50.134647l0,0l-39.5,0l0,0c-14.1,0.1 -24.6,10.7 -24.6,24.8c0,13.9 10.4,24.4 24.3,24.7l0,0l39.6,0c14.2,0 40.36034,-22.97069 40.36034,-24.85394c0,-1.88326 -26.06034,-24.54606 -40.16034,-24.64606m-0.2,39l0,0l-39.3,0c-7.7,-0.1 -14,-6.4 -14,-14.2c0,-7.8 6.4,-14.2 14.2,-14.2l39.1,0c7.8,0 14.2,6.4 14.2,14.2c0,7.9 -6.4,14.2 -14.2,14.2l0,0l0,0z");
|
||||
this.logos.push(p);
|
||||
this.updateTheme();
|
||||
let pt = this.element.createSVGPoint();
|
||||
svg.buttonEvents(
|
||||
this.head,
|
||||
@ -253,13 +254,12 @@ namespace pxsim.micro_bit {
|
||||
let cur = svg.cursorPoint(pt, this.element, ev);
|
||||
state.heading = Math.floor(Math.atan2(cur.y - yc, cur.x - xc) * 180 / Math.PI + 90);
|
||||
if (state.heading < 0) state.heading += 360;
|
||||
console.log('heading: ' + state.heading)
|
||||
this.updateHeading();
|
||||
});
|
||||
this.headInitialized = true;
|
||||
}
|
||||
|
||||
let txt = state.heading.toString() + '°';
|
||||
let txt = state.heading.toString() + "°";
|
||||
if (txt != this.headText.textContent) {
|
||||
svg.rotateElement(this.head, xc, yc, state.heading + 180);
|
||||
this.headText.textContent = txt;
|
||||
@ -273,7 +273,7 @@ namespace pxsim.micro_bit {
|
||||
let now = Date.now();
|
||||
if (now - this.lastFlashTime > 150) {
|
||||
this.lastFlashTime = now;
|
||||
svg.animate(this.systemLed, 'sim-flash')
|
||||
svg.animate(this.systemLed, "sim-flash")
|
||||
}
|
||||
}
|
||||
|
||||
@ -452,6 +452,9 @@ svg.sim.grayscale {
|
||||
animation-duration: 0.4s;
|
||||
animation-timing-function: ease-in;
|
||||
}
|
||||
.sim-button-label {
|
||||
fill:#fff;
|
||||
}
|
||||
|
||||
@keyframes sim-flash-stroke-animation {
|
||||
from { stroke: yellow; }
|
||||
@ -478,11 +481,11 @@ svg.sim.grayscale {
|
||||
this.display = svg.path(this.g, "sim-display", "M333.8,310.3H165.9c-8.3,0-15-6.7-15-15V127.5c0-8.3,6.7-15,15-15h167.8c8.3,0,15,6.7,15,15v167.8C348.8,303.6,342.1,310.3,333.8,310.3z");
|
||||
|
||||
this.logos = [];
|
||||
this.logos.push(svg.child(this.g, "polygon", { class: "sim-theme", points: "115,56.7 173.1,0 115,0" }));
|
||||
this.logos.push(svg.path(this.g, "sim-theme", "M114.2,0H25.9C12.1,2.1,0,13.3,0,27.7v83.9L114.2,0z"));
|
||||
this.logos.push(svg.child(this.g, "polygon", { class: "sim-theme", points: "173,27.9 202.5,0 173,0" }));
|
||||
this.logos.push(svg.child(this.g, "polygon", { class: "sim-theme", points: "54.1,242.4 54.1,274.1 22.4,274.1" }));
|
||||
this.logos.push(svg.child(this.g, "polygon", { class: "sim-theme", points: "446.2,164.6 446.2,132.8 477.9,132.8" }));
|
||||
//this.logos.push(svg.child(this.g, "polygon", { class: "sim-theme", points: "115,56.7 173.1,0 115,0" }));
|
||||
//this.logos.push(svg.path(this.g, "sim-theme", "M114.2,0H25.9C12.1,2.1,0,13.3,0,27.7v83.9L114.2,0z"));
|
||||
//this.logos.push(svg.child(this.g, "polygon", { class: "sim-theme", points: "173,27.9 202.5,0 173,0" }));
|
||||
//this.logos.push(svg.child(this.g, "polygon", { class: "sim-theme", points: "54.1,242.4 54.1,274.1 22.4,274.1" }));
|
||||
//this.logos.push(svg.child(this.g, "polygon", { class: "sim-theme", points: "446.2,164.6 446.2,132.8 477.9,132.8" }));
|
||||
|
||||
// leds
|
||||
this.leds = [];
|
||||
@ -501,9 +504,9 @@ svg.sim.grayscale {
|
||||
// head
|
||||
this.head = <SVGGElement>svg.child(this.g, "g", {});
|
||||
svg.child(this.head, "circle", { cx: 258, cy: 75, r: 100, fill: "transparent" })
|
||||
this.logos.push(svg.path(this.head, "sim-theme", "M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2"));
|
||||
this.logos.push(svg.path(this.head, "sim-theme", "M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7"));
|
||||
this.logos.push(svg.path(this.head, "sim-theme", "M269.7,80.3c2.9,0,5.3-2.4,5.3-5.3c0-2.9-2.4-5.3-5.3-5.3c-2.9,0-5.3,2.4-5.3,5.3C264.4,77.9,266.8,80.3,269.7,80.3"));
|
||||
//this.logos.push(svg.path(this.head, "sim-theme", "M269.9,50.2L269.9,50.2l-39.5,0v0c-14.1,0.1-24.6,10.7-24.6,24.8c0,13.9,10.4,24.4,24.3,24.7v0h39.6c14.2,0,24.8-10.6,24.8-24.7C294.5,61,284,50.3,269.9,50.2 M269.7,89.2L269.7,89.2l-39.3,0c-7.7-0.1-14-6.4-14-14.2c0-7.8,6.4-14.2,14.2-14.2h39.1c7.8,0,14.2,6.4,14.2,14.2C283.9,82.9,277.5,89.2,269.7,89.2"));
|
||||
//this.logos.push(svg.path(this.head, "sim-theme", "M230.6,69.7c-2.9,0-5.3,2.4-5.3,5.3c0,2.9,2.4,5.3,5.3,5.3c2.9,0,5.3-2.4,5.3-5.3C235.9,72.1,233.5,69.7,230.6,69.7"));
|
||||
//this.logos.push(svg.path(this.head, "sim-theme", "M269.7,80.3c2.9,0,5.3-2.4,5.3-5.3c0-2.9-2.4-5.3-5.3-5.3c-2.9,0-5.3,2.4-5.3,5.3C264.4,77.9,266.8,80.3,269.7,80.3"));
|
||||
this.headText = <SVGTextElement>svg.child(this.g, "text", { x: 310, y: 100, class: "sim-text" })
|
||||
|
||||
// https://www.microbit.co.uk/device/pins
|
||||
@ -567,9 +570,10 @@ svg.sim.grayscale {
|
||||
svg.path(this.g, "sim-label", "M35.7,376.4c0-2.8,2.1-5.1,5.5-5.1c3.3,0,5.5,2.4,5.5,5.1v4.7c0,2.8-2.2,5.1-5.5,5.1c-3.3,0-5.5-2.4-5.5-5.1V376.4zM43.3,376.4c0-1.3-0.8-2.3-2.2-2.3c-1.3,0-2.1,1.1-2.1,2.3v4.7c0,1.2,0.8,2.3,2.1,2.3c1.3,0,2.2-1.1,2.2-2.3V376.4z");
|
||||
svg.path(this.g, "sim-label", "M136.2,374.1c2.8,0,3.4-0.8,3.4-2.5h2.9v14.3h-3.4v-9.5h-3V374.1z");
|
||||
svg.path(this.g, "sim-label", "M248.6,378.5c1.7-1,3-1.7,3-3.1c0-1.1-0.7-1.6-1.6-1.6c-1,0-1.8,0.6-1.8,2.1h-3.3c0-2.6,1.8-4.6,5.1-4.6c2.6,0,4.9,1.3,4.9,4.3c0,2.4-2.3,3.9-3.8,4.7c-2,1.3-2.5,1.8-2.5,2.9h6.1v2.7h-10C244.8,381.2,246.4,379.9,248.6,378.5z");
|
||||
svg.path(this.g, "sim-label", "M48.1,270.9l-0.6-1.7h-5.1l-0.6,1.7h-3.5l5.1-14.3h3.1l5.2,14.3H48.1z M45,260.7l-1.8,5.9h3.5L45,260.7z");
|
||||
|
||||
svg.path(this.g, "sim-label", "M449.1,135.8h5.9c3.9,0,4.7,2.4,4.7,3.9c0,1.8-1.4,2.9-2.5,3.2c0.9,0,2.6,1.1,2.6,3.3c0,1.5-0.8,4-4.7,4h-6V135.8zM454.4,141.7c1.6,0,2-1,2-1.7c0-0.6-0.3-1.7-2-1.7h-2v3.4H454.4z M452.4,144.1v3.5h2.1c1.6,0,2-1,2-1.8c0-0.7-0.4-1.8-2-1.8H452.4z")
|
||||
svg.path(this.g, "sim-button-label", "M48.1,270.9l-0.6-1.7h-5.1l-0.6,1.7h-3.5l5.1-14.3h3.1l5.2,14.3H48.1z M45,260.7l-1.8,5.9h3.5L45,260.7z");
|
||||
svg.path(this.g, "sim-button-label", "M449.1,135.8h5.9c3.9,0,4.7,2.4,4.7,3.9c0,1.8-1.4,2.9-2.5,3.2c0.9,0,2.6,1.1,2.6,3.3c0,1.5-0.8,4-4.7,4h-6V135.8zM454.4,141.7c1.6,0,2-1,2-1.7c0-0.6-0.3-1.7-2-1.7h-2v3.4H454.4z M452.4,144.1v3.5h2.1c1.6,0,2-1,2-1.8c0-0.7-0.4-1.8-2-1.8H452.4z")
|
||||
|
||||
svg.path(this.g, "sim-label", "M352.1,381.1c0,1.6,0.9,2.5,2.2,2.5c1.2,0,1.9-0.9,1.9-1.9c0-1.2-0.6-2-2.1-2h-1.3v-2.6h1.3c1.5,0,1.9-0.7,1.9-1.8c0-1.1-0.7-1.6-1.6-1.6c-1.4,0-1.8,0.8-1.8,2.1h-3.3c0-2.4,1.5-4.6,5.1-4.6c2.6,0,5,1.3,5,4c0,1.6-1,2.8-2.1,3.2c1.3,0.5,2.3,1.6,2.3,3.5c0,2.7-2.4,4.3-5.2,4.3c-3.5,0-5.5-2.1-5.5-5.1H352.1z")
|
||||
svg.path(this.g, "sim-label", "M368.5,385.9h-3.1l-5.1-14.3h3.5l3.1,10.1l3.1-10.1h3.6L368.5,385.9z")
|
||||
svg.path(this.g, "sim-label", "M444.4,378.3h7.4v2.5h-1.5c-0.6,3.3-3,5.5-7.1,5.5c-4.8,0-7.5-3.5-7.5-7.5c0-3.9,2.8-7.5,7.5-7.5c3.8,0,6.4,2.3,6.6,5h-3.5c-0.2-1.1-1.4-2.2-3.1-2.2c-2.7,0-4.1,2.3-4.1,4.7c0,2.5,1.4,4.7,4.4,4.7c2,0,3.2-1.2,3.4-2.7h-2.5V378.3z")
|
||||
|
66
sim/state.ts
@ -56,7 +56,7 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
export interface PacketBuffer {
|
||||
data: number[];
|
||||
data: number[] | string;
|
||||
rssi?: number;
|
||||
}
|
||||
|
||||
@ -77,10 +77,13 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
send(buffer: number[]) {
|
||||
send(buffer: number[] | string) {
|
||||
if (buffer instanceof String) buffer = buffer.slice(0, 32);
|
||||
else buffer = buffer.slice(0, 8);
|
||||
|
||||
Runtime.postMessage(<SimulatorRadioPacketMessage>{
|
||||
type: 'radiopacket',
|
||||
data: buffer.slice(0, 8)
|
||||
type: "radiopacket",
|
||||
data: buffer
|
||||
})
|
||||
}
|
||||
|
||||
@ -128,21 +131,6 @@ namespace pxsim {
|
||||
}
|
||||
}
|
||||
|
||||
export enum BasicGesture {
|
||||
GESTURE_NONE,
|
||||
GESTURE_UP,
|
||||
GESTURE_DOWN,
|
||||
GESTURE_LEFT,
|
||||
GESTURE_RIGHT,
|
||||
GESTURE_FACE_UP,
|
||||
GESTURE_FACE_DOWN,
|
||||
GESTURE_FREEFALL,
|
||||
GESTURE_3G,
|
||||
GESTURE_6G,
|
||||
GESTURE_8G,
|
||||
GESTURE_SHAKE
|
||||
};
|
||||
|
||||
interface AccelerometerSample {
|
||||
x: number;
|
||||
y: number;
|
||||
@ -196,8 +184,8 @@ namespace pxsim {
|
||||
|
||||
export class Accelerometer {
|
||||
private sigma: number = 0; // the number of ticks that the instantaneous gesture has been stable.
|
||||
private lastGesture: BasicGesture = BasicGesture.GESTURE_NONE; // the last, stable gesture recorded.
|
||||
private currentGesture: BasicGesture = BasicGesture.GESTURE_NONE; // the instantaneous, unfiltered gesture detected.
|
||||
private lastGesture: number = 0; // the last, stable gesture recorded.
|
||||
private currentGesture: number = 0 // the instantaneous, unfiltered gesture detected.
|
||||
private sample: AccelerometerSample = { x: 0, y: 0, z: -1023 }
|
||||
private shake: ShakeHistory = { x: false, y: false, z: false, count: 0, shaken: 0, timer: 0 }; // State information needed to detect shake events.
|
||||
private pitch: number;
|
||||
@ -250,7 +238,7 @@ namespace pxsim {
|
||||
*
|
||||
* @return A best guess of the current posture of the device, based on instantaneous data.
|
||||
*/
|
||||
private instantaneousPosture(): BasicGesture {
|
||||
private instantaneousPosture(): number {
|
||||
let force = this.instantaneousAccelerationSquared();
|
||||
let shakeDetected = false;
|
||||
|
||||
@ -287,42 +275,42 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
if (this.shake.shaken)
|
||||
return BasicGesture.GESTURE_SHAKE;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_SHAKE;
|
||||
|
||||
let sq = (n: number) => n * n
|
||||
|
||||
if (force < sq(DAL.MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE))
|
||||
return BasicGesture.GESTURE_FREEFALL;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_FREEFALL;
|
||||
|
||||
if (force > sq(DAL.MICROBIT_ACCELEROMETER_3G_TOLERANCE))
|
||||
return BasicGesture.GESTURE_3G;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_3G;
|
||||
|
||||
if (force > sq(DAL.MICROBIT_ACCELEROMETER_6G_TOLERANCE))
|
||||
return BasicGesture.GESTURE_6G;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_6G;
|
||||
|
||||
if (force > sq(DAL.MICROBIT_ACCELEROMETER_8G_TOLERANCE))
|
||||
return BasicGesture.GESTURE_8G;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_8G;
|
||||
|
||||
// Determine our posture.
|
||||
if (this.getX() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_LEFT;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_LEFT;
|
||||
|
||||
if (this.getX() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_RIGHT;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT;
|
||||
|
||||
if (this.getY() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_DOWN;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_DOWN;
|
||||
|
||||
if (this.getY() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_UP;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_TILT_UP;
|
||||
|
||||
if (this.getZ() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_FACE_UP;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_FACE_UP;
|
||||
|
||||
if (this.getZ() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
|
||||
return BasicGesture.GESTURE_FACE_DOWN;
|
||||
return DAL.MICROBIT_ACCELEROMETER_EVT_FACE_DOWN;
|
||||
|
||||
return BasicGesture.GESTURE_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
updateGesture() {
|
||||
@ -578,16 +566,16 @@ namespace pxsim {
|
||||
if (!runtime || runtime.dead) return;
|
||||
|
||||
switch (msg.type || "") {
|
||||
case 'eventbus':
|
||||
case "eventbus":
|
||||
let ev = <SimulatorEventBusMessage>msg;
|
||||
this.bus.queue(ev.id, ev.eventid, ev.value);
|
||||
break;
|
||||
case 'serial':
|
||||
this.serialIn.push((<SimulatorSerialMessage>msg).data || '');
|
||||
case "serial":
|
||||
this.serialIn.push((<SimulatorSerialMessage>msg).data || "");
|
||||
break;
|
||||
case 'radiopacket':
|
||||
case "radiopacket":
|
||||
let packet = <SimulatorRadioPacketMessage>msg;
|
||||
this.radio.datagram.queue({ data: packet.data || [], rssi: packet.rssi || 0 })
|
||||
this.radio.datagram.queue({ data: packet.data, rssi: packet.rssi || 0 })
|
||||
break;
|
||||
}
|
||||
}
|
||||
|