Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
da79f643dc | |||
ea10cde3eb | |||
0a60b0ee37 | |||
b4bc985068 | |||
78f9af5bc2 | |||
e9410d17a6 | |||
ca8ef260d5 | |||
5ea5e9bb5b | |||
19c689a8c4 | |||
72226cd4e5 | |||
0d3af60892 | |||
f88cda8244 | |||
f71925fdd2 | |||
bfeda371a9 | |||
eb09530391 | |||
346d1e77da | |||
bf384355c4 | |||
3801e52370 | |||
99574f1ec8 | |||
12705eed06 | |||
a62f2b00b4 | |||
7d0101af25 | |||
60c3f1f427 | |||
8552a2de52 | |||
b0d4fdb009 |
@ -3,6 +3,8 @@
|
||||
This target allow to program a [BBC micro:bit](https://www.microbit.co.uk/) using
|
||||
[Microsoft Programming Experience Toolkit](https://github.com/Microsoft/pxt).
|
||||
|
||||
* [Try it live](https://m.pxt.io)
|
||||
|
||||
[](https://travis-ci.org/Microsoft/pxt-microbit)
|
||||
|
||||
# Getting started
|
||||
@ -23,4 +25,4 @@ that wraps m.pxt.io and provides additional features.
|
||||
### Building
|
||||
|
||||
* Install Visual Studio 2015 Update 2 or higher. Make sure the Windows 10 templates are installed.
|
||||
* open the ``win10/app.sln`` solution and launch the ``codemicrobit`` project.
|
||||
* open the ``win10/app.sln`` solution and launch the ``m.pxt.io`` project.
|
||||
|
158
docs/camp.md
Normal file
158
docs/camp.md
Normal file
@ -0,0 +1,158 @@
|
||||
# Camp
|
||||
|
||||
Are you ready to build cool BBC micro:bit programs? For each challenge, reorder the blocks to recreate the program.
|
||||
|
||||
## Basic
|
||||
|
||||
### Show your name
|
||||
|
||||
Reorder the blocks below to make the micro:bit show your name.
|
||||
```shuffle
|
||||
basic.showString('Hello!')
|
||||
```
|
||||
|
||||
### Repeat Forever
|
||||
|
||||
Instead of showing your name once, we will repeat it forever!
|
||||
|
||||
Reorder the blocks to make the micro:bit show the name continuously.
|
||||
```shuffle
|
||||
basic.forever(() => {
|
||||
basic.showString('Hello!')
|
||||
});
|
||||
```
|
||||
|
||||
### 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(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
```
|
||||
|
||||
### Show an animation
|
||||
|
||||
To create animation, you can draw multiple drawing using ``show led`` and repeat it. This is just like cartoons in movies.
|
||||
|
||||
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 and 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.
|
@ -24,4 +24,4 @@ serial.writeValue(x, 0);
|
||||
control.inBackground(() => {
|
||||
|
||||
});
|
||||
|
||||
```
|
||||
|
BIN
docs/static/Microsoft-logo_rgb_c-gray.png
vendored
Normal file
BIN
docs/static/Microsoft-logo_rgb_c-gray.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
1
docs/static/microbit.docs.svg
vendored
Normal file
1
docs/static/microbit.docs.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 18 KiB |
2
docs/static/microbit.red.svg
vendored
2
docs/static/microbit.red.svg
vendored
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
1
docs/static/microbit.simplified.svg
vendored
Normal file
1
docs/static/microbit.simplified.svg
vendored
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 17 KiB |
@ -2,7 +2,7 @@
|
||||
|
||||
using namespace pxt;
|
||||
|
||||
#define RADIO_VALUE_PACKET_TYPE 24641622
|
||||
#define MAX_FIELD_NAME_LENGTH 12
|
||||
|
||||
//% color=270 weight=34
|
||||
namespace radio {
|
||||
@ -11,6 +11,8 @@ namespace radio {
|
||||
// Radio
|
||||
// -------------------------------------------------------------------------
|
||||
bool radioEnabled = false;
|
||||
bool transmitSerialNumber = false;
|
||||
|
||||
PacketBuffer packet;
|
||||
|
||||
int radioEnable() {
|
||||
@ -36,83 +38,100 @@ namespace radio {
|
||||
registerWithDal(MES_BROADCAST_GENERAL_ID, message, f);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Broadcasts 4 numbers over radio to any connected micro:bit in the group.
|
||||
*/
|
||||
//% help=radio/send-numbers
|
||||
//% weight=59
|
||||
//% blockId=radio_datagram_send_numbers block="send numbers|0: %VALUE0|1: %VALUE1|2: %VALUE2|3: %VALUE3"
|
||||
void sendNumbers(int value_0, int value_1, int value_2, int value_3) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
int buf[] = { value_0, value_1, value_2, value_3 };
|
||||
uBit.radio.datagram.send((uint8_t*)buf, 4*sizeof(int));
|
||||
* Broadcasts a number over radio to any connected micro:bit in the group.
|
||||
*/
|
||||
//% help=radio/send-number
|
||||
//% weight=60
|
||||
//% 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();
|
||||
uint32_t sn = transmitSerialNumber ? microbit_serial_number() : 0;
|
||||
uint32_t buf[] = { (uint32_t)value, t, sn };
|
||||
uBit.radio.datagram.send((uint8_t*)buf, 3*sizeof(uint32_t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts a name / value pair along with the device serial number
|
||||
* and running time to any connected BBC micro:bit in the group.
|
||||
* @param name the field name (max 12 characters), eg: "data"
|
||||
* @param the numberic value
|
||||
* @param value the numberic value
|
||||
*/
|
||||
//% help=radio/stream-value
|
||||
//% weight=4
|
||||
//% blockId=radio_datagram_stream_value block="stream|value %name|= %value"
|
||||
void streamValue(StringData* name, int number) {
|
||||
//% help=radio/send-value
|
||||
//% weight=59
|
||||
//% blockId=radio_datagram_send_value block="send|value %name|= %value" blockGap=8
|
||||
void sendValue(StringData* name, int value) {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
|
||||
ManagedString n(name);
|
||||
ManagedString n(name);
|
||||
uint32_t t = system_timer_current_time();
|
||||
uint32_t sn = transmitSerialNumber ? microbit_serial_number() : 0;
|
||||
uint8_t buf[32];
|
||||
uint32_t* buf32 = (uint32_t*)buf;
|
||||
memset(buf, 32, 0);
|
||||
buf32[0] = number; // 4 bytes: value
|
||||
buf32[1] = microbit_serial_number(); // 4 bytes: serial number
|
||||
buf32[2] = system_timer_current_time(); // 4 bytes: running time
|
||||
memcpy(buf + 12, n.toCharArray(), min(12, n.length())); // 12-24: field name
|
||||
buf32[7] = RADIO_VALUE_PACKET_TYPE; // last 4 bytes: magic number of package type
|
||||
uBit.radio.datagram.send(buf, 32);
|
||||
buf32[0] = value; // 4 bytes: value
|
||||
buf32[1] = t; // 4 bytes: running time
|
||||
buf32[2] = sn; // 4 bytes: serial number
|
||||
uint8_t len = min(MAX_FIELD_NAME_LENGTH, n.length()); // 1 byte: string length
|
||||
if (len > 0) {
|
||||
buf[12] = len; //
|
||||
memcpy(buf + 13, n.toCharArray(), len); // 13-25: field name
|
||||
}
|
||||
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
|
||||
*/
|
||||
//% help=radio/read-value-to-serial
|
||||
//% help=radio/write-value-to-serial
|
||||
//% weight=3
|
||||
void readValueToSerial() {
|
||||
//% blockId=radio_write_value_serial block="write value to serial"
|
||||
void writeValueToSerial() {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
PacketBuffer p = uBit.radio.datagram.recv();
|
||||
int length = p.length();
|
||||
if (length < 32) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t* bytes = p.getBytes();
|
||||
//uint32_t* buf32 = (uint32_t*)bytes;
|
||||
//uint32_t type = buf32[7];
|
||||
//if (type != RADIO_VALUE_PACKET_TYPE)
|
||||
//{
|
||||
// uBit.serial.send("type: ");
|
||||
// uBit.serial.send(type);
|
||||
// uBit.serial.send("\r\n");
|
||||
// return;
|
||||
//}
|
||||
|
||||
int value;
|
||||
int serial;
|
||||
int time;
|
||||
char name[12+1]; memset(name, 0, 13 * sizeof(char));
|
||||
|
||||
memcpy(&value, bytes, 4);
|
||||
memcpy(&serial, bytes + 4, 4);
|
||||
memcpy(&time, bytes + 8, 4);
|
||||
memcpy(&name, bytes + 12, 12);
|
||||
|
||||
uBit.serial.send("{s:"); uBit.serial.send(serial);
|
||||
uBit.serial.send(",t:"); uBit.serial.send(time);
|
||||
uBit.serial.send(",v:"); uBit.serial.send(value);
|
||||
uBit.serial.send(",n:\""); uBit.serial.send(name);
|
||||
uBit.serial.send("\"}\r\n");
|
||||
uBit.serial.send("{");
|
||||
if (length >= 4) {
|
||||
memcpy(&value, bytes, 4);
|
||||
uBit.serial.send("v:"); uBit.serial.send(value);
|
||||
if(length >= 8) {
|
||||
memcpy(&value, bytes + 4, 4);
|
||||
uBit.serial.send(",t:"); uBit.serial.send(value);
|
||||
if (length >= 12) {
|
||||
memcpy(&value, bytes + 8, 4);
|
||||
uBit.serial.send(",s:"); uBit.serial.send(value);
|
||||
if (length >= 13) {
|
||||
char name[MAX_FIELD_NAME_LENGTH+1];
|
||||
uint8_t len = min(MAX_FIELD_NAME_LENGTH, bytes[12]);
|
||||
memcpy(name, bytes + 13, len);
|
||||
name[len] = 0;
|
||||
uBit.serial.send(",n:\""); uBit.serial.send(name); uBit.serial.send("\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
uBit.serial.send("}\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,7 +150,7 @@ namespace radio {
|
||||
* @param index index of the number to read from 0 to 3. 1 eg
|
||||
*/
|
||||
//% help=radio/received-number-at
|
||||
//% weight=45
|
||||
//% weight=45 debug=true
|
||||
//% blockId=radio_datagram_received_number_at block="receive number|at %VALUE" blockGap=8
|
||||
int receivedNumberAt(int index) {
|
||||
if (radioEnable() != MICROBIT_OK) return 0;
|
||||
@ -156,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
|
||||
@ -192,4 +223,14 @@ namespace radio {
|
||||
if (radioEnable() != MICROBIT_OK) return;
|
||||
uBit.radio.setTransmitPower(power);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the radio to transmit the serial number in each message.
|
||||
*/
|
||||
//% help=radio/set-transmit-serial-number
|
||||
//% weight=8
|
||||
//% block=radio_set_transmit_serial_number block="set tranmist serial number %transmit"
|
||||
void setTransmitSerialNumber(bool transmit) {
|
||||
transmitSerialNumber = transmit;
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,4 @@
|
||||
*/
|
||||
//% color=270 weight=34
|
||||
namespace radio {
|
||||
/**
|
||||
* Broadcasts a number over radio to any connected micro:bit in the group.
|
||||
*/
|
||||
//% help=radio/send-number
|
||||
//% weight=60
|
||||
//% blockId=radio_datagram_send block="send number %MESSAGE" blockGap=8
|
||||
export function sendNumber(value: number) : void {
|
||||
sendNumbers(value, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
53
libs/microbit-radio/shims.d.ts
vendored
53
libs/microbit-radio/shims.d.ts
vendored
@ -6,31 +6,40 @@
|
||||
declare namespace radio {
|
||||
|
||||
/**
|
||||
* Broadcasts 4 numbers over radio to any connected micro:bit in the group.
|
||||
* Broadcasts a number over radio to any connected micro:bit in the group.
|
||||
*/
|
||||
//% help=radio/send-numbers
|
||||
//% weight=59
|
||||
//% blockId=radio_datagram_send_numbers block="send numbers|0: %VALUE0|1: %VALUE1|2: %VALUE2|3: %VALUE3" shim=radio::sendNumbers
|
||||
function sendNumbers(value_0: number, value_1: number, value_2: number, value_3: number): void;
|
||||
//% help=radio/send-number
|
||||
//% weight=60
|
||||
//% blockId=radio_datagram_send block="send number %value" blockGap=8 shim=radio::sendNumber
|
||||
function sendNumber(value: number): void;
|
||||
|
||||
/**
|
||||
* Broadcasts a name / value pair along with the device serial number
|
||||
* and running time to any connected BBC micro:bit in the group.
|
||||
* @param name the field name (max 12 characters), eg: "data"
|
||||
* @param the numberic value
|
||||
* @param value the numberic value
|
||||
*/
|
||||
//% help=radio/stream-value
|
||||
//% weight=4
|
||||
//% blockId=radio_datagram_stream_value block="stream|value %name|= %value" shim=radio::streamValue
|
||||
function streamValue(name: string, number: number): void;
|
||||
//% help=radio/send-value
|
||||
//% weight=59
|
||||
//% 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
|
||||
*/
|
||||
//% help=radio/read-value-to-serial
|
||||
//% weight=3 shim=radio::readValueToSerial
|
||||
function readValueToSerial(): void;
|
||||
//% help=radio/write-value-to-serial
|
||||
//% weight=3
|
||||
//% blockId=radio_write_value_serial block="write value to serial" shim=radio::writeValueToSerial
|
||||
function writeValueToSerial(): void;
|
||||
|
||||
/**
|
||||
* Registers code to run when a packet is received over radio.
|
||||
@ -45,7 +54,7 @@ declare namespace radio {
|
||||
* @param index index of the number to read from 0 to 3. 1 eg
|
||||
*/
|
||||
//% help=radio/received-number-at
|
||||
//% weight=45
|
||||
//% weight=45 debug=true
|
||||
//% blockId=radio_datagram_received_number_at block="receive number|at %VALUE" blockGap=8 shim=radio::receivedNumberAt
|
||||
function receivedNumberAt(index: number): number;
|
||||
|
||||
@ -57,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
|
||||
@ -83,6 +100,14 @@ declare namespace radio {
|
||||
//% weight=9
|
||||
//% blockId=radio_set_transmit_power block="set transmit power %power" shim=radio::setTransmitPower
|
||||
function setTransmitPower(power: number): void;
|
||||
|
||||
/**
|
||||
* Set the radio to transmit the serial number in each message.
|
||||
*/
|
||||
//% help=radio/set-transmit-serial-number
|
||||
//% weight=8
|
||||
//% block=radio_set_transmit_serial_number block="set tranmist serial number %transmit" shim=radio::setTransmitSerialNumber
|
||||
function setTransmitSerialNumber(transmit: boolean): void;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
28
libs/microbit/dal.d.ts
vendored
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
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
|
||||
|
@ -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
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.107",
|
||||
"version": "0.2.115",
|
||||
"description": "BBC micro:bit target for PXT",
|
||||
"keywords": [
|
||||
"JavaScript",
|
||||
@ -29,6 +29,6 @@
|
||||
"typescript": "^1.8.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-core": "0.2.121"
|
||||
"pxt-core": "0.2.124"
|
||||
}
|
||||
}
|
||||
|
@ -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,14 +72,18 @@
|
||||
"log": true
|
||||
},
|
||||
"appTheme": {
|
||||
"accentColor": "#5C2D91",
|
||||
"logoUrl": "https://m.pxt.io/about",
|
||||
"logo": "./static/microbit.red.svg",
|
||||
"docsLogo": "./static/microbit.red.svg",
|
||||
"portraitLogo":"./static/microbit.red.svg",
|
||||
"footerLogo": "./static/microbit.red.svg",
|
||||
"logo": "./static/microbit.simplified.svg",
|
||||
"docsLogo": "./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/",
|
||||
"privacyUrl": "https://go.microsoft.com/fwlink/?LinkId=521839",
|
||||
"termsOfUseUrl": "https://go.microsoft.com/fwlink/?LinkID=206977",
|
||||
"visualStudioCode": true,
|
||||
"docMenu": [
|
||||
{
|
||||
@ -100,4 +104,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -449,20 +449,46 @@ namespace pxsim.radio {
|
||||
board().radio.setTransmitPower(power);
|
||||
}
|
||||
|
||||
export function sendNumbers(value0: number, value1: number, value2: number, value3: number): void {
|
||||
board().radio.datagram.send([value0, value1, value2, value3]);
|
||||
export function setTransmitSerialNumber(transmit: boolean): void {
|
||||
board().radio.setTransmitSerialNumber(transmit);
|
||||
}
|
||||
|
||||
export function streamValue(name: string, value: number) {
|
||||
export function sendNumber(value: number): void {
|
||||
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];
|
||||
b.writeSerial(`{v:${v}}`);
|
||||
}
|
||||
|
||||
export function sendValue(name: string, value: number) {
|
||||
board().radio.datagram.send([value]);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
95
sim/state.ts
95
sim/state.ts
@ -56,7 +56,7 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
export interface PacketBuffer {
|
||||
data: number[];
|
||||
data: number[] | string;
|
||||
rssi?: number;
|
||||
}
|
||||
|
||||
@ -77,15 +77,18 @@ 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
|
||||
})
|
||||
}
|
||||
|
||||
recv(): PacketBuffer {
|
||||
var r = this.datagram.shift();
|
||||
let r = this.datagram.shift();
|
||||
if (!r) r = {
|
||||
data: [0, 0, 0, 0],
|
||||
rssi: -1
|
||||
@ -98,6 +101,7 @@ namespace pxsim {
|
||||
// uint8_t radioDefaultGroup = MICROBIT_RADIO_DEFAULT_GROUP;
|
||||
groupId = 0; // todo
|
||||
power = 0;
|
||||
transmitSerialNumber = false;
|
||||
datagram: RadioDatagram;
|
||||
|
||||
constructor(private runtime: Runtime) {
|
||||
@ -112,6 +116,10 @@ namespace pxsim {
|
||||
this.power = Math.max(0, Math.min(7, power));
|
||||
}
|
||||
|
||||
setTransmitSerialNumber(sn: boolean) {
|
||||
this.transmitSerialNumber = !!sn;
|
||||
}
|
||||
|
||||
broadcast(msg: number) {
|
||||
Runtime.postMessage(<SimulatorEventBusMessage>{
|
||||
type: 'eventbus',
|
||||
@ -123,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;
|
||||
@ -191,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;
|
||||
@ -245,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;
|
||||
|
||||
@ -282,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() {
|
||||
@ -511,7 +504,7 @@ namespace pxsim {
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.id = "b" +Math_.random(2147483647);
|
||||
this.id = "b" + Math_.random(2147483647);
|
||||
this.animationQ = new AnimationQueue(runtime);
|
||||
this.bus = new EventBus(runtime);
|
||||
this.radio = new RadioBus(runtime);
|
||||
@ -573,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;
|
||||
}
|
||||
}
|
||||
@ -598,13 +591,13 @@ namespace pxsim {
|
||||
let c = s[i];
|
||||
this.serialOutBuffer += c;
|
||||
if (c == '\n') {
|
||||
Runtime.postMessage(<SimulatorSerialMessage>{
|
||||
type: 'serial',
|
||||
data: this.serialOutBuffer,
|
||||
id: runtime.id
|
||||
})
|
||||
this.serialOutBuffer = ''
|
||||
break;
|
||||
Runtime.postMessage(<SimulatorSerialMessage>{
|
||||
type: 'serial',
|
||||
data: this.serialOutBuffer,
|
||||
id: runtime.id
|
||||
})
|
||||
this.serialOutBuffer = ''
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -647,7 +640,7 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
for (var i = 0; i < this.data.length; ++i)
|
||||
for (let i = 0; i < this.data.length; ++i)
|
||||
this.data[i] = 0;
|
||||
}
|
||||
}
|
||||
@ -683,11 +676,11 @@ namespace pxsim {
|
||||
}
|
||||
|
||||
export function createFont(): Image {
|
||||
var data = [0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x8, 0x8, 0x0, 0x8, 0xa, 0x4a, 0x40, 0x0, 0x0, 0xa, 0x5f, 0xea, 0x5f, 0xea, 0xe, 0xd9, 0x2e, 0xd3, 0x6e, 0x19, 0x32, 0x44, 0x89, 0x33, 0xc, 0x92, 0x4c, 0x92, 0x4d, 0x8, 0x8, 0x0, 0x0, 0x0, 0x4, 0x88, 0x8, 0x8, 0x4, 0x8, 0x4, 0x84, 0x84, 0x88, 0x0, 0xa, 0x44, 0x8a, 0x40, 0x0, 0x4, 0x8e, 0xc4, 0x80, 0x0, 0x0, 0x0, 0x4, 0x88, 0x0, 0x0, 0xe, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x1, 0x22, 0x44, 0x88, 0x10, 0xc, 0x92, 0x52, 0x52, 0x4c, 0x4, 0x8c, 0x84, 0x84, 0x8e, 0x1c, 0x82, 0x4c, 0x90, 0x1e, 0x1e, 0xc2, 0x44, 0x92, 0x4c, 0x6, 0xca, 0x52, 0x5f, 0xe2, 0x1f, 0xf0, 0x1e, 0xc1, 0x3e, 0x2, 0x44, 0x8e, 0xd1, 0x2e, 0x1f, 0xe2, 0x44, 0x88, 0x10, 0xe, 0xd1, 0x2e, 0xd1, 0x2e, 0xe, 0xd1, 0x2e, 0xc4, 0x88, 0x0, 0x8, 0x0, 0x8, 0x0, 0x0, 0x4, 0x80, 0x4,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, 0x11, 0x31, 0x35, 0xbb, 0x0, 0x12, 0x4c, 0x8c, 0x92, 0x0, 0x11, 0x2a, 0x44, 0x98, 0x0, 0x1e, 0xc4, 0x88, 0x1e, 0x6, 0xc4, 0x8c, 0x84, 0x86, 0x8, 0x8, 0x8, 0x8, 0x8, 0x18, 0x8, 0xc, 0x88, 0x18, 0x0, 0x0, 0xc, 0x83, 0x60];
|
||||
|
||||
let nb = data.length;
|
||||
let n = nb / 5;
|
||||
var font = createImage(nb);
|
||||
let font = createImage(nb);
|
||||
for (let c = 0; c < n; c++) {
|
||||
for (let row = 0; row < 5; row++) {
|
||||
let char = data[c * 5 + row];
|
||||
|
@ -444,13 +444,11 @@
|
||||
"pvjilh",
|
||||
"pvqrgm",
|
||||
"pvzmhz",
|
||||
"pwlxyy",
|
||||
"pxebwk",
|
||||
"pxizap",
|
||||
"pxyovu",
|
||||
"pymfqh",
|
||||
"pzmjbx",
|
||||
"pzptoo",
|
||||
"pzucty",
|
||||
"rannhh",
|
||||
"rbnvdq",
|
||||
|
Reference in New Issue
Block a user