Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Revision:
8:7ba4f82de9b6
Parent:
0:fc77522f4d28
Child:
15:c0c01188a29b
Child:
19:2681edc2f2b9
diff -r ac8277568115 -r 7ba4f82de9b6 aconno_ble/aconno_ble.cpp
--- a/aconno_ble/aconno_ble.cpp	Wed Mar 14 08:48:26 2018 +0000
+++ b/aconno_ble/aconno_ble.cpp	Tue Mar 20 15:13:51 2018 +0000
@@ -4,7 +4,65 @@
  *
  */
 
+#include "main.h"
 #include "aconno_ble.h"
+#include "tasks.h"
+#include "lizzy_service.h"
+
+init_lizzy_t init_lizzy = {
+    .buzz = false,
+    .leds = {false ,false, false},
+    .acc_lsb = LSB_VALUE,
+    .acc_data = {0, 0, 0}
+};
+LizzyService *lizzy_service;
+
+
+void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
+{
+    (lizzy_service->get_ble())->gap().startAdvertising();
+}
+
+void onConnectionCallback(const Gap::ConnectionCallbackParams_t *params){   
+    
+}
+
+void onDataWrittenCallback(const GattWriteCallbackParams *params) 
+{
+    if ((params->handle == lizzy_service->get_buzz_handle()) &&
+        (params->len == 1))
+    {
+        if ((uint8_t)true < *(params->data))
+            lizzy_service->set_buzz_state(true);
+            
+        updateBuzzLedsT.signal_set(UPDATE_BUZZ_LEDS);
+    }
+    else if ((params->handle == lizzy_service->get_red_handle()) &&
+        (params->len == 1))
+    {
+        if ((uint8_t)true < *(params->data))
+            lizzy_service->set_red_state(true);
+            
+        updateBuzzLedsT.signal_set(UPDATE_BUZZ_LEDS);
+    }
+    else if ((params->handle == lizzy_service->get_green_handle()) &&
+        (params->len == 1))
+    {
+        if ((uint8_t)true < *(params->data))
+            lizzy_service->set_green_state(true);
+            
+        updateBuzzLedsT.signal_set(UPDATE_BUZZ_LEDS);
+    }
+    else if ((params->handle == lizzy_service->get_blue_handle()) &&
+        (params->len == 1))
+    {
+        if ((uint8_t)true < *(params->data))
+            lizzy_service->set_blue_state(true);
+            
+        updateBuzzLedsT.signal_set(UPDATE_BUZZ_LEDS);
+    }
+}
+
 
 /**
 * Callback triggered when the ble initialization process has finished
@@ -25,6 +83,12 @@
         return;
     }
     
+    
+    lizzy_service = new LizzyService(ble, &init_lizzy);
+    ble.gap().onDisconnection(disconnectionCallback);
+    //ble.gap().onConnection(onConnectionCallback);         
+    ble.gattServer().onDataWritten(onDataWrittenCallback);
+    
     advertisementPacket.header = APPLICATION_ID;
     advertisementPacket.type = 0x00;
     advertisementPacket.gyroscope[0] = (int16_t)0;