ble nano hid over gatt
Dependencies: BLE_API mbed-dev nRF51822
Diff: KeyboardService.h
- Revision:
- 79:0095bfb18c57
- Parent:
- 75:351d7ffe81d1
- Child:
- 80:3beb0293b384
--- a/KeyboardService.h Fri Sep 02 23:19:19 2016 +0900 +++ b/KeyboardService.h Sat Sep 03 20:36:40 2016 +0900 @@ -89,6 +89,9 @@ uint8_t raw[1]; }; + GattCharacteristic bootKeyboardInputReportCharacteristic; + GattCharacteristic bootKeyboardOutputReportCharacteristic; + InputReportData inputReportDataPublished; InputReportData inputReportData; @@ -111,7 +114,6 @@ static const uint8_t MODIFIER_RIGHT_SHIFT = 1<<5; static const uint8_t MODIFIER_RIGHT_ALT = 1<<6; static const uint8_t MODIFIER_RIGHT_GUI = 1<<7; - public: bool sendAvailable; uint8_t bufferCount; @@ -129,6 +131,19 @@ featureReportLength = sizeof(featureReportData), reportTickerDelay = 20 ), + bootKeyboardInputReportCharacteristic(GattCharacteristic::UUID_BOOT_KEYBOARD_INPUT_REPORT_CHAR, + (uint8_t *)inputReport, inputReportLength, inputReportLength, + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ + | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY + | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE + ), + + bootKeyboardOutputReportCharacteristic(GattCharacteristic::UUID_BOOT_KEYBOARD_OUTPUT_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 + ), isSending(false), sendAvailable(false), bufferCount(0) @@ -141,6 +156,28 @@ inputReportBuffer.reset(); } + virtual void addExtraCharacteristics(GattCharacteristic** characteristics, uint8_t& charIndex) { + DEBUG_PRINTF_BLE("addExtraCharacteristics %d\r\n", charIndex); + characteristics[charIndex++] = &bootKeyboardInputReportCharacteristic; + characteristics[charIndex++] = &bootKeyboardOutputReportCharacteristic; + } + + virtual ble_error_t send(const report_t report) { + if (protocolMode == REPORT_PROTOCOL) { // this is default + return ble.gattServer().write( + bootKeyboardInputReportCharacteristic.getValueHandle(), + report, + inputReportLength + ); + } else { + return ble.gattServer().write( + inputReportCharacteristic.getValueHandle(), + report, + inputReportLength + ); + } + } + void appendReportData(const uint8_t keycode) { uint8_t modifier = toModifierBit(keycode); if (modifier) { @@ -242,7 +279,23 @@ virtual void onDataSent(unsigned int count) { startReportTicker(); } - + + virtual void onDataWritten(const GattWriteCallbackParams *params) { + if (params->handle == inputReportCharacteristic.getValueHandle()) { + DEBUG_PRINTF_BLE_INTERRUPT("onDataWritten: inputReport %d bytes\r\n", params->len); + } else + if (params->handle == outputReportCharacteristic.getValueHandle()) { + DEBUG_PRINTF_BLE_INTERRUPT("onDataWritten: outputReport %d bytes\r\n", params->len); + } else + if (params->handle == featureReportCharacteristic.getValueHandle()) { + DEBUG_PRINTF_BLE_INTERRUPT("onDataWritten: featureReport %d bytes\r\n", params->len); + } else + if (params->handle == protocolModeCharacteristic.getValueHandle()) { + DEBUG_PRINTF_BLE_INTERRUPT("onDataWritten: protocolMode %d bytes %d\r\n", params->len, params->data[0]); + protocolMode = params->data[0]; + } + } + virtual void stopReportTicker(void) { if (reportTickerIsActive) { HIDServiceBase::stopReportTicker();