ble nano hid over gatt
Dependencies: BLE_API mbed-dev nRF51822
Diff: HIDController_BLE.cpp
- Revision:
- 23:b31957ce64e9
- Parent:
- 22:a78f0a91280a
- Child:
- 24:a4dbde033def
--- a/HIDController_BLE.cpp Mon Aug 22 15:24:34 2016 +0000 +++ b/HIDController_BLE.cpp Mon Aug 22 17:34:10 2016 +0000 @@ -76,11 +76,13 @@ static void onConnect(const Gap::ConnectionCallbackParams_t *params) { + /* printf("onConnect: "); for (unsigned i = 0; i < Gap::ADDR_LEN; i++) { printf("%02x", params->peerAddr[i]); } printf("\r\n"); + */ peerAddress.type = params->peerAddrType; memcpy(peerAddress.address, params->peerAddr, Gap::ADDR_LEN); } @@ -120,7 +122,6 @@ // BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_SCAN_REQS); // BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_CONN_REQS); BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_ALL_REQS); - connected = true; } else { printf("Security failed %d\r\n", status); @@ -135,13 +136,15 @@ // https://developer.mbed.org/compiler/#nav:/keyboard/BLE_API/ble/blecommon.h; ble_error_t error; BLE &ble = params->ble; + + connected = false; /**< Minimum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/ uint16_t minConnectionInterval = Gap::MSEC_TO_GAP_DURATION_UNITS(24); /**< Maximum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/ uint16_t maxConnectionInterval = Gap::MSEC_TO_GAP_DURATION_UNITS(44); /**< Slave Latency in number of connection events, see BLE_GAP_CP_LIMITS.*/ - uint16_t slaveLatency = 4; + uint16_t slaveLatency = 0; /**< Connection Supervision Timeout in 10 ms units, see BLE_GAP_CP_LIMITS.*/ uint16_t connectionSupervisionTimeout = 32 * 100; Gap::ConnectionParams_t connectionParams = { @@ -235,6 +238,8 @@ /* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */ ble.gap().setTxPower(0); + // ble.gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST); + printf("advertising\r\n"); error = ble.gap().startAdvertising(); @@ -258,7 +263,6 @@ ble.init(bleInitComplete); while (!ble.hasInitialized()) { } - printf("ble.hasIntialized\r\n"); } @@ -284,6 +288,7 @@ void HIDController::queueCurrentReportData() { if (!connected) return; if (keyboardService) { + printf("queueCurrentReportData\r\n"); keyboardService->queueCurrentReportData(); } }