ble nano hid over gatt
Dependencies: BLE_API mbed-dev nRF51822
Diff: KeyboardService.h
- Revision:
- 60:b899414e1d34
- Parent:
- 59:2d6c0bff2151
- Child:
- 75:351d7ffe81d1
--- a/KeyboardService.h Wed Aug 31 12:31:14 2016 +0000 +++ b/KeyboardService.h Wed Aug 31 13:44:47 2016 +0000 @@ -59,24 +59,30 @@ END_COLLECTION(0), }; +union InputReportData { + uint8_t raw[8]; + struct { + uint8_t modifier; + uint8_t padding; + uint8_t keycode[6]; + } data; +}; + +union { + uint8_t raw[1]; +} outputReportData; + class KeyboardService : public HIDServiceBase { - union InputReportData { - uint8_t raw[8]; - struct { - uint8_t modifier; - uint8_t padding; - uint8_t keycode[6]; - } data; - }; InputReportData inputReportDataPublished; InputReportData inputReportData; - union { - uint8_t raw[1]; - } outputReportData; - - CircularBuffer<InputReportData, 24, uint8_t> inputReportBuffer; + // 5ms ごとのスイッチ判定・20ms ごとの送信 + // 人間の連打限界を16press/secとし keydown/keyup それぞれでレポートを送ることを考えると + // 32report/sec = 31msec で、限界で連打しても20msごとの送信にまにあう + // ただし上記は1キーに対してであり、複数キーを全力で押すとキューに溜まることがある + // 実際にカウントして測ってみたところ、どんなに乱暴に連打しても8ぐらいまでしかいかない + CircularBuffer<InputReportData, 8, uint8_t> inputReportBuffer; InputReportData inputReportDataSending; bool isSending; @@ -91,6 +97,7 @@ public: bool sendAvailable; + uint8_t bufferCount; KeyboardService(BLE& _ble) : HIDServiceBase( @@ -106,7 +113,8 @@ reportTickerDelay = 20 ), isSending(false), - sendAvailable(false) + sendAvailable(false), + bufferCount(0) { for (int i = 0; i < 8; i++) { inputReportData.raw[i] = 0; @@ -150,6 +158,7 @@ } void queueCurrentReportData() { + bufferCount++; inputReportBuffer.push(inputReportData); startReportTicker(); } @@ -196,6 +205,7 @@ stopReportTicker(); return; } + bufferCount--; } static uint8_t busyCount = 0;