diff --git a/docs/javascript.md b/docs/javascript.md index 9cb3e54e..ca3815f0 100644 --- a/docs/javascript.md +++ b/docs/javascript.md @@ -4,7 +4,7 @@ You can write micro:bit programs in a subset of [TypeScript](https://www.typescr Many micro:bit programs, especially at the beginner's level, are just plain JavaScript. TypeScript introduces class-based object-oriented programming, such as: -```js +```typescript class Greeter { greeting: string; constructor(message: string) { diff --git a/docs/reference/bluetooth/start-io-pin-service.md b/docs/reference/bluetooth/start-io-pin-service.md new file mode 100755 index 00000000..5d947a91 --- /dev/null +++ b/docs/reference/bluetooth/start-io-pin-service.md @@ -0,0 +1,36 @@ +# Bluetooth IO Pin Service + +![](/static/bluetooth/Bluetooth_SIG.png) + +The Bluetooth IO pin service makes it possible for another device such as a smartphone to communicate with other electronic 'things' connected to a micro:bit's edge connector. You could for example, use your smartphone to switch on or off a light which is connected to the micro:bit or your smartphone could receive data collected from a sensor connected to the micro:bit. In fact you could do both of these things at the same time since the Bluetooth IO pin service lets you interact with multiple 'pins' on the edge conector in different ways all at the same time. + +No additional code is needed on the micro:bit to use the Bluetooth IO pin service from another device. + +~~~~sig +bluetooth.startIOPinService(); +~~~~ + +### Example: Starting the Bluetooth IO pin service + +The following code shows the Bluetooth IO pin service being started: + +~~~~blocks +bluetooth.startIOPinService(); +~~~~ + +### Video - IO pin service demo starts at 3:49 + +[![micro:bit Bluetooth demo video](/static/bluetooth/microbit_pin_io.png)]( + http://www.youtube.com/watch?v=aep_GVowKfs "Click to launch YouTube video" + ) + +### Advanced + +For more advanced information on the micro:bit Bluetooth IO pin service including information on using a smartphone, see the [Lancaster University micro:bit runtime technical documentation](http://lancaster-university.github.io/microbit-docs/ble/iopin-service/) + +### See also + +[Bluetooth SIG](https://www.bluetooth.com) + +[Bluetooth on micro:bit resources](http://bluetooth-mdw.blogspot.co.uk/p/bbc-microbit.html) + diff --git a/docs/static/bluetooth/Bluetooth_SIG.png b/docs/static/bluetooth/Bluetooth_SIG.png new file mode 100755 index 00000000..5479e652 Binary files /dev/null and b/docs/static/bluetooth/Bluetooth_SIG.png differ diff --git a/docs/static/bluetooth/microbit_pin_io.png b/docs/static/bluetooth/microbit_pin_io.png new file mode 100755 index 00000000..e262587f Binary files /dev/null and b/docs/static/bluetooth/microbit_pin_io.png differ diff --git a/docs/static/mb/projects/a1-display.png b/docs/static/mb/projects/a1-display.png index 55da986b..c835b4fa 100644 Binary files a/docs/static/mb/projects/a1-display.png and b/docs/static/mb/projects/a1-display.png differ diff --git a/docs/static/mb/projects/a10-watch.png b/docs/static/mb/projects/a10-watch.png index a27b1891..9781b759 100644 Binary files a/docs/static/mb/projects/a10-watch.png and b/docs/static/mb/projects/a10-watch.png differ diff --git a/docs/static/mb/projects/a2-buttons.png b/docs/static/mb/projects/a2-buttons.png index 469445ab..ed882419 100644 Binary files a/docs/static/mb/projects/a2-buttons.png and b/docs/static/mb/projects/a2-buttons.png differ diff --git a/docs/static/mb/projects/a3-pins.png b/docs/static/mb/projects/a3-pins.png index 55fa7aad..4ca19601 100644 Binary files a/docs/static/mb/projects/a3-pins.png and b/docs/static/mb/projects/a3-pins.png differ diff --git a/docs/static/mb/projects/a4-motion.png b/docs/static/mb/projects/a4-motion.png index 7e9e31f3..10ea6a2d 100644 Binary files a/docs/static/mb/projects/a4-motion.png and b/docs/static/mb/projects/a4-motion.png differ diff --git a/docs/static/mb/projects/a5-compass.png b/docs/static/mb/projects/a5-compass.png index 644008a9..3d7f8655 100644 Binary files a/docs/static/mb/projects/a5-compass.png and b/docs/static/mb/projects/a5-compass.png differ diff --git a/docs/static/mb/projects/a6-music.png b/docs/static/mb/projects/a6-music.png index 2eaa244d..0ec2718c 100644 Binary files a/docs/static/mb/projects/a6-music.png and b/docs/static/mb/projects/a6-music.png differ diff --git a/docs/static/mb/projects/a7-conductive.png b/docs/static/mb/projects/a7-conductive.png index 4ea87138..3ae20a63 100644 Binary files a/docs/static/mb/projects/a7-conductive.png and b/docs/static/mb/projects/a7-conductive.png differ diff --git a/docs/static/mb/projects/a8-network.png b/docs/static/mb/projects/a8-network.png index 6849a27e..9ac1f2f5 100644 Binary files a/docs/static/mb/projects/a8-network.png and b/docs/static/mb/projects/a8-network.png differ diff --git a/docs/static/mb/projects/a9-radio.png b/docs/static/mb/projects/a9-radio.png index ff3b269e..80d48107 100644 Binary files a/docs/static/mb/projects/a9-radio.png and b/docs/static/mb/projects/a9-radio.png differ diff --git a/libs/microbit-bluetooth/bluetooth.cpp b/libs/microbit-bluetooth/bluetooth.cpp index 7e6f63d9..ab995204 100644 --- a/libs/microbit-bluetooth/bluetooth.cpp +++ b/libs/microbit-bluetooth/bluetooth.cpp @@ -5,7 +5,7 @@ using namespace pxt; //% color=#0082FB weight=20 namespace bluetooth { /** - * Starts the Bluetooth IO pin service + * 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 @@ -23,7 +23,7 @@ namespace bluetooth { } /** - * Starts the temperature service + * Starts the Bluetooth temperature service */ //% help=bluetooth/start-temperature-service //% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8 @@ -32,7 +32,7 @@ namespace bluetooth { } /** - * Starts the magnetometer service + * Starts the Bluetooth magnetometer service */ //% help=bluetooth/start-magnetometer-service //% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8 @@ -41,7 +41,7 @@ namespace bluetooth { } /** - * Starts the accelerometer service + * Starts the Bluetooth accelerometer service */ //% help=bluetooth/start-accelerometer-service //% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8 @@ -50,11 +50,33 @@ namespace bluetooth { } /** - * Starts the button service + * Starts the Bluetooth button service */ //% help=bluetooth/start-button-service //% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 void startButtonService() { new MicroBitButtonService(*uBit.ble); } + + /** + * Register code to run when the micro:bit is connected to over Bluetooth + * @param body Code to run when a Bluetooth connection is established + */ + //% help=bluetooth/on-bluetooth-connected + //% blockId=bluetooth_on_connected block="on bluetooth connected" + void onBluetoothConnected(Action body) { + registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_CONNECTED, body); + } + + /** + * Register code to run when a bluetooth connection to the micro:bit is lost + * @param body Code to run when a Bluetooth connection is lost + */ + //% help=bluetooth/on-bluetooth-disconnected + //% blockId=bluetooth_on_disconnected block="on bluetooth disconnected" + void onBluetoothDisconnected(Action body) { + registerWithDal(MICROBIT_ID_BLE, MICROBIT_BLE_EVT_DISCONNECTED, body); + } + + } diff --git a/libs/microbit-bluetooth/pxt.json b/libs/microbit-bluetooth/pxt.json index 7fab9c9d..584ea366 100644 --- a/libs/microbit-bluetooth/pxt.json +++ b/libs/microbit-bluetooth/pxt.json @@ -15,10 +15,20 @@ "config": { "microbit-dal": { "bluetooth": { - "enabled": 1 - } + "enabled": 1, + "pairing_mode": 1, + "private_addressing": 0, + "open": 0, + "whitelist": 1, + "advertising_timeout": 0, + "tx_power": 0, + "dfu_service": 1, + "event_service": 1, + "device_info_service": 1 + }, + "gatt_table_size": "0x700" } } }, "installedVersion": "vzlhfd" -} +} \ No newline at end of file diff --git a/libs/microbit-bluetooth/shims.d.ts b/libs/microbit-bluetooth/shims.d.ts index 85393c00..9d7d49b5 100644 --- a/libs/microbit-bluetooth/shims.d.ts +++ b/libs/microbit-bluetooth/shims.d.ts @@ -6,7 +6,7 @@ declare namespace bluetooth { /** - * Starts the Bluetooth IO pin service + * 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 shim=bluetooth::startIOPinService @@ -20,32 +20,48 @@ declare namespace bluetooth { function startLEDService(): void; /** - * Starts the temperature service + * Starts the Bluetooth temperature service */ //% help=bluetooth/start-temperature-service //% blockId=bluetooth_start_temperature_service block="bluetooth temperature service" blockGap=8 shim=bluetooth::startTemperatureService function startTemperatureService(): void; /** - * Starts the magnetometer service + * Starts the Bluetooth magnetometer service */ //% help=bluetooth/start-magnetometer-service //% blockId=bluetooth_start_magnetometer_service block="bluetooth magnetometer service" blockGap=8 shim=bluetooth::startMagnetometerService function startMagnetometerService(): void; /** - * Starts the accelerometer service + * Starts the Bluetooth accelerometer service */ //% help=bluetooth/start-accelerometer-service //% blockId=bluetooth_start_accelerometer_service block="bluetooth accelerometer service" blockGap=8 shim=bluetooth::startAccelerometerService function startAccelerometerService(): void; /** - * Starts the button service + * Starts the Bluetooth button service */ //% help=bluetooth/start-button-service //% blockId=bluetooth_start_button_service block="bluetooth button service" blockGap=8 shim=bluetooth::startButtonService function startButtonService(): 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 + */ + //% help=bluetooth/on-bluetooth-connected + //% blockId=bluetooth_on_connected block="on bluetooth connected" shim=bluetooth::onBluetoothConnected + function onBluetoothConnected(body: () => void): void; + + /** + * Register code to run when a bluetooth connection to the micro:bit is lost + * @param body Code to run when a Bluetooth connection is lost + */ + //% help=bluetooth/on-bluetooth-disconnected + //% blockId=bluetooth_on_disconnected block="on bluetooth disconnected" shim=bluetooth::onBluetoothDisconnected + function onBluetoothDisconnected(body: () => void): void; } // Auto-generated. Do not edit. Really.