updated docs
This commit is contained in:
Родитель
23a56e9fa0
Коммит
47ef5c9d75
|
@ -8,7 +8,7 @@ This package allows to create a Bluetooth temperature sensor and provide the dat
|
|||
any custom sensor attached to the @boardname@. In fact, it can be used to stream any data!
|
||||
|
||||
```blocks
|
||||
bluetooth.startTemperatureSensorService(50, () => {
|
||||
bluetooth.startTemperatureSensorService(() => {
|
||||
bluetooth.setTemperatureSensorValue(input.lightLevel());
|
||||
})
|
||||
```
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* Create a representation of the TemperatureService
|
||||
* @param _ble The instance of a BLE device that we're running on.
|
||||
*/
|
||||
TemperatureSensorService::TemperatureSensorService(BLEDevice &_ble, int period) :
|
||||
TemperatureSensorService::TemperatureSensorService(BLEDevice &_ble) :
|
||||
ble(_ble)
|
||||
{
|
||||
// Create the data structures that represent each of our characteristics in Soft Device.
|
||||
|
@ -24,7 +24,7 @@ TemperatureSensorService::TemperatureSensorService(BLEDevice &_ble, int period)
|
|||
|
||||
// Initialise our characteristic values.
|
||||
temperatureDataCharacteristicBuffer = 0;
|
||||
temperaturePeriodCharacteristicBuffer = max(1, period);
|
||||
temperaturePeriodCharacteristicBuffer = 1000;
|
||||
|
||||
// Set default security requirements
|
||||
temperatureDataCharacteristic.requireSecurity(SecurityManager::MICROBIT_BLE_SECURITY_LEVEL);
|
||||
|
|
|
@ -26,7 +26,7 @@ class TemperatureSensorService
|
|||
* Create a representation of the TemperatureService
|
||||
* @param _ble The instance of a BLE device that we're running on.
|
||||
*/
|
||||
TemperatureSensorService(BLEDevice &_ble, int period);
|
||||
TemperatureSensorService(BLEDevice &_ble);
|
||||
|
||||
/**
|
||||
* Callback. Invoked when any of our attributes are written via BLE.
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# Bluetooth Set Temperature Sensor Value
|
||||
|
||||
### ~hint
|
||||
![](/static/bluetooth/Bluetooth_SIG.png)
|
||||
|
||||
For another device like a smartphone to use any of the Bluetooth "services" which the @boardname@ has, it must first be [paired with the @boardname@](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the @boardname@ and exchange data relating to many of the @boardname@'s features.
|
||||
|
||||
### ~
|
||||
|
||||
Set the current temperature measured by the temperature sensor. This function should be called within the handler
|
||||
when start the temperature sensor service.
|
||||
|
||||
```sig
|
||||
bluetooth.setTemperatureSensorValue(1000)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `value`: a [number](/types/number) that represents the temperature in degrees Celcius
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
bluetooth-temperature-sensor
|
||||
```
|
|
@ -0,0 +1,32 @@
|
|||
# Bluetooth Start Temperature Sensor Service
|
||||
|
||||
### ~hint
|
||||
![](/static/bluetooth/Bluetooth_SIG.png)
|
||||
|
||||
For another device like a smartphone to use any of the Bluetooth "services" which the @boardname@ has, it must first be [paired with the @boardname@](/reference/bluetooth/bluetooth-pairing). Once paired, the other device may connect to the @boardname@ and exchange data relating to many of the @boardname@'s features.
|
||||
|
||||
### ~
|
||||
|
||||
This function allows to create a Bluetooth temperature sensor and provide the data from
|
||||
any custom sensor attached to the @boardname@. In fact, it can be used to stream any data!
|
||||
|
||||
|
||||
```sig
|
||||
bluetooth.startTemperatureSensorService(() => {})
|
||||
```
|
||||
|
||||
### Example: Starting the Bluetooth temperature service
|
||||
|
||||
The following code shows the Bluetooth temperature service being started:
|
||||
|
||||
```blocks
|
||||
bluetooth.startTemperatureSensorService(() => {
|
||||
bluetooth.setTemperatureSensorValue(input.lightLevel());
|
||||
});
|
||||
```
|
||||
|
||||
```package
|
||||
bluetooth
|
||||
bluetooth-temperature-sensor
|
||||
```
|
||||
|
|
@ -21,10 +21,10 @@ namespace bluetooth {
|
|||
* to update the temperature sent to the service.
|
||||
*/
|
||||
//% block
|
||||
void startTemperatureSensorService(int period, Action handler) {
|
||||
void startTemperatureSensorService(Action handler) {
|
||||
if (NULL != _pService) return;
|
||||
|
||||
_pService = new TemperatureSensorService(*uBit.ble, period);
|
||||
_pService = new TemperatureSensorService(*uBit.ble);
|
||||
_handler = handler;
|
||||
pxt::incr(_handler);
|
||||
create_fiber(updateTemperature);
|
||||
|
|
|
@ -6,7 +6,7 @@ declare namespace bluetooth {
|
|||
* to update the temperature sent to the service.
|
||||
*/
|
||||
//% block shim=bluetooth::startTemperatureSensorService
|
||||
function startTemperatureSensorService(period: number, handler: () => void): void;
|
||||
function startTemperatureSensorService(handler: () => void): void;
|
||||
|
||||
/**
|
||||
* Sets the current temperature value on the external temperature sensor
|
||||
|
|
4
tests.ts
4
tests.ts
|
@ -1,4 +1,4 @@
|
|||
// tests go here; this will not be compiled when this package is used as a library
|
||||
bluetooth.startTemperatureSensorService(1000, () => {
|
||||
bluetooth.setTemperatureSensorValue(500);
|
||||
bluetooth.startTemperatureSensorService(() => {
|
||||
bluetooth.setTemperatureSensorValue(input.lightLevel());
|
||||
})
|
Загрузка…
Ссылка в новой задаче