This is a basic program that provides the necessary BLE service to allow communications with the UPAS

Dependencies:   BLE_API mbed nRF51822 CronoDot EEPROM NCP5623BMUTBG ADS1115 BME280 Calibration_one MCP40D17 SDFileSystem LSM303 SI1145 STC3100

Fork of BLE_Button by Bluetooth Low Energy

Revision:
12:27273e6a50b3
Parent:
11:1058647c66e8
Child:
13:b43ec7e0cc1d
--- a/main.cpp	Fri Oct 23 02:44:23 2015 +0000
+++ b/main.cpp	Mon Oct 26 21:27:48 2015 +0000
@@ -6,6 +6,13 @@
 #include "EEPROM.h"
 #include "CronoDot.h"
 #include "NCP5623BMUTBG.h"
+#include "SDFileSystem.h"
+#include "Adafruit_ADS1015.h"
+#include "MCP40D17.h"
+#include "STC3100.h"
+#include "LSM303.h"
+#include "BME280.h"
+#include "Calibration.h"
 
 BLE         ble;
 //DigitalOut  led1(LED1); //Use of leds is important for debugging
@@ -14,7 +21,14 @@
 DigitalOut          GPS_EN(p4,0); 
 EEPROM              E2PROM(p22, p20);
 CronoDot            RTC(p22, p20);  
-NCP5623BMUTBG       RGB_LED(p22, p20);          
+NCP5623BMUTBG       RGB_LED(p22, p20);   
+Calibration         calibrations(1);     //Default serial/calibration if there are no values for the selected option
+LSM303              movementsensor(p22, p20);
+I2C                 i2c(p22, p20);
+Adafruit_ADS1115    ads(&i2c);
+MCP40D17            DigPot(&i2c);
+BME280              bmesensor(p22, p20);
+STC3100             gasG(p22, p20);       
 /*EEPROM ADDRESSING:
     0:Status bit-Unused
     1-15:Device Name
@@ -33,25 +47,61 @@
     54: Consider RunReady
     55-56: Menu Options
     57+ Nothing*/
-//    .write(uint32_t addr, uint8_t dt[], uint16_t length);
-//        addr -- is where the data in dt[] will be stored, max of 0x3FFFF, 0x00000 to 0x1FFFF on EEPROM 1 and 0x20000 to 0x3FFFF on EEPROM 2 
-//        dt[] -- is unit8_t array that contains the data to be stored. This can only be uint8_t types, single bytes
-//        length -- is the number of bytes to save t the EEPROM, starting at dt[0]
-//        
-//        returns:
-//            Ture(1) -- when if has finished saving the data 
-//            False(0) -- when length is to long to fit on the remainder of the page, when this happens it does not save any data in order to avoid over writing past data
-//
-//    .read(uint32_t addr, uint8_t *rt_data, uint16_t length);
-//        addr -- where the data is requested from, max of 0x3FFFF, 0x00000 to 0x1FFFF on EEPROM 1 and 0x20000 to 0x3FFFF on EEPROM 2 
-//        rt_data -- a local variable where the data from the EEPROM should be stored, again in uint8_t types
-//        length -- how much to read from the EERPOM, this may be limited to <256 bytes?
 
+Timeout         stop;   //This is the stop call back object
+Timeout         logg;   //This is the logging call back object
 const static char     DEVICE_NAME[] = "UPAS"; //Will hold the actual name of the whichever UPAS is being connected to
 static const uint16_t uuid16_list[] = {UPAS_Service::UPAS_SERVICE_UUID}; //Currently a custom 16-bit representation of 128-bit UUID
 
 UPAS_Service *upasServicePtr;
 
