ble nano hid over gatt

Dependencies:   BLE_API mbed-dev nRF51822

Revision:
65:391ce51e37cc
Parent:
62:51a4d49e5ae0
Child:
66:a7c6fbe45cf5
--- a/HIDController_BLE.cpp	Fri Sep 02 02:18:25 2016 +0900
+++ b/HIDController_BLE.cpp	Fri Sep 02 03:24:36 2016 +0900
@@ -104,20 +104,20 @@
 	controllerStatus = DISCONNECTED;
 
 	/**< Minimum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/
-    uint16_t minConnectionInterval = Gap::MSEC_TO_GAP_DURATION_UNITS(15);
-    /**< Maximum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/
-    uint16_t maxConnectionInterval = Gap::MSEC_TO_GAP_DURATION_UNITS(20);
-    /**< Slave Latency in number of connection events, see BLE_GAP_CP_LIMITS.*/
-    uint16_t slaveLatency = 4;
-    /**< Connection Supervision Timeout in 10 ms units, see BLE_GAP_CP_LIMITS.*/ 
-    uint16_t connectionSupervisionTimeout = 32 * 100;
-    Gap::ConnectionParams_t connectionParams = {
-    	minConnectionInterval,
-    	maxConnectionInterval,
-    	slaveLatency,
-    	connectionSupervisionTimeout
-    };
-    	
+	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(30);
+	/**< Slave Latency in number of connection events, see BLE_GAP_CP_LIMITS.*/
+	uint16_t slaveLatency = 4;
+	/**< Connection Supervision Timeout in 10 ms units, see BLE_GAP_CP_LIMITS.*/ 
+	uint16_t connectionSupervisionTimeout = 32 * 100;
+	Gap::ConnectionParams_t connectionParams = {
+		minConnectionInterval,
+		maxConnectionInterval,
+		slaveLatency,
+		connectionSupervisionTimeout
+	};
+
 	error = params->error;
 	if (error != BLE_ERROR_NONE) {
 		DEBUG_PRINTF_BLE("error on ble.init() \r\n");
@@ -153,18 +153,18 @@
 	
 	//DEBUG_PRINTF_BLE("setup connection params\r\n");
 
-    ble.gap().setPreferredConnectionParams(&connectionParams);
+	ble.gap().setPreferredConnectionParams(&connectionParams);
 
 	// DEBUG_PRINTF_BLE("general setup\r\n");
+//	error = ble.gap().accumulateAdvertisingPayload(
+//		GapAdvertisingData::BREDR_NOT_SUPPORTED |
+//		GapAdvertisingData::LE_GENERAL_DISCOVERABLE
+//	);
+	// shoud be LE_LIMITED_DISCOVERABLE
 	error = ble.gap().accumulateAdvertisingPayload(
 		GapAdvertisingData::BREDR_NOT_SUPPORTED |
-		GapAdvertisingData::LE_GENERAL_DISCOVERABLE
+		GapAdvertisingData::LE_LIMITED_DISCOVERABLE
 	);
-	// shoud be LE_LIMITED_DISCOVERABLE
-//	error = ble.gap().accumulateAdvertisingPayload(
-//		GapAdvertisingData::BREDR_NOT_SUPPORTED |
-//		GapAdvertisingData::LE_LIMITED_DISCOVERABLE
-//	);
 	if (error != BLE_ERROR_NONE) goto return_error;
 
 	// DEBUG_PRINTF_BLE("set COMPLETE_LIST_16BIT_SERVICE_IDS\r\n");
@@ -205,6 +205,9 @@
 	/* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */
 	ble.gap().setTxPower(0);
 
+	// TODO
+	// ちゃんと接続済みになったら ADV_POLICY_FILTER_ALL_REQS にしないといけないが
+	// ペアリングできてるかどうか知るよしがなくてどうしよもない
 	ble.gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST);
 
 	// DEBUG_PRINTF_BLE("advertising\r\n");
@@ -253,9 +256,9 @@
 	// configure the stack to hold on to CPU during critical timing events.
  	// mbed-classic performs __disabe_irq calls in its timers, which can cause MIC failures 
  	// on secure BLE channels.
-    ble_common_opt_radio_cpu_mutex_t opt;
-    opt.enable = 1;
-    sd_ble_opt_set(BLE_COMMON_OPT_RADIO_CPU_MUTEX, (const ble_opt_t *)&opt);
+	ble_common_opt_radio_cpu_mutex_t opt;
+	opt.enable = 1;
+	sd_ble_opt_set(BLE_COMMON_OPT_RADIO_CPU_MUTEX, (const ble_opt_t *)&opt);
      
 	while (!ble.hasInitialized()) { }
 	DEBUG_PRINTF_BLE("ble.hasIntialized\r\n");
@@ -333,4 +336,4 @@
 return_error:
 	DEBUG_PRINTF_BLE("error with %d\r\n", error);
 	return;
-}
\ No newline at end of file
+}