upgraded to lancaster 2.0.0.rc3 (core 0.1.9)

added radio.send/receive string
This commit is contained in:
Peli de Halleux
2016-05-12 12:35:40 -07:00
parent 78f9af5bc2
commit b4bc985068
11 changed files with 125 additions and 158 deletions

View File

@ -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

View File

@ -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