Code supports writing to the SD card as well as working with the Volckens group smartphone apps for the mbed HRM1017

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

Fork of UPAS_BLE_and_USB by Volckens Group Sensors

Files at this revision

API Documentation at this revision

Comitter:
jelord
Date:
Thu Dec 10 23:32:24 2015 +0000
Parent:
93:b53a9a7cb8f1
Child:
95:0ae0ffddc544
Commit message:
Works with new App and can write to the SD card

Changed in this revision

UPAS_Service.h Show annotated file Show diff for this revision Revisions of this file
Universal_BLE_Menu.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UPAS_Service.h	Thu Dec 10 23:32:24 2015 +0000
@@ -0,0 +1,49 @@
+//CODE BY JAKE LORD
+//ALL RIGHTS RESERVED BY VOLCKENS GROUP, FORT COLLINS CO
+
+#ifndef __BLE_UPAS_SERVICE_H__
+#define __BLE_UPAS_SERVICE_H__
+
+class UPAS_Service {
+public:
+    //All Characteristics shall have a read/write counterpart protocol.  This should prevent corruption of data.  
+    const static uint16_t UPAS_SERVICE_UUID                     = 0xA000; //UUID of Service.
+    
+    const static uint16_t RTC_CHARACTERISTIC_UUID               = 0xA002; //UUID for characteristic to write the RTC to 
+    GattCharacteristic                rtcCharacteristic;
+    
+    const static uint16_t SAMPLETIME_CHARACTERISTIC_UUID        = 0xA003; //UUID of variable that app will read from
+    GattCharacteristic                sampleTimeCharacteristic;
+    
+    const static uint16_t SUBJECTLABEL_CHARACTERISTIC_UUID      = 0xA004; //UUID of variable that app will read from
+    GattCharacteristic                subjectLabelCharacteristic;
+    
+    const static uint16_t RUNREADY_CHARACTERISTIC_UUID    = 0xA005; //UUID of variable that app will read from
+    GattCharacteristic                runReadyCharacteristic;
+    
+    const static uint16_t RUNMODE_CHARACTERISTIC_UUID              = 0xA006; //UUID of variable that app will read from
+    GattCharacteristic                runModeCharacteristic;
+
+
+    UPAS_Service(BLEDevice &_ble, bool placeholder, uint8_t *rtc, uint8_t *sampleTime, uint8_t *subjectLabel) :
+
+        rtcCharacteristic(RTC_CHARACTERISTIC_UUID, rtc,6,20, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY ),
+        sampleTimeCharacteristic(SAMPLETIME_CHARACTERISTIC_UUID, sampleTime,12,20,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        subjectLabelCharacteristic(SUBJECTLABEL_CHARACTERISTIC_UUID, subjectLabel,15,20,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        runReadyCharacteristic(RUNREADY_CHARACTERISTIC_UUID,0,0,20,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        runModeCharacteristic(RUNMODE_CHARACTERISTIC_UUID,0,0,20,GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+        ble(_ble) 
+    {
+        
+        GattCharacteristic *charTable[] = {&rtcCharacteristic, &sampleTimeCharacteristic, &subjectLabelCharacteristic, &runReadyCharacteristic, &runModeCharacteristic}; //Set up characteristics to be broadcasted with the UPAS service
+        GattService         upasService(UPAS_Service::UPAS_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); //Finally, construct the service
+        ble.addService(upasService);
+    }
+
+private:
+    BLEDevice                               &ble;
+    
+   // ReadOnlyGattCharacteristic<bool>  placeholderState;
+};
+
+#endif /* #ifndef __BLE_UPAS_SERVICE_H__ */
--- a/Universal_BLE_Menu.lib	Fri Oct 09 21:49:18 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/teams/Vockens-Group-Sensors/code/Universal_BLE_Menu/#35b8560d7dfa
--- a/main.cpp	Fri Oct 09 21:49:18 2015 +0000
+++ b/main.cpp	Thu Dec 10 23:32:24 2015 +0000
@@ -11,33 +11,24 @@
 #include "EEPROM.h"
 #include "US_Menu.h"
 #include "BLEDevice.h"
-#include "BLE_Menu.h"
 #include "Calibration.h"
+#include "UPAS_Service.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. */
-#define BLE_UUIDS_RX_CHARACTERISTIC      0x0003 /**< The UUID of the RX Characteristic. */
 
 #define SERIAL_BAUD_RATE    9600
 #define SCL         20
 #define SDA         22
 
 
-uint8_t txPayload[TXRX_BUF_LEN] = {0,};
-uint8_t rxPayload[TXRX_BUF_LEN] = {0,};
 
-static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
-static const uint8_t uart_tx_uuid[]   = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
-static const uint8_t uart_rx_uuid[]   = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
-static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};
+
 
-GattCharacteristic  txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
-GattCharacteristic  rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
-GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};
-GattService         uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));
-
+uint8_t startAndEndTime[12] = {0,}; 
+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
 BLEDevice   ble;
