Increased default power to 6, added UART write block
This commit is contained in:
@ -91,8 +91,32 @@ namespace bluetooth {
|
||||
//% blockId=bluetooth_start_uart_service block="bluetooth|uart|service" blockGap=8
|
||||
|
||||
void startUartService() {
|
||||
// 32 octet buffer size is
|
||||
uart = new MicroBitUARTService(*uBit.ble, 32, 32);
|
||||
// 61 octet buffer size is 3 x (MTU - 3) + 1
|
||||
// MTU on nRF51822 is 23 octets. 3 are used by Attribute Protocol header data leaving 20 octets for payload
|
||||
// So we allow a buffer that can contain 3 x max length messages plus one octet for a terminator character
|
||||
uart = new MicroBitUARTService(*uBit.ble, 61, 60);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads the Bluetooth UART service buffer, returning when a specified 'end of message' delimiter character is encountered
|
||||
* @param eom End of Message delimiter character
|
||||
*/
|
||||
//% help=bluetooth/uart-read
|
||||
//% blockId=bluetooth_uart_read block="bluetooth|uart|read %eom" blockGap=8
|
||||
StringData* uartRead(char* eom) {
|
||||
// temp hard coding of : as eom delimiter
|
||||
char delim[6] = {':', 0};
|
||||
return uart->readUntil(delim).leakData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
void uartWrite(StringData* data) {
|
||||
uart->send(ManagedString(data));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
"open": 0,
|
||||
"whitelist": 1,
|
||||
"advertising_timeout": 0,
|
||||
"tx_power": 0,
|
||||
"tx_power": 6,
|
||||
"dfu_service": 1,
|
||||
"event_service": 1,
|
||||
"device_info_service": 1
|
||||
|
15
libs/microbit-bluetooth/shims.d.ts
vendored
15
libs/microbit-bluetooth/shims.d.ts
vendored
@ -71,6 +71,21 @@ declare namespace bluetooth {
|
||||
//% help=bluetooth/start-uart-service
|
||||
//% blockId=bluetooth_start_uart_service block="bluetooth|uart|service" blockGap=8 shim=bluetooth::startUartService
|
||||
function startUartService(): void;
|
||||
|
||||
/**
|
||||
* Reads the Bluetooth UART service buffer, returning when a specified 'end of message' delimiter character is encountered
|
||||
* @param eom End of Message delimiter character
|
||||
*/
|
||||
//% help=bluetooth/uart-read
|
||||
//% blockId=bluetooth_uart_read block="bluetooth|uart|read %eom" blockGap=8 shim=bluetooth::uartRead
|
||||
function uartRead(eom: char*): string;
|
||||
|
||||
/**
|
||||
* 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 shim=bluetooth::uartWrite
|
||||
function uartWrite(data: string): void;
|
||||
}
|
||||
|
||||
// Auto-generated. Do not edit. Really.
|
||||
|
Reference in New Issue
Block a user