diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 53605d2b..350682df 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -50,15 +50,6 @@ ## #examples -* [Examples](/examples) - * [Blinky](/examples/blinky) - * [Rando](/examples/rando) - * [Plot Acceleration](/examples/plot-acceleration) - * [Plot Light Level](/examples/plot-light-level) - * [Game of Life](/examples/gameofLife) - * [Egg and Spoon Race](/examples/egg-and-spoon) - * [Radio Dashboard](/examples/radio-dashboard) - ## #courses * [Courses](/courses) @@ -223,10 +214,14 @@ * [send number](/reference/radio/send-number) * [send value](/reference/radio/send-value) * [send string](/reference/radio/send-string) - * [on data packet received](/reference/radio/on-data-packet-received) + * [on received number](/reference/radio/on-received-number) + * [on received string](/reference/radio/on-received-string) + * [on received buffer](/reference/radio/on-received-buffer) + * [received packet](/reference/radio/received-packet) * [set group](/reference/radio/set-group) * [set transmit power](/reference/radio/set-transmit-power) * [set transmit serial number](/reference/radio/set-transmit-serial-number) + * [on data packet received](/reference/radio/on-data-packet-received) * [write received packet to serial](/reference/radio/write-received-packet-to-serial) * [Game](/reference/game) * [create sprite](/reference/game/create-sprite) diff --git a/docs/courses/csintro/radio/activity.md b/docs/courses/csintro/radio/activity.md index 31ee9956..b5a9aa55 100644 --- a/docs/courses/csintro/radio/activity.md +++ b/docs/courses/csintro/radio/activity.md @@ -46,8 +46,7 @@ Here is the complete Marco Polo program: input.onButtonPressed(Button.A, () => { radio.sendString("Marco") }) - -radio.onDataPacketReceived(({ receivedString }) => { +radio.onReceivedString(function (receivedString) { basic.showString(receivedString) }) input.onButtonPressed(Button.B, () => { @@ -69,7 +68,7 @@ input.onButtonPressed(Button.A, () => { radio.sendString("Marco") music.playTone(131, music.beat(BeatFraction.Whole)) }) - radio.onDataPacketReceived( ({ receivedString }) => { +radio.onReceivedString(function (receivedString) { basic.showString(receivedString) }) input.onButtonPressed(Button.B, () => { @@ -134,7 +133,7 @@ In order to know whether to display a dot, a dash, or a space/stop image, we nee * Leave the righthand side default value of zero in the 0=0 block. ```blocks -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { } @@ -145,7 +144,7 @@ radio.onDataPacketReceived( ({ receivedNumber }) => { * Create an image to represent a dot. ```blocks -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { basic.showLeds(` . . . . . @@ -168,7 +167,7 @@ Challenge question: How can we fix this? * Add a 'pause' block and a 'clear screen' block after the 'show leds' block ```blocks -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { basic.showLeds(` . . . . . @@ -198,7 +197,7 @@ Now each time the sender presses button A, you see a dot appear. ```blocks -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { basic.showLeds(` . . . . . @@ -282,7 +281,7 @@ input.onButtonPressed(Button.B, () => { input.onButtonPressed(Button.AB, () => { radio.sendNumber(2) }) -radio.onDataPacketReceived(({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { basic.showLeds(` . . . . . diff --git a/docs/courses/csintro/radio/project.md b/docs/courses/csintro/radio/project.md index eee112d3..533910c6 100644 --- a/docs/courses/csintro/radio/project.md +++ b/docs/courses/csintro/radio/project.md @@ -27,7 +27,7 @@ Second micro:bit that plays the notes ```blocks let sound = 0 -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { sound = 349 music.playTone(sound, music.beat(BeatFraction.Half)) diff --git a/docs/courses/ucp-science/body-electrical/setup-procedure.md b/docs/courses/ucp-science/body-electrical/setup-procedure.md index 1f8119af..b1e22a87 100644 --- a/docs/courses/ucp-science/body-electrical/setup-procedure.md +++ b/docs/courses/ucp-science/body-electrical/setup-procedure.md @@ -89,7 +89,7 @@ basic.forever(() => { This receiver @boardname@ uses the “on start” event to set up the title on the @boardname@ when started, the radio group, and the ``bodyElectricity`` variable to collect and store the data received. -The ``||radio:on radio received||`` event reads the number value sent from the sending @boardname@. The number is then stored in the ``bodyElectricity`` variable. the electricity on pin **0** and stores it in the variable ``bodyElectricity``. The last line uses the serial write command to send the text `"Body Electricity"` label and the value of ``bodyElectricity`` variable back to the Windows 10 MakeCode app. The data is sampled and send from 10 to 20 times per second. +The ``||radio:on received number||`` event reads the number value sent from the sending @boardname@. The number is then stored in the ``bodyElectricity`` variable. the electricity on pin **0** and stores it in the variable ``bodyElectricity``. The last line uses the serial write command to send the text `"Body Electricity"` label and the value of ``bodyElectricity`` variable back to the Windows 10 MakeCode app. The data is sampled and send from 10 to 20 times per second. ```blocks // Body Electricity Receiver @@ -98,7 +98,7 @@ let bodyElectricty = 0 radio.setGroup(99) // Radio Receiver event -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { bodyElectricty = receivedNumber serial.writeValue("Body Electricty", bodyElectricty) }) diff --git a/docs/courses/ucp-science/data-collection/setup-procedure.md b/docs/courses/ucp-science/data-collection/setup-procedure.md index 81d81e68..690d3046 100644 --- a/docs/courses/ucp-science/data-collection/setup-procedure.md +++ b/docs/courses/ucp-science/data-collection/setup-procedure.md @@ -85,7 +85,7 @@ In the radio received event, the temperature is received from sending the micro: let temperature = 0 radio.setGroup(99) basic.showString("TEMPERATURE RECEIVER") -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { basic.showNumber(receivedNumber) }) ``` @@ -99,7 +99,7 @@ This code is the same as above but one additional line of code is added to write let temperature = 0 basic.showString("TEMPERATURE RECEIVER SERIAL") radio.setGroup(99) -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { basic.showNumber(receivedNumber) serial.writeValue("Celisus", receivedNumber) }) @@ -143,14 +143,14 @@ basic.showString("GRAVITY RECEIVER") radio.setGroup(99) ``` -The ``||radio:on radio received||`` event will constantly monitor radio signals from the radio group. +The ``||radio:on received number||`` event will constantly monitor radio signals from the radio group. When a value is received from the group it is stored in the ``gravity`` variable. The ``||serial:serial write value||`` sends 2 pieces of data back to the MakeCode app through the USB cable. First it sends a label `"gravity"` and then the value received as gravity from the ``||input:acceleration||`` method from the first micro:bit. ```blocks basic.showString("GRAVITY RECEIVER") radio.setGroup(99) -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { serial.writeValue("gravity", receivedNumber) }) ``` diff --git a/docs/courses/ucp-science/gravity/setup-procedure.md b/docs/courses/ucp-science/gravity/setup-procedure.md index 5776be3a..9c8b446a 100644 --- a/docs/courses/ucp-science/gravity/setup-procedure.md +++ b/docs/courses/ucp-science/gravity/setup-procedure.md @@ -52,7 +52,7 @@ radio.setGroup(99) #### Code the receive event -7. The ``||radio:on radio received||`` event will constantly monitor radio signals from the radio group. +7. The ``||radio:on received number||`` event will constantly monitor radio signals from the radio group. 8. When a value is received from the group it is stored in the ``gravity`` variable. 9. The ``||serial:serial write Value||`` sends 2 pieces of data back to the MakeCode app through the USB cable. First it sends a label `"gravity"` and then the value received as gravity from the acceleration method from the first @boardname@. 10. Add a ``||led:toggle||`` to indicate that it's receiving data. Change ``x`` to `1` so that another LED blinks. @@ -60,8 +60,8 @@ radio.setGroup(99) ```blocks basic.showString("GRAVITY RECEIVER") radio.setGroup(99) -radio.onDataPacketReceived( ({ receivedNumber: gravity }) => { - serial.writeValue("gravity", gravity) +radio.onReceivedNumber(function (receivedNumber) { + serial.writeValue("gravity", receivedNumber) led.toggle(1, 0) }) ``` diff --git a/docs/courses/ucp-science/rocket-acceleration/setup-procedure.md b/docs/courses/ucp-science/rocket-acceleration/setup-procedure.md index c27936b7..a2e19007 100644 --- a/docs/courses/ucp-science/rocket-acceleration/setup-procedure.md +++ b/docs/courses/ucp-science/rocket-acceleration/setup-procedure.md @@ -71,11 +71,11 @@ radio.setGroup(10) serial.writeLine("Acceleration") ``` -The ``||radio:on radio received||`` event reads the number value from the sending @boardname@. The number is then stored in the variable ``receivedNumber``. The last line uses the serial write command to send the text ``"z"`` label and the value of ``receivedNumber`` variable back to the Windows 10 MakeCode app. The data is sampled and send from 10 to 20 times per second. +The ``||radio:on received number||`` event reads the number value from the sending @boardname@. The number is then stored in the variable ``receivedNumber``. The last line uses the serial write command to send the text ``"z"`` label and the value of ``receivedNumber`` variable back to the Windows 10 MakeCode app. The data is sampled and send from 10 to 20 times per second. ```blocks // onRadio receive & write z value to serial -radio.onDataPacketReceived(({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { serial.writeValue("z", receivedNumber) }) ``` diff --git a/docs/courses/ucp-science/temperature/setup-procedure.md b/docs/courses/ucp-science/temperature/setup-procedure.md index 199f103a..ffc7741e 100644 --- a/docs/courses/ucp-science/temperature/setup-procedure.md +++ b/docs/courses/ucp-science/temperature/setup-procedure.md @@ -102,14 +102,14 @@ basic.forever(() => { In the starting of the code the title is displayed, radio group `99` is setup, and the initial ``temperature`` variable is set to `0`. -In the ``||radio:on radio received||`` event, the temperature is received from sending the @boardname@ radio. The receive temperature is then displayed on the LED display. This is repeated whenever a radio signal is received. +In the ``||radio:on received number||`` event, the temperature is received from sending the @boardname@ radio. The receive temperature is then displayed on the LED display. This is repeated whenever a radio signal is received. ```blocks let temperature = 0 basic.showString("TEMPERATURE RADIO RECEIVER") radio.setGroup(99) -radio.onDataPacketReceived( ({ receivedNumber: temperature }) => { - basic.showNumber(temperature) +radio.onReceivedNumber( function(receivedNumber) { + basic.showNumber(receivedNumber) }) ``` @@ -121,9 +121,9 @@ This code is the same as above but one additional line of code is added to write let temperature = 0 basic.showString("TEMPERATURE RADIO RECEIVER SERIAL") radio.setGroup(99) -radio.onDataPacketReceived( ({ receivedNumber: temperature }) => { - basic.showNumber(temperature) - serial.writeValue("Celisus", temperature) +radio.onReceivedNumber( function(receivedNumber) { + basic.showNumber(receivedNumber) + serial.writeValue("Celisus", receivedNumber) }) ``` diff --git a/docs/device/data-analysis/remote.md b/docs/device/data-analysis/remote.md index 82eb8f93..9ee0feb4 100644 --- a/docs/device/data-analysis/remote.md +++ b/docs/device/data-analysis/remote.md @@ -14,11 +14,11 @@ The receiving @boardname@ sets a radio group number on which to listen for incom radio.setGroup(99) ``` -The receiver then waits to receive a packet (radio message) from the sender which contains the data to record. This happens inside an ``||radio:on radio received||`` block. If the sending @boardname@ is measuring temperature at a remote location (somewhere else in the room maybe), the receiver will write the value received as a temperature measurement to the serial port. +The receiver then waits to receive a packet (radio message) from the sender which contains the data to record. This happens inside an ``||radio:on received number||`` block. If the sending @boardname@ is measuring temperature at a remote location (somewhere else in the room maybe), the receiver will write the value received as a temperature measurement to the serial port. ```blocks radio.setGroup(99) -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { basic.showNumber(receivedNumber) serial.writeValue("TempCelsius", receivedNumber) }) @@ -67,14 +67,14 @@ Here's the program for the receiver to record both temperature and light: ```blocks radio.setGroup(99) -radio.onDataPacketReceived(({ receivedString: name, receivedNumber: value }) => { +radio.onReceivedValue(function (name: string, value: number) { basic.showString(name + ":") basic.showNumber(value) serial.writeValue(name, value) }) ``` -The receiver program uses just one ``||radio:on radio received||`` event to record the values. The ``name`` and the ``value`` are parameters for the event block so both temperature and light values are received here. +The receiver program uses just one ``||radio:on received number||`` event to record the values. The ``name`` and the ``value`` are parameters for the event block so both temperature and light values are received here. ## Multiple remote stations @@ -111,8 +111,10 @@ basic.forever(() => { The program on the receiver board can use the serial number to make a name value pair that the [Data Viewer](./writing#name-value-pairs) can recognize: ```blocks +let id = 0; radio.setGroup(99) -radio.onDataPacketReceived(({ serial: id, receivedString: name, receivedNumber: value }) => { +radio.onReceivedValue(function (name: string, value: number) { + id = radio.receivedPacket(RadioPacketProperty.SerialNumber) basic.showString(name + ":") basic.showNumber(value) serial.writeValue(id + "_" + name, value) @@ -126,7 +128,7 @@ The serial number, ``id``, is used as a _prefix_ for the ``name`` to identify wh If you're recording data to save on a computer for analysis or other uses outside of the MakeCode editor, you can use the ``||radio:radio write received packet to serial||`` block to format it for you. This function will format the data from the received packet into a [JSON](https://en.wikipedia.org/wiki/JSON) string and write it to the serial port, all in one operation. It's used just like this: ```blocks -radio.onDataPacketReceived(() => { +radio.onReceivedNumber(function (receivedNumber) { radio.writeReceivedPacketToSerial(); }); ``` diff --git a/docs/examples/radio-dashboard.md b/docs/examples/radio-dashboard.md index 4cb93f42..d99c4f3a 100644 --- a/docs/examples/radio-dashboard.md +++ b/docs/examples/radio-dashboard.md @@ -52,13 +52,14 @@ function getClient(id: number): Client { } // store data received by clients -radio.onDataPacketReceived(packet => { - const client = getClient(packet.serial); +radio.onReceivedNumber(function (receivedNumber) { + const serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber) + const client = getClient(serialNumber); if (!client) return; client.ping = input.runningTime() - client.sprite.setBrightness(Math.max(1, packet.receivedNumber & 0xff)); + client.sprite.setBrightness(Math.max(1, receivedNumber & 0xff)); }) // monitor the sprites and start blinking when no packet is received diff --git a/docs/fcp/ch1.md b/docs/fcp/ch1.md index 49294d58..fd5be14a 100644 --- a/docs/fcp/ch1.md +++ b/docs/fcp/ch1.md @@ -63,7 +63,7 @@ input.onButtonPressed(Button.A, () => { input.onButtonPressed(Button.B, () => { radio.sendString("B") }) -radio.onDataPacketReceived(({receivedString}) => { +radio.onReceivedNumber(({ receivedString }) => { basic.showString(receivedString) }) ``` \ No newline at end of file diff --git a/docs/lessons/charting.md b/docs/lessons/charting.md index 03a62b38..af7f4945 100644 --- a/docs/lessons/charting.md +++ b/docs/lessons/charting.md @@ -22,7 +22,7 @@ Learn the functions of **on data received**, **send number** and **receive numbe input.acceleration(Dimension.X) led.plotBarGraph(0, 1023) basic.showNumber(0) -radio.onDataPacketReceived(() => {}) +radio.onReceivedNumber(function (receivedNumber) {}) radio.sendNumber(0) ``` diff --git a/docs/lessons/charting/challenge.md b/docs/lessons/charting/challenge.md index 4049d43e..3df69cdd 100644 --- a/docs/lessons/charting/challenge.md +++ b/docs/lessons/charting/challenge.md @@ -28,7 +28,7 @@ We want to register code to run when a packet is received over radio. We can imp basic.forever(() => { radio.sendNumber(input.acceleration(Dimension.X)) }) -radio.onDataPacketReceived(() => { +radio.onReceivedNumber(function (receivedNumber) { }) ``` @@ -39,7 +39,7 @@ Finally, we want to chart the acceleration. So we must first implement `plot bar basic.forever(() => { radio.sendNumber(input.acceleration(Dimension.X)) }) -radio.onDataPacketReceived(({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { led.plotBarGraph(receivedNumber, 1023) }) diff --git a/docs/lessons/pogo.md b/docs/lessons/pogo.md index eaf6c8e2..09844d1d 100644 --- a/docs/lessons/pogo.md +++ b/docs/lessons/pogo.md @@ -31,7 +31,7 @@ basic.showLeds(` `) basic.clearScreen() if (true) {} -radio.onDataPacketReceived(() => { }) +radio.onReceivedNumber(function (receivedNumber) { }) ``` ## Objectives diff --git a/docs/lessons/pogo/activity.md b/docs/lessons/pogo/activity.md index 92a951dd..4a184458 100644 --- a/docs/lessons/pogo/activity.md +++ b/docs/lessons/pogo/activity.md @@ -120,7 +120,7 @@ input.onButtonPressed(Button.AB, () => { let jumps = 0 basic.showNumber(jumps) }) -radio.onDataPacketReceived(({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { basic.showNumber(receivedNumber) }) @@ -151,7 +151,7 @@ input.onButtonPressed(Button.AB, () => { let jumps = 0 basic.showNumber(jumps) }) -radio.onDataPacketReceived(({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { basic.showNumber(receivedNumber) led.stopAnimation() }) diff --git a/docs/lessons/seismograph.md b/docs/lessons/seismograph.md index 98e04931..4c6e9b64 100644 --- a/docs/lessons/seismograph.md +++ b/docs/lessons/seismograph.md @@ -21,7 +21,7 @@ Learn how to **show LEDs** to turn on a LED light pattern on the LED screen. We basic.forever(() => {}); radio.sendNumber(0); input.acceleration(Dimension.Strength) -radio.onDataPacketReceived(() => {}); +radio.onReceivedNumber(function (receivedNumber) {}); led.plotBarGraph(0, 0); ``` diff --git a/docs/lessons/seismograph/challenge.md b/docs/lessons/seismograph/challenge.md index c7363c4c..e0e77664 100644 --- a/docs/lessons/seismograph/challenge.md +++ b/docs/lessons/seismograph/challenge.md @@ -78,7 +78,7 @@ Your finished code will look like this: basic.forever(() => { radio.sendNumber(input.acceleration(Dimension.Strength) - 1023); }); -radio.onDataPacketReceived(() => { +radio.onReceivedNumber(function (receivedNumber) { }); ``` @@ -92,7 +92,7 @@ Your finished code will look like this: basic.forever(() => { radio.sendNumber(input.acceleration(Dimension.Strength) - 1023); }); -radio.onDataPacketReceived(({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { led.plotBarGraph(receivedNumber, 0); }); ``` diff --git a/docs/projects/fireflies.md b/docs/projects/fireflies.md index 5bf058e3..6f503c0a 100644 --- a/docs/projects/fireflies.md +++ b/docs/projects/fireflies.md @@ -87,7 +87,7 @@ When a firefly receives a radio packet, it increments its clock by one: ```block // the clock ticker let clock = 0 -radio.onDataPacketReceived(() => { +radio.onReceivedNumber(function (receivedNumber) { // advance clock to catch up neighbors clock += 1 }) @@ -104,7 +104,7 @@ Download this program on as many @boardname@s as you can find and try it out in ```blocks // the clock ticker let clock = 0 -radio.onDataPacketReceived(() => { +radio.onReceivedNumber(function (receivedNumber) { // advance clock to catch up neighbors clock += 1 }) diff --git a/docs/projects/hot-or-cold.md b/docs/projects/hot-or-cold.md index 6e154ccb..9766103a 100644 --- a/docs/projects/hot-or-cold.md +++ b/docs/projects/hot-or-cold.md @@ -55,8 +55,10 @@ The hunter @boardname@ looks for beacons. To determine how far away or how close they are, we use the signal strength of each radio packet sent by the beacons. The signal strength ranges from ``-128db`` (weak) to ``-42db`` (very strong). ```blocks -radio.onDataPacketReceived( ({ receivedNumber, signal }) => { - basic.showNumber(signal) +let signal = 0; +radio.onReceivedNumber(function (receivedNumber) { + signal = radio.receivedPacket(RadioPacketProperty.SignalStrength) + basic.showNumber(signal); }); radio.setGroup(1) ``` @@ -84,8 +86,9 @@ Here is an example that uses ``-95`` or less for cold, between ``-95`` and ``-80 To make the program more responsive, add a ``||led:stop animation||`` to cancel icon animations when a new beacon packet comes in. ```blocks -radio.onDataPacketReceived( ({ receivedNumber, signal }) => { - led.stopAnimation(); +let signal = 0; +radio.onReceivedNumber(function (receivedNumber) { + signal = radio.receivedPacket(RadioPacketProperty.SignalStrength) if (signal < -90) { basic.showIcon(IconNames.SmallDiamond) } else if (signal < -80) { @@ -121,9 +124,13 @@ To check if an array contains an certain element, we use the ``||arrays:find ind ```blocks let beacons: number[] = [0] -radio.onDataPacketReceived( ({ receivedNumber, signal, serial }) => { - if (signal > -50 && beacons.indexOf(serial) < 0) { - beacons.push(serial) +let signal = 0; +let serialNumber = 0; +radio.onReceivedNumber(function (receivedNumber) { + signal = radio.receivedPacket(RadioPacketProperty.SignalStrength) + serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber) + if (signal > -50 && beacons.indexOf(serialNumber) < 0) { + beacons.push(serialNumber) game.addScore(1) basic.showNumber(game.score()) } @@ -146,7 +153,11 @@ The hunter code with all th pieces together looks like this now. Download and tr ```blocks let beacons: number[] = [0]; -radio.onDataPacketReceived( ({ receivedNumber, signal, serial }) => { +let signal = 0; +let serialNumber = 0; +radio.onReceivedNumber(function (receivedNumber) { + signal = radio.receivedPacket(RadioPacketProperty.SignalStrength) + serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber) led.stopAnimation(); if (signal < -95) { basic.showIcon(IconNames.SmallDiamond) @@ -154,8 +165,8 @@ radio.onDataPacketReceived( ({ receivedNumber, signal, serial }) => { basic.showIcon(IconNames.Diamond) } else { basic.showIcon(IconNames.Square) - if (signal > -50 && beacons.indexOf(serial) < 0) { - beacons.push(serial) + if (signal > -50 && beacons.indexOf(serialNumber) < 0) { + beacons.push(serialNumber) game.addScore(1) basic.showNumber(game.score()) } diff --git a/docs/projects/inchworm/connect.md b/docs/projects/inchworm/connect.md index 3775945b..5d1ad573 100644 --- a/docs/projects/inchworm/connect.md +++ b/docs/projects/inchworm/connect.md @@ -11,7 +11,7 @@ Remote control your inchworm with another @boardname@ You will need one more @boardname@ for this part. By using the radio, we can control the inchworm with another @boardname@. Download the code below to the @boardname@ on the inchworm and then again onto a "controller" @boardname@. Whenever button **A** is pressed, the inchworm moves once. ```blocks -radio.onDataPacketReceived(({receivedNumber}) => { +radio.onReceivedNumber(({ receivedNumber }) => { pins.servoWritePin(AnalogPin.P0, 0) basic.pause(500) pins.servoWritePin(AnalogPin.P0, 180) diff --git a/docs/projects/light-monster/connect.md b/docs/projects/light-monster/connect.md index 5e67d23f..e3064d3a 100644 --- a/docs/projects/light-monster/connect.md +++ b/docs/projects/light-monster/connect.md @@ -11,7 +11,7 @@ Remote control your monster with another @boardname@. You will need one more @boardname@ for this part. By using the radio, we can control the monster with another @boardname@. Download the code below to the @boardname@ on the monster and then again onto a "controller" @boardname@. Whenever button **A** is pressed, the monster's mouth moves once. ```blocks -radio.onDataPacketReceived(({receivedNumber}) => { +radio.onReceivedNumber(({ receivedNumber }) => { pins.servoWritePin(AnalogPin.P0, 30) basic.pause(500) pins.servoWritePin(AnalogPin.P0, 150) diff --git a/docs/projects/milk-carton-robot/connect.md b/docs/projects/milk-carton-robot/connect.md index 2943259c..faf1750d 100644 --- a/docs/projects/milk-carton-robot/connect.md +++ b/docs/projects/milk-carton-robot/connect.md @@ -12,7 +12,7 @@ You will need 2 @boardname@ for this part. By using the radio, we can make the M Download the code below to the @boardname@ on the Milk Carton Monster and another "controller" @boardname@. Whenere ``A`` is pressed, the Milk Carton Monster will move once. ```blocks -radio.onDataPacketReceived(({receivedNumber}) => { +radio.onReceivedNumber(({ receivedNumber }) => { pins.servoWritePin(AnalogPin.P0, 0) basic.pause(500) pins.servoWritePin(AnalogPin.P0, 180) diff --git a/docs/projects/milky-monster/connect.md b/docs/projects/milky-monster/connect.md index cbe2629d..a4636a2f 100644 --- a/docs/projects/milky-monster/connect.md +++ b/docs/projects/milky-monster/connect.md @@ -12,7 +12,7 @@ You will need a second @boardname@ for this part. By using the radio, we can con Download the code below to the @boardname@ that's on the Milky Monster and again to another "controller" @boardname@. Whenever button **A** is pressed, the Milky Monster will move one time. ```blocks -radio.onDataPacketReceived(({receivedNumber}) => { +radio.onReceivedNumber(({ receivedNumber }) => { pins.servoWritePin(AnalogPin.P0, 0) basic.pause(500) pins.servoWritePin(AnalogPin.P0, 180) diff --git a/docs/projects/mood-radio.md b/docs/projects/mood-radio.md index 4cddf1c8..3c2fa2a8 100644 --- a/docs/projects/mood-radio.md +++ b/docs/projects/mood-radio.md @@ -23,12 +23,12 @@ input.onButtonPressed(Button.A, () => { ## Receiving a smiley -We add a ``||radio:on radio received||`` block that will run code whenever a new "mood" message comes in. +We add a ``||radio:on received number||`` block that will run code whenever a new "mood" message comes in. The ``receivedNumber`` variable contains the numeric value that was sent. Since we've decided that `0` is **smiley**, we add a conditional ``||logic:if then||`` statement to show this icon. ```blocks -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { basic.showIcon(IconNames.Happy) } @@ -46,10 +46,10 @@ input.onButtonPressed(Button.B, () => { }) ``` -If the ``||radio:on radio received||`` block, we add another conditional ``||logic:if then||`` statement to handle the **frowny** "mood code". +If the ``||radio:on received number||`` block, we add another conditional ``||logic:if then||`` statement to handle the **frowny** "mood code". ```blocks -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { basic.showIcon(IconNames.Happy) } @@ -76,7 +76,7 @@ input.onButtonPressed(Button.B, () => { radio.sendNumber(1) basic.showIcon(IconNames.Sad) }) -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { if (receivedNumber == 0) { basic.showIcon(IconNames.Happy) } diff --git a/docs/projects/multi-dice.md b/docs/projects/multi-dice.md index 708931b1..5fdadba6 100644 --- a/docs/projects/multi-dice.md +++ b/docs/projects/multi-dice.md @@ -89,3 +89,7 @@ radio.onReceivedNumber(function (receivedNumber) { } }) ``` + +```package +radio +``` \ No newline at end of file diff --git a/docs/projects/radio-bridge.md b/docs/projects/radio-bridge.md index cec9f882..a53bd7f2 100644 --- a/docs/projects/radio-bridge.md +++ b/docs/projects/radio-bridge.md @@ -11,7 +11,7 @@ let group = 0 /** * Send all received packets to serial output */ -radio.onDataPacketReceived(function () { +radio.onReceivedNumber(function (receivedNumber) { radio.writeReceivedPacketToSerial() led.toggle(Math.randomRange(0, 4), Math.randomRange(0, 4)) }) diff --git a/docs/projects/rc-car/connect.md b/docs/projects/rc-car/connect.md index 7e31713f..f020ebc4 100644 --- a/docs/projects/rc-car/connect.md +++ b/docs/projects/rc-car/connect.md @@ -7,10 +7,10 @@ https://youtu.be/XXesoUC0XBU We can use the radio on the @boardname@ to control the toy car remotely. A second @boardname@ will send commands to control the throttle and the steering. -```blocks-ignore +```blocks let steering = 0 let throttle = 0 -radio.onDataPacketReceived( ({ receivedString: name, receivedNumber: value }) => { +radio.onReceivedValue(function (name: string, value: number) { led.toggle(0, 0) if (name == "throttle") { if (value > 0) { diff --git a/docs/projects/rps-teams.md b/docs/projects/rps-teams.md index c8a53442..e44ecad9 100644 --- a/docs/projects/rps-teams.md +++ b/docs/projects/rps-teams.md @@ -97,7 +97,7 @@ let players: number[] = [0] ## Step 4: Receiving a message (part 1) -In an ``||radio:on radio received||`` event, we receive the status from another @boardname@. Click on the **gearwheel** to add the ``serial`` parameter as we will need it to identify who sent that packet. +In an ``||radio:on received number||`` event, we receive the status from another @boardname@. Click on the **gearwheel** to add the ``serial`` parameter as we will need it to identify who sent that packet. We compute three values from the data received: @@ -111,7 +111,9 @@ let player_index = 0 let players: number[] = [0] let tool = 0 let found = false -radio.onDataPacketReceived(({ receivedNumber, serial: serialNumber }) => { +let serialNumber = 0; +radio.onReceivedNumber(function (receivedNumber) { + serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber) match = tool == receivedNumber player_index = players.indexOf(serialNumber) found = player_index >= 0 @@ -134,7 +136,9 @@ let players: number[] = [0] let tool = 0 let found = false let temp = 0 -radio.onDataPacketReceived(({ receivedNumber, serial: serialNumber }) => { +let serialNumber = 0; +radio.onReceivedNumber(function (receivedNumber) { + serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber) match = tool == receivedNumber player_index = players.indexOf(serialNumber) found = player_index >= 0 @@ -183,11 +187,9 @@ let player_index = 0 let tool = 0 let match = false let players: number[] = [] -input.onGesture(Gesture.Shake, () => { - players = [0] - tool = Math.randomRange(0, 3) -}) -radio.onDataPacketReceived( ({ receivedNumber, serial: serialNumber }) => { +let serialNumber = 0; +radio.onReceivedNumber(function (receivedNumber) { + serialNumber = radio.receivedPacket(RadioPacketProperty.SerialNumber) match = tool == receivedNumber player_index = players.indexOf(serialNumber) found = player_index >= 0 @@ -198,6 +200,10 @@ radio.onDataPacketReceived( ({ receivedNumber, serial: serialNumber }) => { temp = players.removeAt(player_index) } }) +input.onGesture(Gesture.Shake, () => { + players = [0] + tool = Math.randomRange(0, 3) +}) basic.forever(() => { radio.sendNumber(tool) if (tool == 0) { diff --git a/docs/projects/tele-potato.md b/docs/projects/tele-potato.md index 2ecfc974..02153ba1 100644 --- a/docs/projects/tele-potato.md +++ b/docs/projects/tele-potato.md @@ -77,7 +77,7 @@ input.onGesture(Gesture.Shake, () => { ### Receiving the potato -Receiving the potato is done in the [``||radio:on radio received||``](/reference/radio/on-data-packet-received) block. +Receiving the potato is done in the [``||radio:on received number||``](/reference/radio/on-received-number) block. The **receivedNumber** represents the potato and is stored in the **potato** variable. ```blocks diff --git a/docs/projects/turtle-scanner.md b/docs/projects/turtle-scanner.md index fabe8a18..ccd6830a 100644 --- a/docs/projects/turtle-scanner.md +++ b/docs/projects/turtle-scanner.md @@ -31,5 +31,5 @@ basic.forever(() => { ``` ```package -microturtle=github:Microsoft/pxt-microturtle#master +microturtle=github:Microsoft/pxt-microturtle#v0.0.9 ``` diff --git a/docs/projects/turtle-spiral.md b/docs/projects/turtle-spiral.md index b1a36d32..d88f9382 100644 --- a/docs/projects/turtle-spiral.md +++ b/docs/projects/turtle-spiral.md @@ -31,5 +31,5 @@ basic.forever(() => { ``` ```package -microturtle=github:Microsoft/pxt-microturtle#master +microturtle=github:Microsoft/pxt-microturtle#v0.0.9 ``` diff --git a/docs/projects/turtle-square.md b/docs/projects/turtle-square.md index 2dd4eb50..fe48cd69 100644 --- a/docs/projects/turtle-square.md +++ b/docs/projects/turtle-square.md @@ -74,5 +74,5 @@ input.onButtonPressed(Button.A, function() { ``` ```package -microturtle=github:Microsoft/pxt-microturtle#master +microturtle=github:Microsoft/pxt-microturtle#v0.0.9 ``` diff --git a/docs/reference/music/set-play-tone.md b/docs/reference/music/set-play-tone.md index 82ab4a88..81c168cd 100644 --- a/docs/reference/music/set-play-tone.md +++ b/docs/reference/music/set-play-tone.md @@ -21,7 +21,7 @@ input.onButtonPressed(Button.A, () => { music.playTone(440, 120) led.toggle(0, 0) }) -radio.onDataPacketReceived( ({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { const freq = receivedNumber >> 16; const duration = receivedNumber & 0xffff; music.playTone(freq, duration); diff --git a/docs/reference/radio/on-data-packet-received.md b/docs/reference/radio/on-data-packet-received.md index 04f8d891..7996f113 100644 --- a/docs/reference/radio/on-data-packet-received.md +++ b/docs/reference/radio/on-data-packet-received.md @@ -34,7 +34,7 @@ thing from nearby @boardname@s. It shows these numbers as a basic.forever(() => { radio.sendNumber(input.acceleration(Dimension.X)); }) -radio.onDataPacketReceived(({ receivedNumber }) => { +radio.onReceivedNumber(function (receivedNumber) { led.plotBarGraph(receivedNumber, 1023); }) ``` diff --git a/docs/reference/radio/on-data-received.md b/docs/reference/radio/on-data-received.md index b60d3517..7c2c2c07 100644 --- a/docs/reference/radio/on-data-received.md +++ b/docs/reference/radio/on-data-received.md @@ -1,6 +1,6 @@ # On Data Received -> Note: This API has been deprecated! Use [on data packet received](/reference/radio/on-data-packet-received) instead. +> Note: This API has been deprecated! Use [on received number](/reference/radio/on-received-number) instead. Run part of a program when the @boardname@ receives a [number](/types/number) or [string](/types/string) over ``radio``. @@ -28,7 +28,7 @@ radio.onDataReceived(() => { ## See also -[on data packet received](/reference/radio/on-data-packet-received), +[on received number](/reference/radio/on-received-number), [send number](/reference/radio/send-number), [set group](/reference/radio/set-group) ```package diff --git a/docs/reference/radio/on-received-buffer.md b/docs/reference/radio/on-received-buffer.md new file mode 100644 index 00000000..e87e4627 --- /dev/null +++ b/docs/reference/radio/on-received-buffer.md @@ -0,0 +1,58 @@ +# on Received Buffer + +Run part of a program when the @boardname@ receives a buffer over ``radio``. + +```sig +radio.onReceivedBuffer(function (receivedBuffer) {}) +``` + +## Parameters + +* **receivedBuffer**: The buffer that was sent in this packet or the empty string if this packet did not contain a string. See [send buffer](/reference/radio/send-buffer) + +## Example: Remote level + +If you load this program onto two @boardname@s, each board will send the level information to the other board. + +```typescript +let ax = 0; +let ay = 0; +basic.forever(() => { + ax = input.acceleration(Dimension.X); + ay = input.acceleration(Dimension.Y); + + // encode data in buffer + let buf = pins.createBuffer(4) + buf.setNumber(NumberFormat.Int16LE, 0, ax) + buf.setNumber(NumberFormat.Int16LE, 2, ay) + radio.sendBuffer(buf) +}) + +radio.onReceivedBuffer(function (receivedBuffer) { + // decode data from buffer + ax = receivedBuffer.getNumber(NumberFormat.Int16LE, 0); + ay = receivedBuffer.getNumber(NumberFormat.Int16LE, 2); + + // display + basic.clearScreen() + led.plot( + pins.map(ax, -1023, 1023, 0, 4), + pins.map(ay, -1023, 1023, 0, 4) + ) +}); +``` + + +## ~hint + +A radio that can both transmit and receive is called a _transceiver_. + +## ~ + +## See also + +[send buffer](/reference/radio/send-buffer) + +```package +radio +``` diff --git a/docs/reference/radio/on-received-number.md b/docs/reference/radio/on-received-number.md index 5243f2de..3314c048 100644 --- a/docs/reference/radio/on-received-number.md +++ b/docs/reference/radio/on-received-number.md @@ -40,7 +40,7 @@ basic.forever(() => { }) radio.onReceivedNumber(function (receivedNumber) { led.plotBarGraph( - Math.abs(radio.getReceivedPacketProperty(radio.PacketProperty.SignalStrength) + 42), + Math.abs(radio.receivedPacket(RadioPacketProperty.SignalStrength) + 42), 128 - 42 ) }) @@ -54,7 +54,7 @@ The radio set group might need to be set, synchronized , before the radio events ## See also -[on received strig](/reference/radio/on-received-string), +[on received string](/reference/radio/on-received-string), [send number](/reference/radio/send-number), [send string](/reference/radio/send-string), [send value](/reference/radio/send-value), diff --git a/docs/reference/radio/receive-number.md b/docs/reference/radio/receive-number.md index 93dc6190..d6fcbfbb 100644 --- a/docs/reference/radio/receive-number.md +++ b/docs/reference/radio/receive-number.md @@ -1,6 +1,6 @@ # Receive Number -> Note: This API has been deprecated! Use [on data packet received](/reference/radio/on-data-packet-received) instead. +> Note: This API has been deprecated! Use [on received number](/reference/radio/on-received-number) instead. Receives the next number sent by a @boardname@ in the same ``radio`` group. diff --git a/docs/reference/radio/receive-string.md b/docs/reference/radio/receive-string.md index 0763dc35..190e6d10 100644 --- a/docs/reference/radio/receive-string.md +++ b/docs/reference/radio/receive-string.md @@ -1,6 +1,6 @@ # Receive String -> Note: This API has been deprecated! Use [on data packet received](/reference/radio/on-data-packet-received) instead. +> Note: This API has been deprecated! Use [on received string](/reference/radio/on-received-string) instead. Find the next string sent by `radio` from another @boardname@. diff --git a/docs/reference/radio/get-received-packet-property.md b/docs/reference/radio/received-packet.md similarity index 81% rename from docs/reference/radio/get-received-packet-property.md rename to docs/reference/radio/received-packet.md index dd21787f..4c198d23 100644 --- a/docs/reference/radio/get-received-packet-property.md +++ b/docs/reference/radio/received-packet.md @@ -1,9 +1,9 @@ -# get Received Packet Property +# Received Packet Property Get one of the properties from the last received radio packet. ```sig -radio.getReceivedPacketProperty(radio.PacketProperty.SignalStrength) +radio.receivedPacket(RadioPacketProperty.SignalStrength) ``` ## Parameters @@ -28,7 +28,7 @@ basic.forever(() => { }) radio.onReceivedNumber(function (receivedNumber) { led.plotBarGraph( - Math.abs(radio.getReceivedPacketProperty(radio.PacketProperty.SignalStrength) + 42), + Math.abs(radio.receivedPacket(RadioPacketProperty.SignalStrength) + 42), 128 - 42 ) }) @@ -37,3 +37,7 @@ radio.onReceivedNumber(function (receivedNumber) { ## See also [set transmit serial number](/reference/radio/set-transmit-serial-number) + +```package +radio +``` \ No newline at end of file diff --git a/docs/reference/radio/received-signal-strength.md b/docs/reference/radio/received-signal-strength.md index 90b1a913..9545cf5c 100644 --- a/docs/reference/radio/received-signal-strength.md +++ b/docs/reference/radio/received-signal-strength.md @@ -7,7 +7,7 @@ Find how strong the ``radio`` signal is, from `-128` to `-42`. The @boardname@ finds the signal strength by checking how strong it was the last time it ran the -[on data packet received](/reference/radio/on-data-packet-received) function. That means +[on received number](/reference/radio/on-received-number) function. That means it needs to run **receive number** first. ```sig @@ -39,7 +39,7 @@ basic.forever(() => { ## See also -[on data packet received](/reference/radio/on-data-packet-received), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received) +[on received number](/reference/radio/on-received-number), [send number](/reference/radio/send-number), [on data received](/reference/radio/on-data-received) ```package radio diff --git a/docs/reference/radio/send-buffer.md b/docs/reference/radio/send-buffer.md index 7cfbdb50..5d4975de 100644 --- a/docs/reference/radio/send-buffer.md +++ b/docs/reference/radio/send-buffer.md @@ -30,7 +30,7 @@ basic.forever(() => { radio.sendBuffer(buf) }) -radio.onDataPacketReceived(({ receivedBuffer }) => { +radio.onReceivedBuffer(function (receivedBuffer) { // decode data from buffer ax = receivedBuffer.getNumber(NumberFormat.Int16LE, 0); ay = receivedBuffer.getNumber(NumberFormat.Int16LE, 2); @@ -52,7 +52,7 @@ A radio that can both transmit and receive is called a _transceiver_. ## See also -[on data packet received](/reference/radio/on-data-packet-received) +[on received buffer](/reference/radio/on-received-buffer) ```package radio diff --git a/docs/reference/radio/set-transmit-power.md b/docs/reference/radio/set-transmit-power.md index 29b58b3a..f680116e 100644 --- a/docs/reference/radio/set-transmit-power.md +++ b/docs/reference/radio/set-transmit-power.md @@ -35,7 +35,7 @@ radio.setTransmitPower(7) ## See also -[get received packet property](/reference/radio/get-received-packet-property), +[received packet](/reference/radio/received-packet), [send number](/reference/radio/send-number), [send value](/reference/radio/send-value), [send string](/reference/radio/send-string) diff --git a/docs/reference/radio/set-transmit-serial-number.md b/docs/reference/radio/set-transmit-serial-number.md index 0afe876a..186b6cf5 100644 --- a/docs/reference/radio/set-transmit-serial-number.md +++ b/docs/reference/radio/set-transmit-serial-number.md @@ -20,7 +20,7 @@ radio.setTransmitSerialNumber(true); ## See also -[get received packet property](/reference/radio/get-received-packet-property), +[received packet property](/reference/radio/received-packet), [send number](/reference/radio/send-number), [send value](/reference/radio/send-value), [send string](/reference/radio/send-string) diff --git a/docs/reference/radio/write-received-packet-to-serial.md b/docs/reference/radio/write-received-packet-to-serial.md index 5c4b0e4a..abdeac78 100644 --- a/docs/reference/radio/write-received-packet-to-serial.md +++ b/docs/reference/radio/write-received-packet-to-serial.md @@ -36,7 +36,7 @@ input.onButtonPressed(Button.A, () => { }); -radio.onDataPacketReceived(() => { +radio.onReceivedNumber(function (receivedNumber) { radio.writeReceivedPacketToSerial(); }); ``` diff --git a/libs/radio/_locales/radio-jsdoc-strings.json b/libs/radio/_locales/radio-jsdoc-strings.json index f78b49f5..956b275b 100644 --- a/libs/radio/_locales/radio-jsdoc-strings.json +++ b/libs/radio/_locales/radio-jsdoc-strings.json @@ -8,8 +8,6 @@ "radio.Packet.time": "The system time of the sender of the packet at the time the packet was sent.", "radio._packetProperty": "Gets a packet property.", "radio._packetProperty|param|type": "the packet property type, eg: PacketProperty.time", - "radio.getReceivedPacketProperty": "Returns properties of the last radio packet received.", - "radio.getReceivedPacketProperty|param|type": "the type of property to retrieve from the last packet", "radio.onDataPacketReceived": "Registers code to run when the radio receives a packet. Also takes the\nreceived packet from the radio queue.", "radio.onDataReceived": "Registers code to run when a packet is received over radio.", "radio.onReceivedBuffer": "Registers code to run when the radio receives a buffer.", @@ -21,6 +19,8 @@ "radio.receiveString": "Reads the next packet from the radio queue and returns the packet's string\npayload or the empty string if the packet did not contain a string.", "radio.receivedBuffer": "Returns the buffer payload from the last packet taken from the radio queue\n(via ``receiveNumber``, ``receiveString``, etc) or the empty string if that\npacket did not contain a string.", "radio.receivedNumber": "Returns the number payload from the last packet taken from the radio queue\n(via ``receiveNumber``, ``receiveString``, etc) or 0 if that packet did not\ncontain a number.", + "radio.receivedPacket": "Returns properties of the last radio packet received.", + "radio.receivedPacket|param|type": "the type of property to retrieve from the last packet", "radio.receivedSerial": "Returns the serial number of the sender micro:bit from the last packet taken\nfrom the radio queue (via ``receiveNumber``, ``receiveString``, etc) or 0 if\nthat packet did not send a serial number.", "radio.receivedSignalStrength": "Gets the received signal strength indicator (RSSI) from the last packet taken\nfrom the radio queue (via ``receiveNumber``, ``receiveString``, etc). Not supported in simulator.\nnamespace=radio", "radio.receivedString": "Returns the string payload from the last packet taken from the radio queue\n(via ``receiveNumber``, ``receiveString``, etc) or the empty string if that\npacket did not contain a string.", diff --git a/libs/radio/_locales/radio-strings.json b/libs/radio/_locales/radio-strings.json index e2479f5b..24604dfc 100644 --- a/libs/radio/_locales/radio-strings.json +++ b/libs/radio/_locales/radio-strings.json @@ -1,9 +1,8 @@ { - "radio.PacketProperty.SerialNumber|block": "serial number", - "radio.PacketProperty.SignalStrength|block": "signal strength", - "radio.PacketProperty.Time|block": "time", + "RadioPacketProperty.SerialNumber|block": "serial number", + "RadioPacketProperty.SignalStrength|block": "signal strength", + "RadioPacketProperty.Time|block": "time", "radio._packetProperty|block": "%note", - "radio.getReceivedPacketProperty|block": "received packet %type=radio_packet_property", "radio.onDataPacketReceived|block": "on radio received", "radio.onDataReceived|block": "radio on data received", "radio.onReceivedBuffer|block": "on radio received", @@ -13,6 +12,7 @@ "radio.raiseEvent|block": "radio raise event|from source %src=control_event_source_id|with value %value=control_event_value_id", "radio.receiveNumber|block": "radio receive number", "radio.receiveString|block": "radio receive string", + "radio.receivedPacket|block": "received packet %type=radio_packet_property", "radio.receivedSignalStrength|block": "radio received signal strength", "radio.sendNumber|block": "radio send number %value", "radio.sendString|block": "radio send string %msg", diff --git a/libs/radio/radio.ts b/libs/radio/radio.ts index a0f5e607..896283bb 100644 --- a/libs/radio/radio.ts +++ b/libs/radio/radio.ts @@ -1,3 +1,16 @@ + +enum RadioPacketProperty { + //% blockIdentity=radio._packetProperty + //% block="signal strength" + SignalStrength = 2, + //% blockIdentity=radio._packetProperty + //% block="time" + Time = 0, + //% block="serial number" + //% blockIdentity=radio._packetProperty + SerialNumber = 1 +} + /** * Communicate data using radio packets */ @@ -33,18 +46,6 @@ namespace radio { public signal: number; } - export enum PacketProperty { - //% blockIdentity=radio._packetProperty - //% block="time" - Time, - //% block="serial number" - //% blockIdentity=radio._packetProperty - SerialNumber, - //% blockIdentity=radio._packetProperty - //% block="signal strength" - SignalStrength - } - /** * Registers code to run when the radio receives a packet. Also takes the * received packet from the radio queue. @@ -133,7 +134,7 @@ namespace radio { //% help=radio/on-received-buffer blockHandlerKey="radioreceived" blockHidden=1 //% blockId=radio_on_buffer block="on radio received" blockGap=16 //% useLoc="radio.onDataPacketReceived" - export function onReceivedBuffer(cb: (buffer: Buffer) => void) { + export function onReceivedBuffer(cb: (receivedBuffer: Buffer) => void) { onDataReceived(() => { receiveNumber(); const packet = new Packet(); @@ -151,14 +152,15 @@ namespace radio { * Returns properties of the last radio packet received. * @param type the type of property to retrieve from the last packet */ - //% help=radio/get-received-packet-property advanced=true - //% blockId=radio_received_packet_property block="received packet %type=radio_packet_property" blockGap=16 - export function getReceivedPacketProperty(type: number) { + //% help=radio/received-packet + //% weight=11 blockGap=8 + //% blockId=radio_received_packet block="received packet %type=radio_packet_property" blockGap=16 + export function receivedPacket(type: number) { if (lastPacket) { switch(type) { - case PacketProperty.Time: return lastPacket.time; - case PacketProperty.SerialNumber: return lastPacket.serial; - case PacketProperty.SignalStrength: return lastPacket.signal; + case RadioPacketProperty.Time: return lastPacket.time; + case RadioPacketProperty.SerialNumber: return lastPacket.serial; + case RadioPacketProperty.SignalStrength: return lastPacket.signal; } } return 0; @@ -170,7 +172,7 @@ namespace radio { */ //% blockId=radio_packet_property block="%note" //% shim=TD_ID blockHidden=1 - export function _packetProperty(type: PacketProperty): number { + export function _packetProperty(type: RadioPacketProperty): number { return type; } } diff --git a/pxtarget.json b/pxtarget.json index bcac50c6..262859ef 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -240,7 +240,7 @@ "productId": "0x0204", "rawHID": true }, - "ignoreDocsErrors": true, + "ignoreDocsErrors": true, "appTheme": { "accentColor": "#5C005C", "logoUrl": "https://microbit.org/code/",