ble nano hid over gatt
Dependencies: BLE_API mbed-dev nRF51822
Diff: HIDServiceBase.cpp
- Revision:
- 59:2d6c0bff2151
- Parent:
- 55:f01a31103685
- Child:
- 66:a7c6fbe45cf5
--- a/HIDServiceBase.cpp Tue Aug 30 14:44:24 2016 +0000 +++ b/HIDServiceBase.cpp Wed Aug 31 12:31:14 2016 +0000 @@ -17,7 +17,26 @@ #include "mbed.h" #include "HIDServiceBase.h" -static const uint16_t UUID_BATTERY_LEVEL_CHAR = GattCharacteristic::UUID_BATTERY_LEVEL_CHAR; +static const report_reference_t inputReportReferenceData = { 0, INPUT_REPORT }; +static const GattAttribute inputReportReferenceDescriptor(BLE_UUID_DESCRIPTOR_REPORT_REFERENCE, (uint8_t *)&inputReportReferenceData, 2, 2, false); +static const GattAttribute * inputReportDescriptors[] = { + &inputReportReferenceDescriptor, +}; + +static const report_reference_t outputReportReferenceData = { 0, OUTPUT_REPORT }; +static const GattAttribute outputReportReferenceDescriptor(BLE_UUID_DESCRIPTOR_REPORT_REFERENCE, (uint8_t *)&outputReportReferenceData, 2, 2, false); +static const GattAttribute * outputReportDescriptors[] = { + &outputReportReferenceDescriptor, +}; + + +static const report_reference_t featureReportReferenceData = { 0, FEATURE_REPORT }; +static const GattAttribute featureReportReferenceDescriptor(BLE_UUID_DESCRIPTOR_REPORT_REFERENCE, (uint8_t *)&featureReportReferenceData, 2, 2, false); +static const GattAttribute * featureReportDescriptors[] = { + &featureReportReferenceDescriptor, +}; + +static const HID_information_t HID_information = {HID_VERSION_1_11, 0x00, 0x03}; HIDServiceBase::HIDServiceBase(BLE &_ble, report_map_t reportMap, @@ -43,13 +62,6 @@ protocolMode(REPORT_PROTOCOL), - inputReportReferenceDescriptor(BLE_UUID_DESCRIPTOR_REPORT_REFERENCE, - (uint8_t *)&inputReportReferenceData, 2, 2), - outputReportReferenceDescriptor(BLE_UUID_DESCRIPTOR_REPORT_REFERENCE, - (uint8_t *)&outputReportReferenceData, 2, 2), - featureReportReferenceDescriptor(BLE_UUID_DESCRIPTOR_REPORT_REFERENCE, - (uint8_t *)&featureReportReferenceData, 2, 2), - protocolModeCharacteristic(GattCharacteristic::UUID_PROTOCOL_MODE_CHAR, &protocolMode, 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE), @@ -59,20 +71,20 @@ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE, - inputReportDescriptors(), 1), + const_cast<GattAttribute**>(inputReportDescriptors), 1), outputReportCharacteristic(GattCharacteristic::UUID_REPORT_CHAR, (uint8_t *)outputReport, outputReportLength, outputReportLength, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE, - outputReportDescriptors(), 1), + const_cast<GattAttribute**>(outputReportDescriptors), 1), featureReportCharacteristic(GattCharacteristic::UUID_REPORT_CHAR, (uint8_t *)featureReport, featureReportLength, featureReportLength, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE, - featureReportDescriptors(), 1), + const_cast<GattAttribute**>(featureReportDescriptors), 1), /* * We need to set reportMap content as const, in order to let the compiler put it into flash @@ -82,9 +94,9 @@ reportMapCharacteristic(GattCharacteristic::UUID_REPORT_MAP_CHAR, const_cast<uint8_t*>(reportMap), reportMapLength, reportMapLength, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ, - reportMapDescriptors(), 0), + NULL, 0), - HIDInformationCharacteristic(GattCharacteristic::UUID_HID_INFORMATION_CHAR, HIDInformation()), + HIDInformationCharacteristic(GattCharacteristic::UUID_HID_INFORMATION_CHAR, const_cast<HID_information_t*>(&HID_information)), HIDControlPointCharacteristic(GattCharacteristic::UUID_HID_CONTROL_POINT_CHAR, &controlPointCommand, 1, 1, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE), @@ -171,49 +183,6 @@ startReportTicker(); } -GattAttribute** HIDServiceBase::inputReportDescriptors() { - inputReportReferenceData.ID = 0; - inputReportReferenceData.type = INPUT_REPORT; - - static GattAttribute * descs[] = { - &inputReportReferenceDescriptor, - }; - return descs; -} - -GattAttribute** HIDServiceBase::outputReportDescriptors() { - outputReportReferenceData.ID = 0; - outputReportReferenceData.type = OUTPUT_REPORT; - - static GattAttribute * descs[] = { - &outputReportReferenceDescriptor, - }; - return descs; -} - -GattAttribute** HIDServiceBase::featureReportDescriptors() { - featureReportReferenceData.ID = 0; - featureReportReferenceData.type = FEATURE_REPORT; - - static GattAttribute * descs[] = { - &featureReportReferenceDescriptor, - }; - return descs; -} - -GattAttribute** HIDServiceBase::reportMapDescriptors() { - return 0;/* - static GattAttribute * descs[] = { - &batteryServiceExternalReportReferenceDescriptor, - }; - return descs;*/ -} - -HID_information_t* HIDServiceBase::HIDInformation() { - static HID_information_t info = {HID_VERSION_1_11, 0x00, 0x03}; - - return &info; -} ble_error_t HIDServiceBase::send(const report_t report) { return ble.gattServer().write(inputReportCharacteristic.getValueHandle(),