AirConLibに対応したMSC

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleChat_LED_kai by EQUUS_KUBOTA

Committer:
ke_ix1
Date:
Sun Feb 12 10:34:03 2017 +0000
Revision:
8:8962bcb7ddc4
Parent:
5:35728098eeae
AirCon init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ke_ix1 5:35728098eeae 1 #ifndef TX_POWER_H
ke_ix1 5:35728098eeae 2 #define TX_POWER_H
ke_ix1 5:35728098eeae 3 #include "ble/BLE.h"
ke_ix1 5:35728098eeae 4
ke_ix1 5:35728098eeae 5 //#include "BLEDevice.h"
ke_ix1 5:35728098eeae 6
ke_ix1 5:35728098eeae 7 /**
ke_ix1 5:35728098eeae 8 * @class Tx power service
ke_ix1 5:35728098eeae 9 * @brief Tx power Service. This service exposes a device’s current transmit power level when in a connection (-100dbm to +20).
ke_ix1 5:35728098eeae 10 * Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.tx_power.xml
ke_ix1 5:35728098eeae 11 * Tx power Char: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.tx_power_level.xml
ke_ix1 5:35728098eeae 12 */
ke_ix1 5:35728098eeae 13 class TxPowerService
ke_ix1 5:35728098eeae 14 {
ke_ix1 5:35728098eeae 15
ke_ix1 5:35728098eeae 16 public:
ke_ix1 5:35728098eeae 17 /**
ke_ix1 5:35728098eeae 18 * @param[ref] _ble
ke_ix1 5:35728098eeae 19 * BLEDevice object for the underlying controller.
ke_ix1 5:35728098eeae 20 * @param[in] TxValue
ke_ix1 5:35728098eeae 21 * signed 8bit Transmit power.
ke_ix1 5:35728098eeae 22 */
ke_ix1 5:35728098eeae 23
ke_ix1 5:35728098eeae 24 // TxPowerChar(GattCharacteristic::UUID_TX_POWER_LEVEL_CHAR, (uint8_t*)&TxPower, sizeof(TxPower), sizeof(TxPower),
ke_ix1 5:35728098eeae 25 // GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) {
ke_ix1 5:35728098eeae 26
ke_ix1 5:35728098eeae 27 TxPowerService(BLE &_ble, int8_t TxValue):
ke_ix1 5:35728098eeae 28 ble(_ble),
ke_ix1 5:35728098eeae 29 TxPower(TxValue),
ke_ix1 5:35728098eeae 30 TxPowerChar(GattCharacteristic::UUID_TX_POWER_LEVEL_CHAR, &TxPower, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) {
ke_ix1 5:35728098eeae 31 GattCharacteristic *charTable[] = {&TxPowerChar};
ke_ix1 5:35728098eeae 32 GattService TxPowerService(GattService::UUID_TX_POWER_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
ke_ix1 5:35728098eeae 33
ke_ix1 5:35728098eeae 34 ble.addService(TxPowerService);
ke_ix1 5:35728098eeae 35 }
ke_ix1 5:35728098eeae 36
ke_ix1 5:35728098eeae 37 /**
ke_ix1 5:35728098eeae 38 * @brief Update the Tx power with a new value. with a valid range from -100dbm to +20dbm according to the service Char.
ke_ix1 5:35728098eeae 39 *
ke_ix1 5:35728098eeae 40 * @param newTxPower
ke_ix1 5:35728098eeae 41 * update the Tx power with the new value.
ke_ix1 5:35728098eeae 42 */
ke_ix1 5:35728098eeae 43 void updateTxPower(int8_t newTxPower) {
ke_ix1 5:35728098eeae 44
ke_ix1 5:35728098eeae 45 if(newTxPower >= -100 && newTxPower <= 20) {
ke_ix1 5:35728098eeae 46
ke_ix1 5:35728098eeae 47 TxPower = newTxPower;
ke_ix1 5:35728098eeae 48 ble.updateCharacteristicValue (TxPowerChar.getValueAttribute().getHandle(), (uint8_t*)&TxPower, 1);
ke_ix1 5:35728098eeae 49 //ble.updateCharacteristicValue (TxPowerChar.getValueHandle(), (uint8_t*)&TxPower, 1);
ke_ix1 5:35728098eeae 50 //ble.gattServer().write(TxPowerChar.getValueHandle(), &TxPower, 1);
ke_ix1 5:35728098eeae 51 }
ke_ix1 5:35728098eeae 52 }
ke_ix1 5:35728098eeae 53
ke_ix1 5:35728098eeae 54 private:
ke_ix1 5:35728098eeae 55 BLE &ble;
ke_ix1 5:35728098eeae 56 int8_t TxPower;
ke_ix1 5:35728098eeae 57 ReadOnlyGattCharacteristic<int8_t> TxPowerChar;
ke_ix1 5:35728098eeae 58 };
ke_ix1 5:35728098eeae 59
ke_ix1 5:35728098eeae 60 #endif