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:
13:b43ec7e0cc1d
Parent:
12:27273e6a50b3
Child:
14:4fc1788b8ad2
--- a/main.cpp	Mon Oct 26 21:27:48 2015 +0000
+++ b/main.cpp	Mon Nov 02 20:54:48 2015 +0000
@@ -6,13 +6,7 @@
 #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
@@ -22,13 +16,7 @@
 EEPROM              E2PROM(p22, p20);
 CronoDot            RTC(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
@@ -55,51 +43,6 @@
 
 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
@@ -110,16 +53,16 @@
 void periodicCallback(void)
 {
  //   led1 = !led1; /* Do blinky on LED1 to indicate system aliveness. */
-}
-void readCharCallin(const GattReadCallbackParams *eventDataP)
-{
     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);
+    RGB_LED.set_led(3,0,2);
 }
+
 void writeCharacteristicCallback(const GattWriteCallbackParams *params)
 {
     uint8_t *writeData =  const_cast<uint8_t*>(params->data);
+
     // check to see what characteristic was written, by handle
     if(params->handle == upasServicePtr->rtcCharacteristic.getValueHandle()) {
 
@@ -131,6 +74,17 @@
     }else if(params->handle == upasServicePtr->sampleTimeCharacteristic.getValueHandle()){
         
         E2PROM.write(0x00015, writeData, 12);
+    
+    }else if(params->handle == upasServicePtr->subjectLabelCharacteristic.getValueHandle()){
+        E2PROM.write(0x00001,writeData,15);
+    
+    }else if(params->handle == upasServicePtr->twentyFourHourCharacteristic.getValueHandle()){
+        /* Trigger twenty-four run-time mode*/
+        RGB_LED.set_led(2,3,1);
+    
+    }else if(params->handle == upasServicePtr->demoCharacteristic.getValueHandle()){
+        /* Trigger demo mode*/
+        RGB_LED.set_led(3,1,0);
     }
 }
 
@@ -138,7 +92,7 @@
 {
    // led1 = 1;
     Ticker ticker;
-    ticker.attach(periodicCallback, 1);
+    ticker.attach(periodicCallback, 10);
     RGB_LED.set_led(1,1,1);
     RTC.get_time();
     uint8_t rtcPassValues[6] = {RTC.seconds, RTC.minutes,RTC.hour,RTC.date,RTC.month,RTC.year};
@@ -150,7 +104,6 @@
     ble.init();
     ble.gap().onDisconnection(disconnectionCallback);
     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,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
 
@@ -169,7 +122,7 @@
     ble.gap().startAdvertising();
     
     //Loop keeps device in infinite loop waiting for events to occur
-    while (true) {
+    while (1) {
         ble.waitForEvent();
     }
 }