+float press,temp,rh;
+int uv,vis,ir;
+float accel_x ,accel_y ,accel_z,angle_x,angle_y,angle_z,compass,accel_comp,mag_x,mag_y,mag_z,massflow,volflow,omronVolt,atmoRho;
+
+int vInReading,vBlowerReading,omronDiff,omronReading,logInerval = 10;
+
+float volflowSet = 1.0; 
+//int   logInerval = 10;
+double secondsD = 0,lastsecondD = 0;
+float massflowSet;
+float deltaVflow = 0.0,deltaMflow = 0.0;
+float gainFlow;
+float sampledVol; //L, total sampled volume
+
+int digital_pot_setpoint,digital_pot_set,digital_pot_change; //min = 0x7F, max = 0x00
+int digitalpotMax = 127;
+int digitalpotMin = 2;
+
+int dutyUp,dutyDown;
+
+// variables are only place holders for the US_Menu //
+int refreshtime;
+float home_lat, home_lon, work_lat, work_lon;
+//*************************************************//
+
+char device_name[] = "---------------";
+char filename[] = "/sd/XXXX0000LOG000000000000---------------.txt";
+SDFileSystem sd(SPIS_PSELMOSI, SPIS_PSELMISO, SPIS_PSELSCK, SPIS_PSELSS, "sd");
+
+//FLAG: NEED FOR MY CODE
+//void check_stop()   // this checks if it's time to stop and shutdown
+//{
+//
+//    if(RTC.compare(Menu.f_sec, Menu.f_min, Menu.f_hour, Menu.f_day, Menu.f_month, Menu.f_year)) {
+//        pbKill = 0; // this is were we shut everything down
+//        printf("If you're reading this something has gone very wrong.");
+//    }
+//    stop.detach();
+//    stop.attach(&check_stop, 9);
+//}
+
+
+
+
+
+
+//MARK: THIS IS ALL CODE NOT TAKEN FROM OTHER MENU>>>DONT ALTER!!!
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)//Code called when mbed ble senses a disconnect
 {
     ble.gap().startAdvertising();
@@ -63,24 +113,24 @@
 }
 void readCharCallin(const GattReadCallbackParams *eventDataP)
 {
-     RTC.get_time();
+    RTC.get_time();
+    const uint8_t refreshPassValues[6] = {RTC.seconds, RTC.minutes,RTC.hour,RTC.date,RTC.month,RTC.year};
+    ble.updateCharacteristicValue( upasServicePtr->rtcCharacteristic.getValueHandle(),refreshPassValues,6);
 }
-void writeCharCallback(const GattWriteCallbackParams *params)
+void writeCharacteristicCallback(const GattWriteCallbackParams *params)
 {
- //   led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */
-    
+    uint8_t *writeData =  const_cast<uint8_t*>(params->data);
     // check to see what characteristic was written, by handle
-    if(params->handle == upasServicePtr->writeChar.getValueHandle()) {
-        // toggle LED if only 1 byte is written
-        if(params->len == 1) {
-            //led1 = params->data[0];
-        }
-        // update the readChar with the value of writeChar
-        ble.updateCharacteristicValue(upasServicePtr->readChar.getValueHandle(),params->data,params->len);
-        uint8_t *writeData =  const_cast<uint8_t*>(params->data);
-      
-        E2PROM.write(0x00015, writeData+6, 12);
+    if(params->handle == upasServicePtr->rtcCharacteristic.getValueHandle()) {
+
+        //ble.updateCharacteristicValue(upasServicePtr->readChar.getValueHandle(),params->data,params->len);
+        
+       // E2PROM.write(0x00015, writeData+6, 12);
         RTC.set_time(writeData[0],writeData[1],writeData[2],writeData[3],writeData[3],writeData[4],writeData[5]);
+   
+    }else if(params->handle == upasServicePtr->sampleTimeCharacteristic.getValueHandle()){
+        
+        E2PROM.write(0x00015, writeData, 12);
     }
 }
 
@@ -91,14 +141,17 @@
     ticker.attach(periodicCallback, 1);
     RGB_LED.set_led(1,1,1);
     RTC.get_time();
-    uint8_t newReadValues[20] = {RTC.seconds, RTC.minutes,RTC.hour,RTC.date,RTC.month,RTC.year};
-    E2PROM.read(0x00015, newReadValues+6, 12);
+    uint8_t rtcPassValues[6] = {RTC.seconds, RTC.minutes,RTC.hour,RTC.date,RTC.month,RTC.year};
+    uint8_t sampleTimePassValues[12] = {0,};
+    uint8_t subjectLabelOriginal[15] = {0,};
+    E2PROM.read(0x00015, sampleTimePassValues, 12);
+    E2PROM.read(0x00001, subjectLabelOriginal,15);
 
     ble.init();
     ble.gap().onDisconnection(disconnectionCallback);
-    ble.gattServer().onDataWritten(writeCharCallback); //add writeCharCallback (custom function) to whenever data is being written to device
+    ble.gattServer().onDataWritten(writeCharacteristicCallback); //add writeCharCallback (custom function) to whenever data is being written to device
     ble.gattServer().onDataRead(readCharCallin);
-    UPAS_Service upasService(ble, false,newReadValues); //Create a GattService that is defined in UPAS_Service.h
+    UPAS_Service upasService(ble, false,rtcPassValues,sampleTimePassValues,subjectLabelOriginal); //Create a GattService that is defined in UPAS_Service.h
     upasServicePtr = &upasService; //Create a pointer to the service (Allows advertisement without specifically adding the service
 
     /* setup advertising