Renaming the string in onDataPacketReceived and updating docs (#292)
This commit is contained in:
parent
f191d9033d
commit
2bc5db517e
@ -5,12 +5,23 @@ Run part of a program when the micro:bit receives a
|
|||||||
|
|
||||||
|
|
||||||
```sig
|
```sig
|
||||||
radio.onDataPacketReceived((packet: Packet) => { });
|
radio.onDataPacketReceived(({receivedNumber, receivedString, time, serial, signal}) => { });
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### ~hint
|
||||||
|
|
||||||
|
To add or remove the parts of the packet from the block, try clicking the blue gear in the corner!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
### Callback Parameters
|
### Callback Parameters
|
||||||
|
|
||||||
* ``packet`` - the [packet](/reference/radio/packet) that was received by the radio
|
* ``packet`` - the [packet](/reference/radio/packet) that was received by the radio. The packet has the following properties:
|
||||||
|
* `receivedNumber` - The [number](/reference/types/number) that was sent in this packet or `0` if this packet did not contain a number. See [send number](/reference/radio/send-number) and [send value](/reference/radio/send-value)
|
||||||
|
* `receivedString` - The [string](/reference/types/string) that was sent in this packet or the empty string if this packet did not contain a string. See [send string](/reference/radio/send-string) and [send value](/reference/radio/send-value)
|
||||||
|
* `time` - The system time of the micro:bit that sent this packet at the time the packet was sent.
|
||||||
|
* `serial` - The serial number of the micro:bit that sent this packet or `0` if the micro:bit did not include its serial number.
|
||||||
|
* `signal` - How strong the radio signal is from `255` (weak) to `0` (strong).
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ A packet that was received by the radio.
|
|||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
* `receivedNumber` - The number that was sent in this packet or `0` if this packet did not contain a number. See [send number](/reference/radio/send-number) and [send value](/reference/radio/send-value)
|
* `receivedNumber` - The [number](/reference/types/number) that was sent in this packet or `0` if this packet did not contain a number. See [send number](/reference/radio/send-number) and [send value](/reference/radio/send-value)
|
||||||
* `text` - The string that was sent in this packet or the empty string if this packet did not contain a string. See [send string](/reference/radio/send-string) and [send value](/reference/radio/send-value)
|
* `receivedString` - The [string](/reference/types/string) that was sent in this packet or the empty string if this packet did not contain a string. See [send string](/reference/radio/send-string) and [send value](/reference/radio/send-value)
|
||||||
* `time` - The system time of the micro:bit that sent this packet at the time the packet was sent.
|
* `time` - The system time of the micro:bit that sent this packet at the time the packet was sent.
|
||||||
* `serial` - The serial number of the micro:bit that sent this packet or `0` if the micro:bit did not include its serial number.
|
* `serial` - The serial number of the micro:bit that sent this packet or `0` if the micro:bit did not include its serial number.
|
||||||
* `signal` - How strong the radio signal is from `255` (weak) to `0` (strong).
|
* `signal` - How strong the radio signal is from `255` (weak) to `0` (strong).
|
||||||
|
@ -24,8 +24,8 @@ input.onButtonPressed(Button.A, () => {
|
|||||||
basic.showString("SENT");
|
basic.showString("SENT");
|
||||||
})
|
})
|
||||||
|
|
||||||
radio.onDataPacketReceived(({ text }) => {
|
radio.onDataPacketReceived(({ receivedString }) => {
|
||||||
basic.showString(text);
|
basic.showString(receivedString);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ or model rocket.
|
|||||||
```blocks
|
```blocks
|
||||||
radio.setGroup(99)
|
radio.setGroup(99)
|
||||||
input.onButtonPressed(Button.A, () => {
|
input.onButtonPressed(Button.A, () => {
|
||||||
radio.sendValue("acc",input.acceleration(Dimension.X))
|
radio.sendValue("acc", input.acceleration(Dimension.X))
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -31,8 +31,8 @@ Then it shows them on the LED screen.
|
|||||||
|
|
||||||
```blocks
|
```blocks
|
||||||
radio.setGroup(99)
|
radio.setGroup(99)
|
||||||
radio.onDataPacketReceived(({ text, receivedNumber }) => {
|
radio.onDataPacketReceived(({ receivedString, receivedNumber }) => {
|
||||||
basic.showString(text);
|
basic.showString(receivedString);
|
||||||
basic.showNumber(receivedNumber);
|
basic.showNumber(receivedNumber);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -13,7 +13,7 @@ namespace radio {
|
|||||||
* The string payload if a string was sent in this packet (via ``sendString()`` or ``sendValue()``)
|
* The string payload if a string was sent in this packet (via ``sendString()`` or ``sendValue()``)
|
||||||
* or the empty string if this packet did not contain a string.
|
* or the empty string if this packet did not contain a string.
|
||||||
*/
|
*/
|
||||||
public text: string;
|
public receivedString: string;
|
||||||
/**
|
/**
|
||||||
* The system time of the sender of the packet at the time the packet was sent.
|
* The system time of the sender of the packet at the time the packet was sent.
|
||||||
*/
|
*/
|
||||||
@ -35,7 +35,7 @@ namespace radio {
|
|||||||
//% help=radio/on-data-packet-received
|
//% help=radio/on-data-packet-received
|
||||||
//% mutate=true
|
//% mutate=true
|
||||||
//% mutateText=Packet
|
//% mutateText=Packet
|
||||||
//% mutateDefaults="receivedNumber;text,receivedNumber;text"
|
//% mutateDefaults="receivedNumber;receivedString,receivedNumber;receivedString"
|
||||||
//% blockId=radio_on_packet block="on radio received" blockGap=8
|
//% blockId=radio_on_packet block="on radio received" blockGap=8
|
||||||
export function onDataPacketReceived(cb: (packet: Packet) => void) {
|
export function onDataPacketReceived(cb: (packet: Packet) => void) {
|
||||||
onDataReceived(() => {
|
onDataReceived(() => {
|
||||||
@ -44,7 +44,7 @@ namespace radio {
|
|||||||
packet.receivedNumber = receivedNumber();
|
packet.receivedNumber = receivedNumber();
|
||||||
packet.time = receivedTime();
|
packet.time = receivedTime();
|
||||||
packet.serial = receivedSerial();
|
packet.serial = receivedSerial();
|
||||||
packet.text = receivedString();
|
packet.receivedString = receivedString();
|
||||||
packet.signal = receivedSignalStrength();
|
packet.signal = receivedSignalStrength();
|
||||||
cb(packet)
|
cb(packet)
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user