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
Diff: main.cpp
- Revision:
- 92:bb36c4bedb8e
- Parent:
- 91:f838d9a5b596
- Child:
- 93:b53a9a7cb8f1
--- a/main.cpp Tue Sep 29 02:01:37 2015 +0000 +++ b/main.cpp Tue Oct 06 03:14:40 2015 +0000 @@ -133,9 +133,10 @@ 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);//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)) { pbKill = 0; // this is were we shut everything down + pc.printf("If you're reading this something has gone very wrong."); } stop.detach(); stop.attach(&check_stop, 9); @@ -145,14 +146,26 @@ void log_data() { logg.detach(); - logg.attach(&log_data, logInerval-0.5); // reading and logging data must take significintly less than 0.5s. This can be increased. + 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. + } RTC.get_time(); - secondsD = RTC.seconds; - while(fmod(secondsD,logInerval)!=0) { - RTC.get_time(); - secondsD = RTC.seconds; - } - + //*****************************************// + //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); @@ -170,7 +183,6 @@ deltaVflow = volflow-volflowSet; massflowSet = volflowSet*atmoRho; deltaMflow = massflow-massflowSet; - if(abs(deltaMflow)>.025) { digital_pot_change = (int)(gainFlow*deltaMflow); @@ -195,7 +207,6 @@ } else { RGB_LED.set_led(0,1,0); } - movementsensor.getACCEL(); movementsensor.getCOMPASS(); compass = movementsensor.getCOMPASS_HEADING(); @@ -206,7 +217,6 @@ mag_x = movementsensor.MagData.x; mag_y = movementsensor.MagData.y; mag_z = movementsensor.MagData.z; - vInReading = ads.readADC_SingleEnded(1, 0xD583); // read channel 0 vBlowerReading = ads.readADC_SingleEnded(2, 0xE783); // read channel 0 omronDiff = ads.readADC_Differential(0x8583); // differential channel 2-3 @@ -216,11 +226,10 @@ uv = lightsensor.getUV(); vis = lightsensor.getVIS(); ir = lightsensor.getIR(); - FILE *fp = fopen(filename, "a"); fprintf(fp, "%02d,%02d,%02d,%02d,%02d,%02d,%1.3f,%1.3f,%2.2f,%4.2f,%2.1f,%1.3f,%1.3f,%5.1f,%1.1f,%1.1f,%1.1f,%1.1f,%d,%d,%d,%d,%d,%d,%d,%d,%d,%1.3f,%1.3f,%f\r\n",RTC.year, RTC.month,RTC.date,RTC.hour,RTC.minutes,RTC.seconds,omronVolt,massflow,temp,press,rh,atmoRho,volflow,sampledVol,accel_x,accel_y,accel_z,accel_comp,uv,omronReading, vInReading, vBlowerReading, omronDiff,gasG.getAmps(), gasG.getVolts(), gasG.getCharge(),digital_pot_set, deltaMflow, deltaVflow, compass); fclose(fp); - + wait_ms(5); } int main() @@ -346,7 +355,7 @@ 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 5 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) { @@ -449,7 +458,8 @@ } } } - + 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); @@ -515,7 +525,6 @@ //** end of initalization **// - //---------------------------------------------------------------------------------------------// //---------------------------------------------------------------------------------------------// // Main Control Loop