This commit is contained in:
Peli de Halleux 2017-03-31 09:41:42 -07:00
Родитель 23a56e9fa0
Коммит 47ef5c9d75
8 изменённых файлов: 65 добавлений и 9 удалений

Просмотреть файл

@ -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);

2
shims.d.ts поставляемый
Просмотреть файл

@ -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

Просмотреть файл

@ -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());
})