Reading SenseAir LP8 CO2 sensor over bluetooth low energy

Dependencies:   BLE_API mbed nRF51822

Revision:
2:d02255d8c36f
Parent:
0:ee3787c8e209
Child:
3:933dd59ad44d
diff -r b512a405b584 -r d02255d8c36f LP8_Service.h
--- a/LP8_Service.h	Mon Jun 05 11:10:28 2017 +0000
+++ b/LP8_Service.h	Mon Aug 14 20:52:48 2017 +0000
@@ -7,28 +7,80 @@
 {
 public:
 
-    const static uint16_t LP8_SERVICE_UUID                      = 0xA000;           //set custom UUID´s
-    const static uint16_t LP8_STATE_CHARACTERISTIC_UUID         = 0xA001;           //
+    //UUID descriptors
+    const static uint16_t LP8_SERVICE_UUID                      = 0xA000;           // 
+    const static uint16_t LP8_STATE_CHARACTERISTIC_UUID         = 0xA001;           // CO2 concentration characteristic
+    const static uint16_t LP8_READ_TEMP_UUID                    = 0x2A1F;           // temp (Celsius) characteristic
+    const static uint16_t LP8_VCAP_UUID                         = 0xA010;           // Vcap characteristic (mV)
+    const static uint16_t LP8_ERROR_UUID                        = 0xA011;           // LP8 Error bits characteristic
+    
+    const static uint16_t LP8_WRITE_UUID                        = 0xA002;           // Write calculation control from app to lp8
+    const static uint16_t LP8_WRITTEN_UUID                      = 0xB001;           // display what was written into lp8 calculation control
+    
     
     //constructor setup for Gatt Service
-    LP8_Service(BLE &_ble, int co2ValueInitial):                                    /* Passes a refrence to ble stack object and the lp8State copy to the private members */
+    LP8_Service(BLE &_ble, int co2ValueInitial, double tempValueInitial, 
+                int initialVcap, uint32_t initialError, uint8_t initCC):  /* Pass variables to ble stack  */
         ble(_ble), 
-        lp8State(LP8_STATE_CHARACTERISTIC_UUID, &co2ValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
+        lp8State(LP8_STATE_CHARACTERISTIC_UUID, &co2ValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        lp8Temp(LP8_READ_TEMP_UUID, &tempValueInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        lp8Vcap(LP8_VCAP_UUID, &initialVcap, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        lp8Error(LP8_ERROR_UUID, &initialError, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        lp8WriteCC(LP8_WRITE_UUID, &initCC),
+        lp8Written(LP8_WRITTEN_UUID, &initCC, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
         {
-            GattCharacteristic *charTable[] = {&lp8State };                                                                     //create an 1 element array with lp8 Gatt characteristic
-            GattService        lp8Service(LP8_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));       //create an LP8 GattService
-            ble.addService(lp8Service);                                                                                         //add gatt service to the ble stack
+            //characterisitics 
+            GattCharacteristic *charTable[] = {&lp8State, &lp8Temp, &lp8Vcap, &lp8Error, &lp8WriteCC, &lp8Written };
+             
+            //Service, Setup for LP8 GattService
+            GattService        lp8Service(LP8_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));       
+            
+            //add gatt service to ble stack
+            ble.addService(lp8Service);                                                                                         
         };
 
+
+//update Gattserver with new values to characteristics
     void updateCo2Value(int co2Value)
     {
-        ble.gattServer().write(lp8State.getValueAttribute().getHandle(),(uint8_t *) &co2Value, sizeof(co2Value));               //update the Gatt Server with new CO2 value
+        ble.gattServer().write(lp8State.getValueAttribute().getHandle(),(uint8_t *) &co2Value, sizeof(co2Value));   
+    };
+
+    void updateTempValue(double tempValue)
+    {
+        ble.gattServer().write(lp8Temp.getValueAttribute().getHandle(),(uint8_t *) &tempValue, sizeof(tempValue));              
+    };
+    
+    void updateVcapValue(int Vcap)
+    {
+        ble.gattServer().write(lp8Vcap.getValueAttribute().getHandle(),(uint8_t *) &Vcap, sizeof(Vcap));                        
     };
+    
+    void updateError(uint32_t lp8ErrorValue)
+    {
+        ble.gattServer().write(lp8Error.getValueAttribute().getHandle(),(uint8_t *) &lp8ErrorValue, sizeof(lp8ErrorValue));                        
+    };
+
+//reWrite written data     
+    void updateDataWritten(uint8_t lp8WrittenValue)
+    {
+        ble.gattServer().write(lp8Written.getValueAttribute().getHandle(),(uint8_t *) &lp8WrittenValue, sizeof(lp8WrittenValue));
+    }
+
 
 private:
 
-    BLE                                 &ble;       //reference to ble object
-    ReadOnlyGattCharacteristic<int>     lp8State;   //
+    BLE                                     &ble;       //
+    
+    //Service Characteristics
+    //Read Values
+    ReadOnlyGattCharacteristic<int>         lp8State;   //
+    ReadOnlyGattCharacteristic<double>      lp8Temp;
+    ReadOnlyGattCharacteristic<int>         lp8Vcap;
+    ReadOnlyGattCharacteristic<uint32_t>    lp8Error;
+    ReadOnlyGattCharacteristic<uint8_t>     lp8Written;
+    //Write Values
+    WriteOnlyGattCharacteristic<uint8_t>    lp8WriteCC;
     
 
 };