ble nano hid over gatt
Dependencies: BLE_API mbed-dev nRF51822
ScanParametersService.h@85:e526a89a0674, 2016-09-15 (annotated)
- Committer:
- cho45
- Date:
- Thu Sep 15 08:48:57 2016 +0900
- Revision:
- 85:e526a89a0674
Add ScanParametersService
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cho45 |
85:e526a89a0674 | 1 | #ifndef __BLE_SCAN_PARAMETERS_SERVICE_H__ |
cho45 |
85:e526a89a0674 | 2 | #define __BLE_SCAN_PARAMETERS_SERVICE_H__ |
cho45 |
85:e526a89a0674 | 3 | |
cho45 |
85:e526a89a0674 | 4 | #include "ble/BLE.h" |
cho45 |
85:e526a89a0674 | 5 | |
cho45 |
85:e526a89a0674 | 6 | #pragma pack(push, 1) |
cho45 |
85:e526a89a0674 | 7 | typedef struct { |
cho45 |
85:e526a89a0674 | 8 | uint16_t LE_Scan_Interval; |
cho45 |
85:e526a89a0674 | 9 | uint16_t LE_Scan_Window; |
cho45 |
85:e526a89a0674 | 10 | } ScanIntervalWindow_t; |
cho45 |
85:e526a89a0674 | 11 | #pragma pack(pop) |
cho45 |
85:e526a89a0674 | 12 | |
cho45 |
85:e526a89a0674 | 13 | class ScanParametersService { |
cho45 |
85:e526a89a0674 | 14 | public: |
cho45 |
85:e526a89a0674 | 15 | ScanParametersService( |
cho45 |
85:e526a89a0674 | 16 | BLE &_ble |
cho45 |
85:e526a89a0674 | 17 | ) : |
cho45 |
85:e526a89a0674 | 18 | ble(_ble), |
cho45 |
85:e526a89a0674 | 19 | scanIntervalWindowCharacteristic( |
cho45 |
85:e526a89a0674 | 20 | GattCharacteristic::UUID_SCAN_INTERVAL_WINDOW_CHAR, |
cho45 |
85:e526a89a0674 | 21 | (uint8_t*)&scanIntervalWindowData, |
cho45 |
85:e526a89a0674 | 22 | sizeof(scanIntervalWindowData), |
cho45 |
85:e526a89a0674 | 23 | sizeof(scanIntervalWindowData), |
cho45 |
85:e526a89a0674 | 24 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE |
cho45 |
85:e526a89a0674 | 25 | ), |
cho45 |
85:e526a89a0674 | 26 | scanRefreshCharacteristic( |
cho45 |
85:e526a89a0674 | 27 | GattCharacteristic::UUID_SCAN_REFRESH_CHAR, |
cho45 |
85:e526a89a0674 | 28 | &scanRefreshData, |
cho45 |
85:e526a89a0674 | 29 | sizeof(scanIntervalWindowData), |
cho45 |
85:e526a89a0674 | 30 | sizeof(scanIntervalWindowData), |
cho45 |
85:e526a89a0674 | 31 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY |
cho45 |
85:e526a89a0674 | 32 | ) |
cho45 |
85:e526a89a0674 | 33 | { |
cho45 |
85:e526a89a0674 | 34 | GattCharacteristic *charTable[] = { |
cho45 |
85:e526a89a0674 | 35 | &scanIntervalWindowCharacteristic, |
cho45 |
85:e526a89a0674 | 36 | &scanRefreshCharacteristic |
cho45 |
85:e526a89a0674 | 37 | }; |
cho45 |
85:e526a89a0674 | 38 | |
cho45 |
85:e526a89a0674 | 39 | GattService scanParametersService( |
cho45 |
85:e526a89a0674 | 40 | GattService::UUID_SCAN_PARAMETERS_SERVICE, |
cho45 |
85:e526a89a0674 | 41 | charTable, |
cho45 |
85:e526a89a0674 | 42 | sizeof(charTable) / sizeof(GattCharacteristic *) |
cho45 |
85:e526a89a0674 | 43 | ); |
cho45 |
85:e526a89a0674 | 44 | |
cho45 |
85:e526a89a0674 | 45 | ble.addService(scanParametersService); |
cho45 |
85:e526a89a0674 | 46 | ble.gattServer().onDataWritten(this, &ScanParametersService::onDataWritten); |
cho45 |
85:e526a89a0674 | 47 | } |
cho45 |
85:e526a89a0674 | 48 | |
cho45 |
85:e526a89a0674 | 49 | protected: |
cho45 |
85:e526a89a0674 | 50 | BLE& ble; |
cho45 |
85:e526a89a0674 | 51 | |
cho45 |
85:e526a89a0674 | 52 | ScanIntervalWindow_t scanIntervalWindowData; |
cho45 |
85:e526a89a0674 | 53 | uint8_t scanRefreshData; |
cho45 |
85:e526a89a0674 | 54 | |
cho45 |
85:e526a89a0674 | 55 | GattCharacteristic scanIntervalWindowCharacteristic; |
cho45 |
85:e526a89a0674 | 56 | GattCharacteristic scanRefreshCharacteristic; |
cho45 |
85:e526a89a0674 | 57 | |
cho45 |
85:e526a89a0674 | 58 | void onDataWritten(const GattWriteCallbackParams *params) { |
cho45 |
85:e526a89a0674 | 59 | if (params->handle == scanIntervalWindowCharacteristic.getValueHandle()) { |
cho45 |
85:e526a89a0674 | 60 | DEBUG_PRINTF_BLE_INTERRUPT("onDataWritten: scanIntervalWindow %d bytes\r\n", params->len); |
cho45 |
85:e526a89a0674 | 61 | } |
cho45 |
85:e526a89a0674 | 62 | } |
cho45 |
85:e526a89a0674 | 63 | }; |
cho45 |
85:e526a89a0674 | 64 | |
cho45 |
85:e526a89a0674 | 65 | #endif |