Project for IoT2

Dependencies:   BLE_API BMP085 mbed nRF51822

Fork of nRF51822_SimpleControls by bjay kamwa watanabe

Revision:
4:c6ac3ffb8ed3
Parent:
3:823f105078c7
Child:
5:76d5bf03cadd
diff -r 823f105078c7 -r c6ac3ffb8ed3 main.cpp
--- a/main.cpp	Thu Jan 07 02:49:37 2016 +0000
+++ b/main.cpp	Sun May 29 10:39:53 2016 +0000
@@ -21,6 +21,7 @@
 #include "ble/BLE.h"
 #include "Servo.h"
 #include "GattCallbackParamTypes.h"
+#include "BMP085.h"
 
 #define BLE_UUID_TXRX_SERVICE            0x0000 /**< The UUID of the Nordic UART Service. */
 #define BLE_UUID_TX_CHARACTERISTIC       0x0002 /**< The UUID of the TX Characteristic. */
@@ -32,7 +33,7 @@
 #define DIGITAL_IN_PIN                   P0_5   //A4
 #define PWM_PIN                          P0_16  //D6
 #define SERVO_PIN                        P0_14  //D10
-#define ANALOG_IN_PIN                    P0_6   //A5
+#define ANALOG_IN_PIN                    P0_1   //A0
 
 BLE             ble;
 
@@ -41,10 +42,11 @@
 PwmOut          PWM(PWM_PIN);
 AnalogIn        ANALOG(ANALOG_IN_PIN);
 Servo           MYSERVO(SERVO_PIN);
-
+BMP085  myCaptor(P0_29, P0_28);
 Serial pc(USBTX, USBRX);
 
 static uint8_t analog_enabled = 0;
+static uint8_t captor_enabled = 0;
 static uint8_t old_state = 0;
 
 // The Nordic UART Service
@@ -94,12 +96,17 @@
             
         if(buf[0] == 0x01)
         {
+            
             if(buf[1] == 0x01)
-                LED_SET = 1;
+            while(1)
+            {
+                LED_SET = !LED_SET;
+                wait(0.25);
+            }
             else
                 LED_SET = 0;    
         }
-        else if(buf[0] == 0xA0)
+        else if(buf[0] == 0x06)
         {
             if(buf[1] == 0x01)
                 analog_enabled = 1;
@@ -123,6 +130,13 @@
             LED_SET = 0;
             old_state = 0;    
         }
+        else if(buf[0] == 0xA0)
+        {
+            if(buf[1] == 0x01)
+                captor_enabled = 1;
+            else
+                captor_enabled = 0;
+        }
 
     }
 }
@@ -158,7 +172,17 @@
         buf[2] = (value);
         ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3); 
     }
-    
+    if (captor_enabled)  // if analog reading enabled
+    {
+        // Read and send out
+        myCaptor.update();
+        float s = myCaptor.get_temperature();
+        uint16_t value = s; 
+        buf[0] = (0x0B);
+        buf[1] = (value >> 8);
+        buf[2] = (value);
+        ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 3); 
+    }
     // If digital in changes, report the state
     if (BUTTON != old_state)
     {
@@ -200,7 +224,7 @@
     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
-                                    (const uint8_t *)"Biscuit", sizeof("Biscuit") - 1);
+                                    (const uint8_t *)"Mustafa", sizeof("Mustafa") - 1);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                     (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
     // 100ms; in multiples of 0.625ms.