ST / Mbed OS Node_BLE_Sensors_Device

Dependencies:   X_NUCLEO_IKS01A2

Fork of Node_BLE_Switch_Device by ST

Bluetooth Low Energy enabled device with environmental and inertial features, i.e. "Pressure", "Humidity", "Temperature", "Accelerometer", "Gyroscope", and "Magnetometer", plus "Switch" feature, compatible with BlueST Protocol.

Revision:
7:2b5ed57b088c
Parent:
6:01d49589410e
--- a/source/main.cpp	Tue May 22 16:35:05 2018 +0000
+++ b/source/main.cpp	Mon Aug 06 09:57:49 2018 +0000
@@ -67,7 +67,8 @@
 
 /* Variables -----------------------------------------------------------------*/
 
-/* Button state. */
+/* Switch and toggle state. */
+CustomService::switch_state_t switch_state;
 bool toggle_state;
 
 /* LED to indicate system state. */
@@ -99,6 +100,7 @@
 /* Custom service related functions ------------------------------------------*/
 
 void button_callback(void) {
+    switch_state = (CustomService::switch_state_t) (CustomService::SWITCH_ON - switch_state);
     toggle_state = true;
 }
 
@@ -155,6 +157,13 @@
  */
 void on_data_read_callback(const GattReadCallbackParams *params) {
     /* Reading characteristic and sending it via bluetooth. */
+/*
+    if (params->handle == custom_service->get_state_command_handle()) {
+        if (BLE::Instance().getGapState().connected) {
+            event_queue.call(Callback<void(uint16_t, uint8_t)>(custom_service, &CustomService::send_state), time_stamp++, led_state.read() ? CustomService::SWITCH_ON : CustomService::SWITCH_OFF);
+        }
+    } else
+*/
     if (params->handle == custom_service->get_env_sensors_handle()) {
         if (BLE::Instance().getGapState().connected) {
             get_and_send_env_sensors();
@@ -176,7 +185,7 @@
 void on_data_written_callback(const GattWriteCallbackParams *params) {
     /* Receiving data via bluetooth and writing it to the characteristic. */
     if (params->handle == custom_service->get_state_command_handle()) {
-        led_state.write(((CustomService::switch_state_t) ((uint8_t *) (params->data))[0]));
+        led_state.write(((CustomService::switch_state_t) ((uint8_t *) (params->data))[SWITCH_DATA_INDEX]));
     } 
 }
 
@@ -188,7 +197,7 @@
     /* Reading toggle command and sending it via bluetooth, if needed. */
     if (toggle_state) {
         if (BLE::Instance().getGapState().connected) {
-            event_queue.call(Callback<void(uint16_t, uint8_t)>(custom_service, &CustomService::send_state), time_stamp++, toggle_state ? TOGGLE_ON : TOGGLE_OFF);
+            event_queue.call(Callback<void(uint16_t, uint8_t)>(custom_service, &CustomService::send_state), time_stamp++, switch_state);
             toggle_state = false;
         }
     }