The firmware of the Grove Node

Dependencies:   BLE_API color_pixels mbed-src-nrf51822 nRF51822

Fork of BLE_LoopbackUART by Bluetooth Low Energy

Revision:
10:f34ff4e47741
Parent:
9:84cb66d0375d
Child:
11:c0885b74a63a
--- a/main.cpp	Thu Nov 06 02:22:01 2014 +0000
+++ b/main.cpp	Thu Jun 04 09:34:13 2015 +0000
@@ -21,7 +21,7 @@
 #include "nrf_delay.h"
 #include "battery.h"
 
-#define DEBUG   0
+#define DEBUG   1
 
 #if DEBUG       // for Arch BLE
 #define LOG(...)        { printf(__VA_ARGS__); }
@@ -49,6 +49,8 @@
 UARTService *uartServicePtr;
 Ticker ticker;
 
+volatile bool ble_is_connected = false;
+
 volatile bool button_event = false;
 
 const int MAX_ARGS = 8;
@@ -66,11 +68,18 @@
 
 int button_detect();
 
+void connectionCallback(Gap::Handle_t handle, const Gap::ConnectionParams_t *params)
+{
+    LOG("Connected\n");
+    ble_is_connected = true;
+}
+
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
 {
     LOG("Disconnected!\n");
     LOG("Restarting the advertising process\n");
     ble.startAdvertising();
+    ble_is_connected = false;
 }
 
 void onDataWritten(const GattCharacteristicWriteCBParams *params)
@@ -125,6 +134,7 @@
 
     LOG("Initialising the nRF51822\n");
     ble.init();
+    ble.onConnection(connectionCallback);
     ble.onDisconnection(disconnectionCallback);
     ble.onDataWritten(onDataWritten);