From a19d1c848b64ce96a0de55947d0959cf43e0bb1a Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 17 Oct 2016 16:18:04 -0700 Subject: [PATCH 01/15] renaming board name --- pxtarget.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pxtarget.json b/pxtarget.json index 4cd7e1fd..80173f11 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -249,7 +249,7 @@ "path": "/browsers/windows" } ], - "boardName": "BBC micro:bit", + "boardName": "micro:bit", "docMenu": [ { "name": "Getting Started", From ec910cb10f361f08b1893aec20112cf85c9a8ca9 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 17 Oct 2016 16:45:17 -0700 Subject: [PATCH 02/15] Bump pxt-core to 0.4.60 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5f335312..b804d36a 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.4.58" + "pxt-core": "0.4.60" } } From c3b2b99d7cab0658d2d2eed7672b4a4db875d8c1 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 17 Oct 2016 16:45:20 -0700 Subject: [PATCH 03/15] 0.4.50 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b804d36a..78ad81d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.4.49", + "version": "0.4.50", "description": "micro:bit target for PXT", "keywords": [ "JavaScript", From 932c01f394b079a593891e2deafbb53b59c205af Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 17 Oct 2016 21:12:30 -0700 Subject: [PATCH 04/15] Bump pxt-core to 0.4.62 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 78ad81d5..baebcaa4 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.4.60" + "pxt-core": "0.4.62" } } From 1fbf25761978032bfa0e9bbba019beaa64188579 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Mon, 17 Oct 2016 21:12:33 -0700 Subject: [PATCH 05/15] 0.4.51 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index baebcaa4..89de2ace 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.4.50", + "version": "0.4.51", "description": "micro:bit target for PXT", "keywords": [ "JavaScript", From 135aaf48555e72c056b51b98ca345a4c9179bcfd Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 09:08:25 -0700 Subject: [PATCH 06/15] 0.4.52 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 89de2ace..be838d4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.4.51", + "version": "0.4.52", "description": "micro:bit target for PXT", "keywords": [ "JavaScript", From 81b66664efd63c136d388a9d6a2d2e1a2137e6de Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 13:18:19 -0700 Subject: [PATCH 07/15] Bump pxt-core to 0.4.63 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be838d4e..1ff7cb9c 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.4.62" + "pxt-core": "0.4.63" } } From 5eb8704382c0f07f04fc6cb1746499f225573ec9 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 13:18:20 -0700 Subject: [PATCH 08/15] 0.4.53 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ff7cb9c..3299d7c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.4.52", + "version": "0.4.53", "description": "micro:bit target for PXT", "keywords": [ "JavaScript", From fba37d96b2772721cbcbe711692dffe647433036 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 13:19:46 -0700 Subject: [PATCH 09/15] updated localization help --- docs/translate.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/translate.md b/docs/translate.md index 053e3155..5d978662 100644 --- a/docs/translate.md +++ b/docs/translate.md @@ -16,13 +16,9 @@ You will find two files in that project: ## Translating the blocks and reference documentation -The project below contains the resources from the blocks and functions using in the https://codethemicrobit.com. +You will find package files under ``/microbit`` , one for the block definition and one for the descriptions: -* [https://crowdin.com/project/pxt-microbit](https://crowdin.com/project/pxt-microbit) - -You will find two files for each package available in the micro:bit, one for the block definition and one for the descriptions: - -* ``microbit-strings.json``: contains the block definitions -* ``microbit-jsdoc-strings.json``: contains the descriptions +* ``core-strings.json``: contains the block definitions +* ``core-jsdoc-strings.json``: contains the descriptions The block definition should be carefully translated using the [block definition syntax](https://www.pxt.io/defining-blocks). \ No newline at end of file From 58ae4945cb12809c634120cedb6d3ed0b04e0dcd Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 21:03:34 -0700 Subject: [PATCH 10/15] Bump pxt-core to 0.4.65 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3299d7c5..98f06819 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.4.63" + "pxt-core": "0.4.65" } } From 75baca4a97c44a0d631bc7d025fa81fed7c7c96a Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 21:03:36 -0700 Subject: [PATCH 11/15] 0.4.54 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 98f06819..8686a3ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.4.53", + "version": "0.4.54", "description": "micro:bit target for PXT", "keywords": [ "JavaScript", From ae5d5c74a7c36fc8fa35b3f7e342ae0e4ae17cde Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 21:36:42 -0700 Subject: [PATCH 12/15] better support for BLE UART and alignment with serial blocks. (#276) * aligning uart apis with serial * reorganizing serial/bluetooth blocks * Autoupdate configuration for UART. (#279) * Autoupdate configuration for UART. * removing serial autoupdates. --- docs/reference/bluetooth.md | 40 +++++++--- .../{uart-read.md => uart-read-until.md} | 4 +- docs/reference/bluetooth/uart-write-number.md | 28 +++++++ .../{uart-write.md => uart-write-string.md} | 8 +- docs/reference/bluetooth/uart-write-value.md | 28 +++++++ libs/bluetooth/bluetooth.cpp | 78 ++++++++----------- libs/bluetooth/bluetooth.ts | 62 ++++++++------- libs/bluetooth/enums.d.ts | 16 ---- libs/bluetooth/shims.d.ts | 74 +++++++++--------- libs/core/enums.d.ts | 16 ++++ libs/core/serial.cpp | 58 ++++++++++---- libs/core/serial.ts | 20 +++++ libs/core/shims.d.ts | 17 +++- pxtarget.json | 7 ++ sim/state/misc.ts | 2 +- 15 files changed, 294 insertions(+), 164 deletions(-) rename docs/reference/bluetooth/{uart-read.md => uart-read-until.md} (96%) mode change 100755 => 100644 create mode 100644 docs/reference/bluetooth/uart-write-number.md rename docs/reference/bluetooth/{uart-write.md => uart-write-string.md} (86%) mode change 100755 => 100644 create mode 100644 docs/reference/bluetooth/uart-write-value.md diff --git a/docs/reference/bluetooth.md b/docs/reference/bluetooth.md index 5a34e62f..5fd0543e 100644 --- a/docs/reference/bluetooth.md +++ b/docs/reference/bluetooth.md @@ -2,6 +2,14 @@ Support for additional Bluetooth services. +### ~hint +![](/static/bluetooth/Bluetooth_SIG.png) + +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + + ```cards bluetooth.startAccelerometerService(); bluetooth.startButtonService(); @@ -9,20 +17,34 @@ bluetooth.startIOPinService(); bluetooth.startLEDService(); bluetooth.startMagnetometerService(); bluetooth.startTemperatureService(); -bluetooth.uartRead(""); -bluetooth.uartWrite(""); -bluetooth.onBluetoothConnected(() => { - -}); -bluetooth.onBluetoothDisconnected(() => { - -}); +bluetooth.onBluetoothConnected(() => {}); +bluetooth.onBluetoothDisconnected(() => {}); +``` + +## UART + +```cards +bluetooth.startUartService(); +bluetooth.uartReadUntil(""); +bluetooth.uartWriteString(""); +bluetooth.uartWriteNumber(0); +bluetooth.uartWriteValue("", 0); ``` ```package microbit-bluetooth ``` +### Advanced + +For more advanced information on the micro:bit Bluetooth UART service including information on using a smartphone, see the [Lancaster University micro:bit runtime technical documentation](http://lancaster-university.github.io/microbit-docs/ble/uart-service/) + ### See Also -[startAccelerometerService](/reference/bluetooth/start-accelerometer-service), [startButtonService](/reference/bluetooth/start-button-service), [startIOPinService](/reference/bluetooth/start-io-pin-service), [startLEDService](/reference/bluetooth/start-led-service), [startMagnetometerService](/reference/bluetooth/start-magnetometer-service), [startTemperatureService](/reference/bluetooth/start-temperature-service), [uartRead](/reference/bluetooth/uart-read), [uartWrite](/reference/bluetooth/uart-write), [onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), [onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected) +[startAccelerometerService](/reference/bluetooth/start-accelerometer-service), [startButtonService](/reference/bluetooth/start-button-service), [startIOPinService](/reference/bluetooth/start-io-pin-service), [startLEDService](/reference/bluetooth/start-led-service), [startMagnetometerService](/reference/bluetooth/start-magnetometer-service), [startTemperatureService](/reference/bluetooth/start-temperature-service), +[startUartService](/reference/bluetooth/start-uart-service), +[uartReadUntil](/reference/bluetooth/uart-read-until), +[uartWriteString](/reference/bluetooth/uart-write-string), +[uartWriteNumber](/reference/bluetooth/uart-write-number), +[uartWriteValue](/reference/bluetooth/uart-write-value), +[onBluetoothConnected](/reference/bluetooth/on-bluetooth-connected), [onBluetoothDisconnected](/reference/bluetooth/on-bluetooth-disconnected) diff --git a/docs/reference/bluetooth/uart-read.md b/docs/reference/bluetooth/uart-read-until.md old mode 100755 new mode 100644 similarity index 96% rename from docs/reference/bluetooth/uart-read.md rename to docs/reference/bluetooth/uart-read-until.md index b7295109..189e9afd --- a/docs/reference/bluetooth/uart-read.md +++ b/docs/reference/bluetooth/uart-read-until.md @@ -12,7 +12,7 @@ The [Bluetooth UART service](start-uart-service.md) allows another device such a With the Bluetooth UART service running, this block allows a micro:bit to read data which has been received from a Bluetooth connected device, terminating reading and returning the value obtained as soon as a specified delimiter character is encountered. This means that connected devices can send data to the micro:bit and indicate that the complete message has been sent by appending the message with the delimiter character. ```sig -bluetooth.uartRead(""); +bluetooth.uartReadUntil(""); ``` ### Example: Starting the Bluetooth UART service and then reading data received from another device which is terminated by ":" character and then displaying it @@ -25,7 +25,7 @@ bluetooth.onBluetoothConnected(() => { basic.showString("C"); connected = 1; while (connected == 1) { - uartData = bluetooth.uartRead(":"); + uartData = bluetooth.uartReadUntil(":"); basic.showString(uartData); } }); diff --git a/docs/reference/bluetooth/uart-write-number.md b/docs/reference/bluetooth/uart-write-number.md new file mode 100644 index 00000000..8ee099aa --- /dev/null +++ b/docs/reference/bluetooth/uart-write-number.md @@ -0,0 +1,28 @@ +# UART Write Number + +### ~hint +![](/static/bluetooth/Bluetooth_SIG.png) + +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + +The [Bluetooth UART service](/reference/bluetooth/start-uart-service.md) allows another device such as a smartphone to exchange any data it wants to with the micro:bit, in small chunks. + +With the Bluetooth UART service running, this block allows a micro:bit to send data to a Bluetooth connected device. + +```sig +bluetooth.uartWriteNumber(42); +``` + +### Advanced + +For more advanced information on the micro:bit Bluetooth UART service including information on using a smartphone, see the [Lancaster University micro:bit runtime technical documentation](http://lancaster-university.github.io/microbit-docs/ble/uart-service/) + +### See also + +[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com) + +```package +microbit-bluetooth +``` diff --git a/docs/reference/bluetooth/uart-write.md b/docs/reference/bluetooth/uart-write-string.md old mode 100755 new mode 100644 similarity index 86% rename from docs/reference/bluetooth/uart-write.md rename to docs/reference/bluetooth/uart-write-string.md index 21008b75..aa368f99 --- a/docs/reference/bluetooth/uart-write.md +++ b/docs/reference/bluetooth/uart-write-string.md @@ -1,4 +1,4 @@ -# UART Write +# UART Write Number ### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) @@ -7,12 +7,12 @@ For another device like a smartphone to use any of the Bluetooth "services" whic ### ~ -The [Bluetooth UART service](start-uart-service.md) allows another device such as a smartphone to exchange any data it wants to with the micro:bit, in small chunks. +The [Bluetooth UART service](/reference/bluetooth/start-uart-service.md) allows another device such as a smartphone to exchange any data it wants to with the micro:bit, in small chunks. With the Bluetooth UART service running, this block allows a micro:bit to send data to a Bluetooth connected device. ```sig -bluetooth.uartWrite(""); +bluetooth.uartWriteString(""); ``` ### Example: Starting the Bluetooth UART service and then sending "HELLO" whenever button A is pressed and another device has connected over Bluetooth @@ -29,7 +29,7 @@ bluetooth.onBluetoothDisconnected(() => { }); input.onButtonPressed(Button.A, () => { if (connected == 1) { - bluetooth.uartWrite("HELLO"); + bluetooth.uartWriteString("HELLO"); } }); ``` diff --git a/docs/reference/bluetooth/uart-write-value.md b/docs/reference/bluetooth/uart-write-value.md new file mode 100644 index 00000000..f3e86816 --- /dev/null +++ b/docs/reference/bluetooth/uart-write-value.md @@ -0,0 +1,28 @@ +# UART Write Value + +### ~hint +![](/static/bluetooth/Bluetooth_SIG.png) + +For another device like a smartphone to use any of the Bluetooth "services" which the micro:bit has, it must first be [paired with the micro:bit](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the micro:bit and exchange data relating to many of the micro:bit's features. + +### ~ + +The [Bluetooth UART service](/reference/bluetooth/start-uart-service.md) allows another device such as a smartphone to exchange any data it wants to with the micro:bit, in small chunks. + +With the Bluetooth UART service running, this block allows a micro:bit to send data to a Bluetooth connected device. + +```sig +bluetooth.uartWriteValue("x", 42); +``` + +### Advanced + +For more advanced information on the micro:bit Bluetooth UART service including information on using a smartphone, see the [Lancaster University micro:bit runtime technical documentation](http://lancaster-university.github.io/microbit-docs/ble/uart-service/) + +### See also + +[About Bluetooth](/reference/bluetooth/about-bluetooth), [micro:bit Bluetooth profile overview ](http://lancaster-university.github.io/microbit-docs/ble/profile/), [micro:bit Bluetooth profile reference](http://lancaster-university.github.io/microbit-docs/resources/bluetooth/microbit-profile-V1.9-Level-2.pdf), [Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html), [Bluetooth SIG](https://www.bluetooth.com) + +```package +microbit-bluetooth +``` diff --git a/libs/bluetooth/bluetooth.cpp b/libs/bluetooth/bluetooth.cpp index 890f2f2c..007f5518 100644 --- a/libs/bluetooth/bluetooth.cpp +++ b/libs/bluetooth/bluetooth.cpp @@ -4,22 +4,6 @@ using namespace pxt; -enum Delimiters { - //% block="new line" - NewLine = 1, - //% block="," - Comma = 2, - //% block="$" - Dollar = 3, - //% block=":" - Colon = 4, - //% block="." - Fullstop = 5, - //% block="#" - Hash = 6, -}; - - /** * Support for additional Bluetooth services. */ @@ -27,12 +11,33 @@ enum Delimiters { namespace bluetooth { MicroBitUARTService *uart = NULL; + + /** + * Starts the Bluetooth accelerometer service + */ + //% help=bluetooth/start-accelerometer-service + //% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" + //% parts="bluetooth" weight=90 blockGap=8 + void startAccelerometerService() { + new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer); + } + + /** + * Starts the Bluetooth button service + */ + //% help=bluetooth/start-button-service + //% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 + //% parts="bluetooth" weight=89 + void startButtonService() { + new MicroBitButtonService(*uBit.ble); + } + /** * Starts the Bluetooth IO pin service. */ //% help=bluetooth/start-io-pin-service //% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8 - //% parts="bluetooth" + //% parts="bluetooth" weight=88 void startIOPinService() { new MicroBitIOPinService(*uBit.ble, uBit.io); } @@ -42,7 +47,7 @@ namespace bluetooth { */ //% help=bluetooth/start-led-service //% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8 - //% parts="bluetooth" + //% parts="bluetooth" weight=87 void startLEDService() { new MicroBitLEDService(*uBit.ble, uBit.display); } @@ -52,7 +57,7 @@ namespace bluetooth { */ //% help=bluetooth/start-temperature-service //% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8 - //% parts="bluetooth" + //% parts="bluetooth" weight=86 void startTemperatureService() { new MicroBitTemperatureService(*uBit.ble, uBit.thermometer); } @@ -61,38 +66,19 @@ namespace bluetooth { * Starts the Bluetooth magnetometer service */ //% help=bluetooth/start-magnetometer-service - //% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8 - //% parts="bluetooth" + //% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" + //% parts="bluetooth" weight=85 void startMagnetometerService() { new MicroBitMagnetometerService(*uBit.ble, uBit.compass); } - /** - * Starts the Bluetooth accelerometer service - */ - //% help=bluetooth/start-accelerometer-service - //% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8 - //% parts="bluetooth" - void startAccelerometerService() { - new MicroBitAccelerometerService(*uBit.ble, uBit.accelerometer); - } - - /** - * Starts the Bluetooth button service - */ - //% help=bluetooth/start-button-service - //% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 - //% parts="bluetooth" - void startButtonService() { - new MicroBitButtonService(*uBit.ble); - } /** * Starts the Bluetooth UART service */ //% help=bluetooth/start-uart-service - //% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8 - //% parts="bluetooth" + //% blockId=bluetooth_start_uart_service block="bluetooth uart service" + //% parts="bluetooth" advanced=true void startUartService() { if (uart) return; // 61 octet buffer size is 3 x (MTU - 3) + 1 @@ -102,13 +88,13 @@ namespace bluetooth { } //% - void uartWrite(StringData *data) { + void uartWriteString(StringData *data) { startUartService(); uart->send(ManagedString(data)); } //% - StringData* uartRead(StringData *del) { + StringData* uartReadUntil(StringData *del) { startUartService(); return uart->readUntil(ManagedString(del)).leakData(); } @@ -133,7 +119,5 @@ namespace bluetooth { //% parts="bluetooth" void onBluetoothDisconnected(Action body) { registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, body); - } - - + } } \ No newline at end of file diff --git a/libs/bluetooth/bluetooth.ts b/libs/bluetooth/bluetooth.ts index 05144086..f5630ddd 100644 --- a/libs/bluetooth/bluetooth.ts +++ b/libs/bluetooth/bluetooth.ts @@ -1,42 +1,48 @@ +/** + * Support for additional Bluetooth services. + */ +//% color=#0082FB weight=20 namespace bluetooth { - /** - * Returns the delimiter corresponding string - */ - //% blockId="bluetooth_uart_delimiter_conv" block="%del" - //% weight=1 parts="bluetooth" - export function delimiters(del: Delimiters): string { - // even though it might not look like, this is more - // (memory) efficient than the C++ implementation, because the - // strings are statically allocated and take no RAM - switch (del) { - case Delimiters.NewLine: return "\n" - case Delimiters.Comma: return "," - case Delimiters.Dollar: return "$" - case Delimiters.Colon: return ":" - case Delimiters.Fullstop: return "." - case Delimiters.Hash: return "#" - default: return "\n" - } - } - /** * Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device. */ - //% help=bluetooth/uart-write - //% blockId=bluetooth_uart_write block="bluetooth uart write %data" blockGap=8 - //% parts="bluetooth" shim=bluetooth::uartWrite - export function uartWrite(data: string): void { + //% help=bluetooth/uart-write weight=80 + //% blockId=bluetooth_uart_write block="bluetooth uart|write string %data" blockGap=8 + //% parts="bluetooth" shim=bluetooth::uartWriteString advanced=true + export function uartWriteString(data: string): void { // dummy implementation for simulator console.log("UART Write: " + data) } + /** + * Prints a numeric value to the serial + */ + //% help=serial/write-number weight=79 + //% weight=89 blockGap=8 advanced=true + //% blockId=bluetooth_uart_writenumber block="bluetooth uart|write number %value" + export function uartWriteNumber(value: number): void { + uartWriteString(value.toString()); + } + + /** + * Writes a ``name: value`` pair line to the serial. + * @param name name of the value stream, eg: x + * @param value to write + */ + //% weight=88 weight=78 + //% help=bluetooth/uart-write-value advanced=true + //% blockId=bluetooth_uart_writevalue block="bluetooth uart|write value %name|= %value" + export function uartWriteValue(name: string, value: number): void { + uartWriteString(name + ":" + value + "\r\n"); + } + /** * Reads from the Bluetooth UART service buffer, returning its contents when the specified delimiter character is encountered. */ - //% help=bluetooth/uart-read - //% blockId=bluetooth_uart_read block="bluetooth uart read %del=bluetooth_uart_delimiter_conv" blockGap=8 - //% parts="bluetooth" shim=bluetooth::uartRead - export function uartRead(del: string): string { + //% help=bluetooth/uart-read-until weight=75 + //% blockId=bluetooth_uart_read block="bluetooth uart|read until %del=serial_delimiter_conv" + //% parts="bluetooth" shim=bluetooth::uartReadUntil advanced=true + export function uartReadUntil(del: string): string { // dummy implementation for simulator return "???" } diff --git a/libs/bluetooth/enums.d.ts b/libs/bluetooth/enums.d.ts index b1a4cfa4..c1770c7b 100644 --- a/libs/bluetooth/enums.d.ts +++ b/libs/bluetooth/enums.d.ts @@ -1,20 +1,4 @@ // Auto-generated. Do not edit. - - - declare enum Delimiters { - //% block="new line" - NewLine = 1, - //% block="," - Comma = 2, - //% block="$" - Dollar = 3, - //% block=":" - Colon = 4, - //% block="." - Fullstop = 5, - //% block="#" - Hash = 6, - } declare namespace bluetooth { } diff --git a/libs/bluetooth/shims.d.ts b/libs/bluetooth/shims.d.ts index 31c8e34b..58c52fa9 100644 --- a/libs/bluetooth/shims.d.ts +++ b/libs/bluetooth/shims.d.ts @@ -7,44 +7,12 @@ //% color=#0082FB weight=20 declare namespace bluetooth { - /** - * Starts the Bluetooth IO pin service. - */ - //% help=bluetooth/start-io-pin-service - //% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8 - //% parts="bluetooth" shim=bluetooth::startIOPinService - function startIOPinService(): void; - - /** - * Starts the Bluetooth LED service - */ - //% help=bluetooth/start-led-service - //% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8 - //% parts="bluetooth" shim=bluetooth::startLEDService - function startLEDService(): void; - - /** - * Starts the Bluetooth temperature service - */ - //% help=bluetooth/start-temperature-service - //% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8 - //% parts="bluetooth" shim=bluetooth::startTemperatureService - function startTemperatureService(): void; - - /** - * Starts the Bluetooth magnetometer service - */ - //% help=bluetooth/start-magnetometer-service - //% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8 - //% parts="bluetooth" shim=bluetooth::startMagnetometerService - function startMagnetometerService(): void; - /** * Starts the Bluetooth accelerometer service */ //% help=bluetooth/start-accelerometer-service - //% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8 - //% parts="bluetooth" shim=bluetooth::startAccelerometerService + //% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" + //% parts="bluetooth" weight=90 blockGap=8 shim=bluetooth::startAccelerometerService function startAccelerometerService(): void; /** @@ -52,15 +20,47 @@ declare namespace bluetooth { */ //% help=bluetooth/start-button-service //% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 - //% parts="bluetooth" shim=bluetooth::startButtonService + //% parts="bluetooth" weight=89 shim=bluetooth::startButtonService function startButtonService(): void; + /** + * Starts the Bluetooth IO pin service. + */ + //% help=bluetooth/start-io-pin-service + //% blockId=bluetooth_start_io_pin_service block="bluetooth io pin service" blockGap=8 + //% parts="bluetooth" weight=88 shim=bluetooth::startIOPinService + function startIOPinService(): void; + + /** + * Starts the Bluetooth LED service + */ + //% help=bluetooth/start-led-service + //% blockId=bluetooth_start_led_service block="bluetooth led service" blockGap=8 + //% parts="bluetooth" weight=87 shim=bluetooth::startLEDService + function startLEDService(): void; + + /** + * Starts the Bluetooth temperature service + */ + //% help=bluetooth/start-temperature-service + //% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8 + //% parts="bluetooth" weight=86 shim=bluetooth::startTemperatureService + function startTemperatureService(): void; + + /** + * Starts the Bluetooth magnetometer service + */ + //% help=bluetooth/start-magnetometer-service + //% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" + //% parts="bluetooth" weight=85 shim=bluetooth::startMagnetometerService + function startMagnetometerService(): void; + /** * Starts the Bluetooth UART service */ //% help=bluetooth/start-uart-service - //% blockId=bluetooth_start_uart_service block="bluetooth uart service" blockGap=8 - //% parts="bluetooth" shim=bluetooth::startUartService + //% blockId=bluetooth_start_uart_service block="bluetooth uart service" + //% parts="bluetooth" advanced=true shim=bluetooth::startUartService function startUartService(): void; /** diff --git a/libs/core/enums.d.ts b/libs/core/enums.d.ts index 8e9372e3..7910c33f 100644 --- a/libs/core/enums.d.ts +++ b/libs/core/enums.d.ts @@ -309,6 +309,22 @@ declare namespace led { //% block=9600 BaudRate9600 = 9600, } + + + declare enum Delimiters { + //% block="new line" + NewLine = 1, + //% block="," + Comma = 2, + //% block="$" + Dollar = 3, + //% block=":" + Colon = 4, + //% block="." + Fullstop = 5, + //% block="#" + Hash = 6, + } declare namespace serial { } diff --git a/libs/core/serial.cpp b/libs/core/serial.cpp index b50de6b7..95e7bf7e 100644 --- a/libs/core/serial.cpp +++ b/libs/core/serial.cpp @@ -1,6 +1,6 @@ #include "ksbit.h" -enum class SerialPin { +enum SerialPin { P0 = MICROBIT_ID_IO_P0, P1 = MICROBIT_ID_IO_P1, P2 = MICROBIT_ID_IO_P2, @@ -12,36 +12,52 @@ enum class SerialPin { P16 = MICROBIT_ID_IO_P16 }; -enum class BaudRate { +enum BaudRate { //% block=115200 BaudRate115200 = 115200, //% block=9600 BaudRate9600 = 9600 }; +enum Delimiters { + //% block="new line" + NewLine = 1, + //% block="," + Comma = 2, + //% block="$" + Dollar = 3, + //% block=":" + Colon = 4, + //% block="." + Fullstop = 5, + //% block="#" + Hash = 6, +}; + //% weight=2 color=30 //% advanced=true namespace serial { // note that at least one // followed by % is needed per declaration! /** - * Reads a line of text from the serial port. + * Reads a line of text from the serial port and returns the buffer when the delimiter is met. + * @param delimiter text delimiter that separates each text chunk */ - //% help=serial/read-line - //% blockId=serial_read_line block="serial read line" - //% weight=20 - StringData* readLine() { - return uBit.serial.readUntil(ManagedString("\n")).leakData(); + //% help=serial/read-until + //% blockId=serial_read_until block="serial|read until %delimiter=serial_delimiter_conv" + //% weight=19 + StringData* readUntil(StringData* delimiter) { + return uBit.serial.readUntil(ManagedString(delimiter)).leakData(); } /** - * Sends a piece of text through Serial connection. + * Reads a line of text from the serial port. */ - //% help=serial/write-string - //% weight=87 - //% blockId=serial_writestring block="serial write string %text" - void writeString(StringData *text) { - uBit.serial.send(ManagedString(text)); + //% help=serial/read-line + //% blockId=serial_read_line block="serial|read line" + //% weight=20 blockGap=8 + StringData* readLine() { + return readUntil(ManagedString("\n").leakData()); } /** @@ -49,12 +65,22 @@ namespace serial { * @param delimiters the characters to match received characters against. eg:"\n" */ // help=serial/on-data-received - // weight=19 + // weight=18 void onDataReceived(StringData* delimiters, Action body) { uBit.serial.eventOn(ManagedString(delimiters)); registerWithDal(MICROBIT_ID_SERIAL, MICROBIT_SERIAL_EVT_DELIM_MATCH, body); } + /** + * Sends a piece of text through Serial connection. + */ + //% help=serial/write-string + //% weight=87 + //% blockId=serial_writestring block="serial|write string %text" + void writeString(StringData *text) { + uBit.serial.send(ManagedString(text)); + } + /** * Dynamically configuring the serial instance to use pins other than USBTX and USBRX. * @param tx the new transmission pins @@ -63,7 +89,7 @@ namespace serial { */ //% weight=10 //% help=serial/redirect-to - //% blockId=serial_redirect block="serial redirect to|TX %tx|RX %rx|at baud rate %rate" + //% blockId=serial_redirect block="serial|redirect to|TX %tx|RX %rx|at baud rate %rate" //% blockExternalInputs=1 void redirect(SerialPin tx, SerialPin rx, BaudRate rate) { uBit.serial.redirect((PinName)tx, (PinName)rx); diff --git a/libs/core/serial.ts b/libs/core/serial.ts index cd632c5e..7de284c4 100644 --- a/libs/core/serial.ts +++ b/libs/core/serial.ts @@ -46,4 +46,24 @@ namespace serial { export function onLineReceived(body: Action): void { // serial.onDataReceived("\n", body); } + + /** + * Returns the delimiter corresponding string + */ + //% blockId="serial_delimiter_conv" block="%del" + //% weight=1 + export function delimiters(del: Delimiters): string { + // even though it might not look like, this is more + // (memory) efficient than the C++ implementation, because the + // strings are statically allocated and take no RAM + switch (del) { + case Delimiters.NewLine: return "\n" + case Delimiters.Comma: return "," + case Delimiters.Dollar: return "$" + case Delimiters.Colon: return ":" + case Delimiters.Fullstop: return "." + case Delimiters.Hash: return "#" + default: return "\n" + } + } } diff --git a/libs/core/shims.d.ts b/libs/core/shims.d.ts index c649e7de..6c7be203 100644 --- a/libs/core/shims.d.ts +++ b/libs/core/shims.d.ts @@ -648,12 +648,21 @@ declare namespace pins { //% advanced=true declare namespace serial { + /** + * Reads a line of text from the serial port and returns the buffer when the delimiter is met. + * @param delimiter text delimiter that separates each text chunk + */ + //% help=serial/read-until + //% blockId=serial_read_until block="serial|read until %delimiter=serial_delimiter_conv" + //% weight=19 shim=serial::readUntil + function readUntil(delimiter: string): string; + /** * Reads a line of text from the serial port. */ //% help=serial/read-line - //% blockId=serial_read_line block="serial read line" - //% weight=20 shim=serial::readLine + //% blockId=serial_read_line block="serial|read line" + //% weight=20 blockGap=8 shim=serial::readLine function readLine(): string; /** @@ -661,7 +670,7 @@ declare namespace serial { */ //% help=serial/write-string //% weight=87 - //% blockId=serial_writestring block="serial write string %text" shim=serial::writeString + //% blockId=serial_writestring block="serial|write string %text" shim=serial::writeString function writeString(text: string): void; /** @@ -672,7 +681,7 @@ declare namespace serial { */ //% weight=10 //% help=serial/redirect-to - //% blockId=serial_redirect block="serial redirect to|TX %tx|RX %rx|at baud rate %rate" + //% blockId=serial_redirect block="serial|redirect to|TX %tx|RX %rx|at baud rate %rate" //% blockExternalInputs=1 shim=serial::redirect function redirect(tx: SerialPin, rx: SerialPin, rate: BaudRate): void; } diff --git a/pxtarget.json b/pxtarget.json index 80173f11..cd4b4502 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -84,6 +84,13 @@ "microbit-pins": "", "microbit-serial": "" } + }, + { + "type": "api", + "map": { + "bluetooth\\.uartRead\\((.*?)\\)" : "bluetooth.uartReadUntil($1)", + "bluetooth\\.uartWrite\\((.*?)\\)" : "bluetooth.uartWriteUntil($1)" + } } ] }, diff --git a/sim/state/misc.ts b/sim/state/misc.ts index 03ed5103..d2d20061 100644 --- a/sim/state/misc.ts +++ b/sim/state/misc.ts @@ -168,7 +168,7 @@ namespace pxsim.bluetooth { export function uartWrite(s : string): void { // TODO } - export function uartRead(): string { + export function uartReadUntil(del: string): string { // TODO return "" } From 6ad59e04a6e7760c86e94ff3b8e738458c41a38d Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 21:47:54 -0700 Subject: [PATCH 13/15] fixed uart issues --- docs/reference/bluetooth/uart-write-string.md | 2 +- libs/bluetooth/bluetooth.ts | 4 ++-- sim/state/serial.ts | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/reference/bluetooth/uart-write-string.md b/docs/reference/bluetooth/uart-write-string.md index aa368f99..ffd10579 100644 --- a/docs/reference/bluetooth/uart-write-string.md +++ b/docs/reference/bluetooth/uart-write-string.md @@ -1,4 +1,4 @@ -# UART Write Number +# UART Write String ### ~hint ![](/static/bluetooth/Bluetooth_SIG.png) diff --git a/libs/bluetooth/bluetooth.ts b/libs/bluetooth/bluetooth.ts index f5630ddd..3f480408 100644 --- a/libs/bluetooth/bluetooth.ts +++ b/libs/bluetooth/bluetooth.ts @@ -6,7 +6,7 @@ namespace bluetooth { /** * Writes to the Bluetooth UART service buffer. From there the data is transmitted over Bluetooth to a connected device. */ - //% help=bluetooth/uart-write weight=80 + //% help=bluetooth/uart-write-string weight=80 //% blockId=bluetooth_uart_write block="bluetooth uart|write string %data" blockGap=8 //% parts="bluetooth" shim=bluetooth::uartWriteString advanced=true export function uartWriteString(data: string): void { @@ -17,7 +17,7 @@ namespace bluetooth { /** * Prints a numeric value to the serial */ - //% help=serial/write-number weight=79 + //% help=bluetooth/uart-write-number weight=79 //% weight=89 blockGap=8 advanced=true //% blockId=bluetooth_uart_writenumber block="bluetooth uart|write number %value" export function uartWriteNumber(value: number): void { diff --git a/sim/state/serial.ts b/sim/state/serial.ts index ff4f9420..5f6e1b4d 100644 --- a/sim/state/serial.ts +++ b/sim/state/serial.ts @@ -43,6 +43,10 @@ namespace pxsim.serial { return board().serialState.readSerial(); } + export function readUntil(del: string): string { + return readLine(); + } + export function onDataReceived(delimiters: string, handler: RefAction) { let b = board(); b.bus.listen(DAL.MICROBIT_ID_SERIAL, DAL.MICROBIT_SERIAL_EVT_DELIM_MATCH, handler); From 23d30484d41511be5c12c8471854c2ae2b1e47d8 Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 21:52:10 -0700 Subject: [PATCH 14/15] updated docs page --- docs/docs.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/docs.md b/docs/docs.md index b2527bb7..be6b9f5d 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -5,7 +5,8 @@ ### Things to do * **[Getting Started](/getting-started)** -* [Ten projects](/projects) +* [Projects](/projects) +* [Lessons](/lessons) ### Micro:bit reference @@ -16,16 +17,15 @@ * [Blocks language](/blocks) * [JavaScript language](/javascript) -* [Streaming data](/streaming) ### More questions? * [Frequently Asked Question](/faq) -* [Embedding project](/share) * [Help Translate](/translate) -* [Release notes](/release-notes) +* [Embedding project](/share) ### Developers * [Command Line Interface](/cli) * Learn about [packages](/packages) +* [Release notes](/release-notes) From 0f7323f2dad84cc5de2b8a36760b69cbb7ad64ec Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 18 Oct 2016 21:52:38 -0700 Subject: [PATCH 15/15] 0.4.55 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8686a3ac..2cb4e513 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.4.54", + "version": "0.4.55", "description": "micro:bit target for PXT", "keywords": [ "JavaScript",