ble nano hid over gatt

Dependencies:   BLE_API mbed-dev nRF51822

Files at this revision

API Documentation at this revision

Comitter:
cho45
Date:
Fri Sep 02 03:24:36 2016 +0900
Parent:
64:656686e87927
Child:
66:a7c6fbe45cf5
Commit message:
update

Changed in this revision

HIDController_BLE.cpp Show annotated file Show diff for this revision Revisions of this file
Makefile Show annotated file Show diff for this revision Revisions of this file
config.h Show annotated file Show diff for this revision Revisions of this file
--- 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
+}
--- a/Makefile	Fri Sep 02 02:18:25 2016 +0900
+++ b/Makefile	Fri Sep 02 03:24:36 2016 +0900
@@ -123,7 +123,7 @@
 merge:
 	$(SREC_CAT) $(SOFTDEVICE) -intel $(PROJECT).hex -intel -o combined.hex -intel --line-length=44
 
-flash: merge
+flash: keyboard.hex merge
 	dd if=combined.hex of=/Volumes/MBED/firmware.hex conv=notrunc
 
 endif
--- a/config.h	Fri Sep 02 02:18:25 2016 +0900
+++ b/config.h	Fri Sep 02 03:24:36 2016 +0900
@@ -34,4 +34,4 @@
 #define DEBUG_PRINTF(...)
 #endif
 
-#endif
\ No newline at end of file
+#endif