ble nano hid over gatt

Dependencies:   BLE_API mbed-dev nRF51822

Revision:
32:6c0f43fda460
Parent:
30:f9ebc769118d
Child:
34:7da766a8aa96
--- a/HIDController_BLE.cpp	Wed Aug 24 13:11:10 2016 +0000
+++ b/HIDController_BLE.cpp	Thu Aug 25 00:07:21 2016 +0000
@@ -77,27 +77,18 @@
 
 
 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);
 	controllerStatus = CONNECTED;
 }
 
 static void onDisconnect(const Gap::DisconnectionCallbackParams_t *params) {
-	printf("onDisconnect\r\n");
 	controllerStatus = DISCONNECTED;
 	BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
 }
 
 static void onTimeout(const Gap::TimeoutSource_t source) {
-	printf("onTimeout\r\n");
-	controllerStatus = DISCONNECTED;
+	controllerStatus = TIMEOUT;
 	BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
 }
 
@@ -247,12 +238,13 @@
 	/* (Valid values are -40, -20, -16, -12, -8, -4, 0, 4) */
 	ble.gap().setTxPower(0);
 
-	// ble.gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST);
+	ble.gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST);
 
 
-	printf("advertising\r\n");
+	// printf("advertising\r\n");
 	error = ble.gap().startAdvertising();
 	if (error != BLE_ERROR_NONE) goto return_error;
+	controllerStatus = ADVERTISING;
 	return;
 
 return_error:
@@ -268,6 +260,22 @@
 	return controllerStatus;
 }
 
+const char* HIDController::statusString() {
+	static const char* disconnected = "disconnected";
+	static const char* connecting = "connecting";
+	static const char* connected = "connected";
+	static const char* timeout = "timeout";
+	static const char* advertising = "advertising";
+	static const char* unknown = "unknown";
+
+	return controllerStatus == DISCONNECTED ? disconnected:
+	       controllerStatus == CONNECTING ? connecting:
+	       controllerStatus == CONNECTED ? connected:
+	       controllerStatus == TIMEOUT ? timeout:
+	       controllerStatus == ADVERTISING ? advertising:
+	       unknown;
+}
+
 void HIDController::init() {
 	// https://github.com/jpbrucker/BLE_HID/blob/master/examples/examples_common.cpp
 	printf("ble.init\r\n");