@@ -17,6 +17,8 @@
 | 
			
		||||
  "bluetooth.onBluetoothConnected|param|body": "Code to run when a Bluetooth connection is established",
 | 
			
		||||
  "bluetooth.onBluetoothDisconnected": "Register code to run when a bluetooth connection to the micro:bit is lost",
 | 
			
		||||
  "bluetooth.onBluetoothDisconnected|param|body": "Code to run when a Bluetooth connection is lost",
 | 
			
		||||
  "bluetooth.onUartDataReceived": "Registers an event to be fired when one of the delimiter is matched.",
 | 
			
		||||
  "bluetooth.onUartDataReceived|param|delimiters": "the characters to match received characters against.",
 | 
			
		||||
  "bluetooth.setTransmitPower": "Sets the bluetooth transmit power between 0 (minimal) and 7 (maximum).",
 | 
			
		||||
  "bluetooth.setTransmitPower|param|power": "power level between 0 (minimal) and 7 (maximum), eg: 7.",
 | 
			
		||||
  "bluetooth.startAccelerometerService": "Starts the Bluetooth accelerometer service",
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
  "bluetooth.advertiseUrl|block": "bluetooth advertise url %url|with power %power|connectable %connectable",
 | 
			
		||||
  "bluetooth.onBluetoothConnected|block": "on bluetooth connected",
 | 
			
		||||
  "bluetooth.onBluetoothDisconnected|block": "on bluetooth disconnected",
 | 
			
		||||
  "bluetooth.onUartDataReceived|block": "bluetooth|on data received %delimiters=serial_delimiter_conv",
 | 
			
		||||
  "bluetooth.setTransmitPower|block": "bluetooth set transmit power %power",
 | 
			
		||||
  "bluetooth.startAccelerometerService|block": "bluetooth accelerometer service",
 | 
			
		||||
  "bluetooth.startButtonService|block": "bluetooth button service",
 | 
			
		||||
 
 | 
			
		||||
@@ -98,6 +98,18 @@ namespace bluetooth {
 | 
			
		||||
        return uart->readUntil(ManagedString(del)).leakData();
 | 
			
		||||
    }    
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
    * Registers an event to be fired when one of the delimiter is matched.
 | 
			
		||||
    * @param delimiters the characters to match received characters against.
 | 
			
		||||
    */
 | 
			
		||||
    //% help=bluetooth/on-uart-data-received
 | 
			
		||||
    //% weight=18 blockId=bluetooth_on_data_received block="bluetooth|on data received %delimiters=serial_delimiter_conv"
 | 
			
		||||
    void onUartDataReceived(StringData* delimiters, Action body) {
 | 
			
		||||
      startUartService();
 | 
			
		||||
      uart->eventOn(ManagedString(delimiters));
 | 
			
		||||
      registerWithDal(MICROBIT_ID_BLE_UART, MICROBIT_UART_S_EVT_DELIM_MATCH, body);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Register code to run when the micro:bit is connected to over Bluetooth
 | 
			
		||||
     * @param body Code to run when a Bluetooth connection is established
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								libs/bluetooth/shims.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								libs/bluetooth/shims.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -63,6 +63,14 @@ declare namespace bluetooth {
 | 
			
		||||
    //% parts="bluetooth" advanced=true shim=bluetooth::startUartService
 | 
			
		||||
    function startUartService(): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers an event to be fired when one of the delimiter is matched.
 | 
			
		||||
     * @param delimiters the characters to match received characters against.
 | 
			
		||||
     */
 | 
			
		||||
    //% help=bluetooth/on-uart-data-received
 | 
			
		||||
    //% weight=18 blockId=bluetooth_on_data_received block="bluetooth|on data received %delimiters=serial_delimiter_conv" shim=bluetooth::onUartDataReceived
 | 
			
		||||
    function onUartDataReceived(delimiters: string, body: () => void): void;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Register code to run when the micro:bit is connected to over Bluetooth
 | 
			
		||||
     * @param body Code to run when a Bluetooth connection is established
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user