-BLE_Menu    bleMenu(ble, txPayload, rxPayload, uart_base_uuid_rev, uart_base_uuid, uartService);
+UPAS_Service *upasServicePtr;
+//BLE_Menu    bleMenu(ble, txPayload, rxPayload, uart_base_uuid_rev, uart_base_uuid, uartService);
 
 I2C                 i2c(p22, p20);
 Adafruit_ADS1115    ads(&i2c);
@@ -121,20 +112,48 @@
 
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
 {
-    bleMenu.disconnectionCallback();
+    ble.startAdvertising();
 }
 
 void WrittenHandler(const GattCharacteristicWriteCBParams *Handler) // called any time the phone sends a message
 {
-    bleMenu.WrittenHandler(pc, txPayload, txCharacteristic,  Handler);
-    //returns things to the txPayload
+   uint8_t *writeData =  const_cast<uint8_t*>(Handler->data);
+    // check to see what characteristic was written, by handle
+    if(Handler->charHandle == upasServicePtr->rtcCharacteristic.getValueAttribute().getHandle()) {
+
+
+        
+        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(Handler->charHandle == upasServicePtr->sampleTimeCharacteristic.getValueAttribute().getHandle()){
+        
+        E2PROM.write(0x00015, writeData, 12);
+    
+    }else if(Handler->charHandle == upasServicePtr->subjectLabelCharacteristic.getValueAttribute().getHandle()){
+        E2PROM.write(0x00001,writeData,15);
+    
+    }else if(Handler->charHandle == upasServicePtr->runReadyCharacteristic.getValueAttribute().getHandle()){
+        uint8_t runData = writeData[0];
+        
+        if(runData == 10){
+             RunReady = 10;
+             RGB_LED.set_led(1,2,3);
+        }else{ 
+             RunReady = 2;
+        }
+    
+    }else if(Handler->charHandle == upasServicePtr->runModeCharacteristic.getValueAttribute().getHandle()){
+        /* Trigger demo mode*/
+        RGB_LED.set_led(3,1,0);
+        E2PROM.write(0x00036,writeData,1);
+    }
 }
 
 void check_stop()   // this checks if it's time to stop and shutdown
 {
-    //RTC.get_time(); //debug
-    //pc.printf("%02d:%02d:%02d on %d/%d/%d checking if it's time to shutdown \r\n",RTC.hour, RTC.minutes, RTC.seconds, RTC.month, RTC.date, RTC.year);//debug
-    if(RTC.compare(Menu.f_sec, Menu.f_min, Menu.f_hour, Menu.f_day, Menu.f_month, Menu.f_year)) {
+    
+    if(RTC.compare(startAndEndTime[6], startAndEndTime[7], startAndEndTime[8], startAndEndTime[9], startAndEndTime[10], startAndEndTime[11])) {
         pbKill = 0; // this is were we shut everything down
         pc.printf("If you're reading this something has gone very wrong.");
     }
@@ -146,26 +165,11 @@
 void log_data()
 {
     logg.detach();
-   // if(logInerval < 1){
-        logg.attach(&log_data, logInerval);     // reading and logging data must take significintly less than 0.5s. This can be increased.
-   // }else{
-   //     logg.attach(&log_data, logInerval-0.5); // reading and logging data must take significintly less than 0.5s. This can be increased.
-   // }
+
+    logg.attach(&log_data, logInerval);     // reading and logging data must take significintly less than 0.5s. This can be increased.
+
     RTC.get_time();
-    //*****************************************//
-    //RTC.get_time(); //debug
-    //pc.printf("%02d:%02d:%02d on %d/%d/%d before fmod  \r\n",RTC.hour, RTC.minutes, RTC.seconds, RTC.month, RTC.date, RTC.year);//debug
-    //*****************************************//
-    //secondsD = RTC.seconds;
-    //while(fmod(secondsD,logInerval)!=0) {
-    //    RTC.get_time();
-    //    secondsD = RTC.seconds;
-    //    wait_ms(5);
-    //}
-    //*****************************************//
-    //RTC.get_time(); //debug
-    //pc.printf("%02d:%02d:%02d on %d/%d/%d after fmod \r\n",RTC.hour, RTC.minutes, RTC.seconds, RTC.month, RTC.date, RTC.year);//debug
-    //*****************************************//
+
     omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V
     omronVolt = (omronReading*4.096)/(32768*2);
 
@@ -244,93 +248,79 @@
         Menu.factory_reset(E2PROM, logInerval,refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num);
     }
     //**************//BLE initialization//**************//
-    bleMenu.read_menu(E2PROM, logInerval,refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num);   //Read all data from the EEPROM here
-    uint8_t BLE_name[] = {device_name[0], device_name[1], device_name[2], device_name[3], device_name[4], device_name[5], device_name[6], device_name[7], device_name[8]};
+    RTC.get_time();
+    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();
-    // setup advertising
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+    ble.onDisconnection(disconnectionCallback);
+    ble.onDataWritten(WrittenHandler); //add writeCharCallback (custom function) to whenever data is being written to device
+    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 
+    Following lines do the follow:
+        1:Declare the device as Bluetooth Smart(Low-Energy)
+        2.Advertise the UPAS service that will send and receive the 57-bits of settable values in the UPAS EEPROM
+        3.Advertise the name that will be associated with the UPAS
+        4.Allow the UPAS to advertise unrestricted (this might change) */
+        
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
+    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
     ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,(const uint8_t *)BLE_name, sizeof(BLE_name) - 1); // ~8 char max!
-    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.
-    ble.setAdvertisingInterval(160);
-    ble.addService(uartService);
+    ble.setAdvertisingInterval(160); /* 160ms. */
     ble.startAdvertising();
-    ble.onDisconnection(disconnectionCallback); //what happens when disconected
-    ble.onDataWritten(WrittenHandler);          //what happens when the phone sends a message
+
     //**************//BLE initialization//**************//
+    while (1) {
+        ble.waitForEvent();
+        if(RunReady==2 && blower ==0){ //Code used to see if one-click run should begin
+            calibrations.initialize(serial_num);
+            RGB_LED.set_led(3,0,2);
+            blower=1;
+            RunReady=0;
+         }
+         if(RunReady==2 && blower ==1){ //Code used to see if one-click run is done.
+            blower=0;
+            RunReady=0;
+         }
+         
+        if(RunReady==10){ //Check to see if app is done with configurations
+           blower = 0;
+           ble.stopAdvertising();
+           break;
+       }
+    }
+
+    E2PROM.read(0x00015, startAndEndTime, 12); //Grab start and end times from EEPROM
+    while(!RTC.compare(startAndEndTime[0], startAndEndTime[1], startAndEndTime[2], startAndEndTime[3], startAndEndTime[4], startAndEndTime[5])) {  // this while waits for the start time by looping until the start time
+            wait(0.5);
+            RTC.get_time(); 
+
+        }
+    calibrations.initialize(serial_num);
+    blower=1;
+    
+   // while(!RTC.compare(startAndEndTime[6], startAndEndTime[7], startAndEndTime[8], startAndEndTime[9], startAndEndTime[10], startAndEndTime[11])) { //Waits for end time
+//        wait(0.5);
+//        RTC.get_time(); 
+//
+//    }
+    //pbKill = 0; // this is were we shut everything down
 
 
 
-    //Test for errors
-    //RunReady = 0; //debug always open the menu
-    //if(RTC.OSF()) {                 //Force the menu open if the RTC needs reset.
-    //    RunReady = 0;
-    //}
-Reopen:
-    temp_crr = Menu.crr;
-    if((Menu.crr &0x01) != 0x01) { // crr bit 0, should the menu be optional
-        RGB_LED.set_led(1,1,1);
-        wait(5);
-        RGB_LED.set_led(1,1,0);
-        Menu.Start(pc, E2PROM, RTC, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, Menu.menu_ops, 2, serial_num, calibrations);  //Forces you to open the menu
-        bleMenu.open_menu(txPayload, rxCharacteristic, E2PROM, RTC, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, Menu.menu_ops ,RunReady, 3, serial_num, calibrations);
-    } else if(RunReady == 0 ) {
-        RGB_LED.set_led(0,1,1); // error code/color
-        //pc.printf("Fix RTC\r\n");
-        while(RunReady == 0 ) {
-            RGB_LED.set_led(0,1,1);   // error code/color
-            RunReady = Menu.Start(pc, E2PROM, RTC, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, Menu.menu_ops, 0.25, serial_num, calibrations);  //Forces you to open the menu
-            RGB_LED.set_led(0,3,3); // error code/color
-            bleMenu.open_menu(txPayload, rxCharacteristic, E2PROM, RTC, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, Menu.menu_ops ,RunReady, 0.25, serial_num, calibrations);
-        }
+
+
 
-        if((Menu.crr & 0x08) != 0) { // crr bit 3, power down prepared to sample 24hr when powered on
-            RunReady = 1;
-            Menu.save_menu(E2PROM, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num);       //Save all data to the EEPROM
-            
-            pbKill = 0;
-        }
-    }
-    /*if(((Menu.crr & 0x02) != 0) || ((Menu.crr & 0x02) != 0)) {
-        RTC.get_time();
-        if(RTC.OSF()) {  //Don't proceed if the time needs to be reset
-            RGB_LED.set_led(0,1,1); // error code/color
-            pc.printf("Please fix the Time before exiting!\r\n");
-            RunReady = 0;
-            goto Reopen;
-        }
-    }*/
-    if((Menu.crr & 0x02) != 0) {
-        RTC.get_time();
-        if(RTC.compare(Menu.s_sec, Menu.s_min, Menu.s_hour, Menu.s_day, Menu.s_month, Menu.s_year)) {  //Don't proceed if it's already time to start
-            RGB_LED.set_led(0,1,1); // error code/color
-            pc.printf("Please fix the START time before exiting!\r\n");
-            RunReady = 0;
-            goto Reopen;
-        }
-    }
-    // Compare function for 519(UBCUO) mode to have it wait for the start time to start
-    if(((Menu.crr & 0x04) != 0) && ((Menu.crr & 0x08) == 0)) {
-        RTC.get_time();
-        //Need to add in a compare function to check to see if the start time has already passed.
-        if(RTC.compare(Menu.f_sec, Menu.f_min, Menu.f_hour, Menu.f_day, Menu.f_month, Menu.f_year)) {  //Don't proceed if it's already time to stop
-            RGB_LED.set_led(0,1,1); // error code/color
-            pc.printf("Please fix the STOP time before exiting!\r\n");
-            RunReady = 0;
-            goto Reopen;
-        }
-    }
-    
-    if(bleMenu.crr != temp_crr ) { 
-        Menu.crr = bleMenu.crr; // if this was changed in the UBM move it to the primary USM before saving
-        Menu.save_menu(E2PROM, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num);       //Save all data to the EEPROM
-    }
-    //if(Menu.crr != temp_crr) {
-    //    Menu.save_menu(E2PROM, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num);       //Save all data to the EEPROM
-    //    //RunReady = ?;
-    //    goto Restart;
-    //}
+
+
+
     
     pc.printf("You're done, you can now disconect the USB cable.\r\n");
     RunReady = 0;
@@ -338,26 +328,11 @@
     
     RGB_LED.set_led(1,1,0);
 
-    if((Menu.crr & 0x10) != 0) { //crr bit 4 uses Demo values
-        //volflowSet = 1.0; //L/min
-        //logInerval = 10;
-    }
-
-    if((Menu.crr & 0x02) != 0) {
-        while(!RTC.compare(Menu.s_sec, Menu.s_min, Menu.s_hour, Menu.s_day, Menu.s_month, Menu.s_year)) {  // this while waits for the start time by looping until the start time
-            wait(0.5);
-            RTC.get_time(); //debug
-            pc.printf("%02d:%02d:%02d on %d/%d/%d) \r\n",RTC.hour, RTC.minutes, RTC.seconds, RTC.month, RTC.date, RTC.year);//debug
-            //pc.printf("Waiting to start\r\n");
-            // serial print a count down??
-        }
-    }
 
     calibrations.initialize(serial_num);
 
-    if((Menu.crr & 0x04) != 0) { // don't shut off when in demo mode
-        stop.attach(&check_stop, 60);    // check if we should shut down every 9 seconds, starting 60s after the start.
-    }
+
+    stop.attach(&check_stop, 60);    // check if we should shut down every 9 seconds, starting 60s after the start.
 
     if(volflowSet<=1.0) {
         gainFlow = 100;
@@ -376,20 +351,8 @@
     massflowSet = volflowSet*atmoRho;
     //Digtal pot tf from file: UPAS v2 OSU-PrimaryFlowData FullSet 2015-05-29 CQ mods.xlsx
 
-    //--------------------------------------------------------------//
-    //  Calibration value checks   //
-    //--------------------------------------------------------------//
-    //while(1){
-    //pc.printf("%f,%f,%f,%f,%f\r\n",calibrations.DP4, calibrations.DP3, calibrations.DP2, calibrations.DP1, calibrations.DP0);
-    //pc.printf("%f,%f,%f,%f\r\n",calibrations.omronVMin, calibrations.omronVMax, calibrations.omronMFMin, calibrations.omronMFMax);
-    //pc.printf("%f,%f,%f,%f,%f\r\n",calibrations.MF4, calibrations.MF3, calibrations.MF2, calibrations.MF1, calibrations.MF0);
-    //wait(1);
-    //}
-    //--------------------------------------------------------------//
-    //--------------------------------------------------------------//
 
     digital_pot_setpoint = (int)floor(calibrations.DP4*pow(massflowSet,4)+calibrations.DP3*pow(massflowSet,3)+calibrations.DP2*pow(massflowSet,2)+calibrations.DP1*massflowSet+calibrations.DP0); //min = 0x7F, max = 0x00
-    //pc.printf("%d\r\n", digital_pot_setpoint);
 
     if(digital_pot_setpoint>=digitalpotMax) {
         digital_pot_setpoint = digitalpotMax;
@@ -400,71 +363,12 @@
     DigPot.writeRegister(digital_pot_setpoint);
     wait(1);
     blower = 1;
-    if((Menu.crr &0x08) != 0) {
-        RTC.get_time();
-        Menu.f_sec = RTC.seconds;
-        Menu.f_min = RTC.minutes;
-        Menu.f_hour = RTC.hour;
-        if(RTC.month == 1 | RTC.month == 3 | RTC.month == 5 | RTC.month == 7 | RTC.month == 8 | RTC.month == 10) {
-            if(RTC.date == 31) {
-                Menu.f_day = 1;
-                Menu.f_month = RTC.month +1;
-                Menu.f_year = RTC.year;
-            } else {
-                Menu.f_day = RTC.date+1;
-                Menu.f_month = RTC.month;
-                Menu.f_year = RTC.year;
-            }
-        } else if(RTC.month == 4 | RTC.month == 6 | RTC.month == 9 | RTC.month == 11) {
-            if(RTC.date == 30) {
-                Menu.f_day = 1;
-                Menu.f_month = RTC.month +1;
-                Menu.f_year = RTC.year;
-            } else {
-                Menu.f_day = RTC.date+1;
-                Menu.f_month = RTC.month;
-                Menu.f_year = RTC.year;
-            }
-        } else if(RTC.month == 2) {
-            if(RTC.year == 16 | RTC.year == 20 | RTC.year == 24| RTC.year == 28) {
-                if(RTC.date == 29) {
-                    Menu.f_day = 1;
-                    Menu.f_month = RTC.month +1;
-                    Menu.f_year = RTC.year;
-                } else {
-                    Menu.f_day = RTC.date+1;
-                    Menu.f_month = RTC.month;
-                    Menu.f_year = RTC.year;
-                }
-            } else {
-                if(RTC.date == 28) {
-                    Menu.f_day = 1;
-                    Menu.f_month = RTC.month +1;
-                    Menu.f_year = RTC.year;
-                } else {
-                    Menu.f_day = RTC.date+1;
-                    Menu.f_month = RTC.month;
-                    Menu.f_year = RTC.year;
-                }
-            }
-        } else if(RTC.month == 12) {
-            if(RTC.date == 31) {
-                Menu.f_day = 1;
-                Menu.f_month = 1;
-                Menu.f_year = RTC.year+1;
-            } else {
-                Menu.f_day = RTC.date+1;
-                Menu.f_month = RTC.month;
-                Menu.f_year = RTC.year;
-            }
-        }
-    }
-    Menu.save_menu(E2PROM, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num);       //Save all data to the EEPROM
+   
+    //Menu.save_menu(E2PROM, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, RunReady, serial_num);       //Save all data to the EEPROM
             
     sprintf(filename, "/sd/UPAS%04dLOG_%02d-%02d-%02d_%02d=%02d=%02d_%s.txt",serial_num,RTC.year,RTC.month,RTC.date,RTC.hour,RTC.minutes,RTC.seconds,device_name);
     FILE *fp = fopen(filename, "w");
     fclose(fp);
-    //pc.printf("%d\r\n",digital_pot_setpoint);
 
     //---------------------------------------------------------------------------------------------//
     //Following lines are needed to enter into the initiallization flow control loop
@@ -504,8 +408,7 @@
         volflow = massflow/atmoRho;
         massflowSet = volflowSet*atmoRho;
         deltaMflow = massflow-massflowSet;
-        //pc.printf("%f,%f,%f,%f,%d,%u,%x\r\n",volflow,massflow,massflowSet,deltaMflow,digital_pot_set,digital_pot_set,digital_pot_set);
-        //pc.printf("%d,%d,%d,%d,%d,%d\r\n",Menu.f_sec,Menu.f_min,Menu.f_hour,Menu.f_day,Menu.f_month,Menu.f_year,digital_pot_set);
+
         digital_pot_set = (int)(digital_pot_set+(int)((gainFlow*deltaMflow)));
         if(digital_pot_set>=digitalpotMax) {
             digital_pot_set = digitalpotMax;
@@ -532,16 +435,6 @@
 
 
     logg.attach(&log_data, logInerval); // uses callbacks or block Interrupts for anything that uses i2c
-    /*while(1) {
-        //__disable_irq();  // Disable Interrupts
-        //RTC.get_time();
-        //__enable_irq();   // Enable Interrupts
-        //secondsD = (double)RTC.seconds;
-        //if(fmod(secondsD,logInerval)==0) {
-        //log_data();
-        //}
-    }
-    */
 
 }