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

Revision:
62:edc9632bcc43
Parent:
60:5913d77c8a4a
Child:
63:66796aef8d68
--- a/main.cpp	Mon Jul 06 21:53:40 2015 +0000
+++ b/main.cpp	Wed Jul 08 13:56:40 2015 +0000
@@ -32,6 +32,7 @@
 UPAS_Serial     Menu;
 
 Timeout         stop;   //This is the stop call back object
+Timeout         logg;    //This is the logging call back object
 
 //UPAS0012 CALIBRATION TRANSFER FUNCTION COEFFICIENTS FROM 'UPAS v2 OSU-calibration primary flow data.xlsx'
 //mass flow sensor output signal (x) vs. mass flow (y)
@@ -79,7 +80,7 @@
 
 float massflow; //g/min
 float volflow; //L/min
-float volflowSet = 1.0; //L/min
+float volflowSet = 2.0; //L/min
 int   logInerval = 10;
 double secondsD = 0;
 float massflowSet;
@@ -104,17 +105,16 @@
 SDFileSystem sd(SPIS_PSELMOSI, SPIS_PSELMISO, SPIS_PSELSCK, SPIS_PSELSS, "sd"); // I believe this matches Todd's pinout, let me know if this doesn't work. (p12, p13, p15, p14)
 
 
-/*void check_stop()   // this checks if it's time to stop and shutdown
+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) \r\n",RTC.hour, RTC.minutes, RTC.seconds, RTC.month, RTC.date, RTC.year);//debig
+    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);//debig
     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
     }
-    wait(0.1);
     stop.detach();
     stop.attach(&check_stop, 5);    // checks stop time every 5 seconds
-}*/
+}
 
 
 void log_data()
@@ -192,6 +192,8 @@
     //sd.unmount();
 
     wait(1);
+    logg.detach();
+    logg.attach(&log_data, 10);
 }
 
 int main()
@@ -200,10 +202,7 @@
 // Setup and Initialization
 //---------------------------------------------------------------------------------------------//
 
-    Timer refresh_Timer;        //sets up a timer for use in loop; how often do we log data?
-    refresh_Timer.start();      //starts the clock on the timer
     RGB_LED.set_led(0,1,1);
-    refresh_Timer.reset(); // resets the timer to zero
 
     Menu.read_menu(E2PROM, refresh_Time, volflowSet, device_name, dutyUp, dutyDown);       //Read all data from the EEPROM here
 fix_error:
@@ -228,7 +227,7 @@
     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
         // serial print a count down??
     }
-    //stop.attach(&check_stop, 30);    // check if we should shut down every 5 seconds, starting 60s after the start.
+    stop.attach(&check_stop, 60);    // check if we should shut down every 5 seconds, starting 60s after the start.
 
 
     if(volflowSet==1.0) {
@@ -303,7 +302,7 @@
         volflow = massflow/atmoRho;
         massflowSet = volflowSet*atmoRho;
         deltaMflow = massflow-massflowSet;
-        //pc.printf("%f,%f,%f,%f,%d,%u,%x\r\n",omronVolt,massflow,massflowSet,deltaMflow,digital_pot_set,digital_pot_set,digital_pot_set);
+        pc.printf("%f,%f,%f,%f,%d,%u,%x\r\n",volflow,massflow,massflowSet,deltaMflow,digital_pot_set,digital_pot_set,digital_pot_set);
         digital_pot_set = (int)(digital_pot_set+(int)((gainFlow*deltaMflow)));
         if(digital_pot_set>=digitalpotMax) {
             digital_pot_set = digitalpotMax;
@@ -320,7 +319,6 @@
 
     sampledVol = 0.0;
     RGB_LED.set_led(0,1,0);
-    refresh_Timer.reset();  //restarts the clock on the timer
 
     //** end of initalization **//
 
@@ -329,20 +327,14 @@
     //---------------------------------------------------------------------------------------------//
     // Main Control Loop
 
+    logg.attach(&log_data, logInerval); // uses callbacks or block Interrupts for anything that uses i2c
     while(1) {
-
-        RTC.get_time();
-        secondsD = (double)RTC.seconds;
-
-        if(fmod(secondsD,logInerval)==0) {
-
-            log_data();
-            refresh_Timer.reset(); // resets the timer to zero
-
-            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
-            }
-
+        //__disable_irq();  // Disable Interrupts
+        //RTC.get_time();
+        //__enable_irq();   // Enable Interrupts
+        //secondsD = (double)RTC.seconds;
+        //if(fmod(secondsD,logInerval)==0) {
+            //log_data();
         }
     }