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
Revision 85:a95dd5f03818, committed 2015-09-18
- Comitter:
- joshuasmth04
- Date:
- Fri Sep 18 16:00:46 2015 +0000
- Parent:
- 84:85d11d422da3
- Child:
- 86:60c9ec6e48ed
- Commit message:
- A lot of stuff, see the onenote page.;
Changed in this revision
--- a/Calibration.lib Wed Sep 16 16:13:22 2015 +0000 +++ b/Calibration.lib Fri Sep 18 16:00:46 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/Vockens-Group-Sensors/code/Calibration/#a81fe04d1549 +https://developer.mbed.org/teams/Vockens-Group-Sensors/code/Calibration/#68014331c715
--- a/Universal_Serial_Menu.lib Wed Sep 16 16:13:22 2015 +0000 +++ b/Universal_Serial_Menu.lib Fri Sep 18 16:00:46 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/Vockens-Group-Sensors/code/Universal_Serial_Menu/#83e85792a127 +https://developer.mbed.org/teams/Vockens-Group-Sensors/code/Universal_Serial_Menu/#32238c2da2eb
--- a/main.cpp Wed Sep 16 16:13:22 2015 +0000 +++ b/main.cpp Fri Sep 18 16:00:46 2015 +0000 @@ -106,7 +106,6 @@ int dutyUp; int dutyDown; -uint8_t f_sec, f_min, f_hour, f_date, f_month, f_year; // variables are only place holders for the US_Menu // int refreshtime; @@ -133,9 +132,9 @@ 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 - if(RTC.compare(f_sec, f_min, f_hour, f_date, f_month, f_year)) { + 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 } stop.detach(); @@ -154,7 +153,6 @@ secondsD = RTC.seconds; } - omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V omronVolt = (omronReading*4.096)/(32768*2); @@ -231,7 +229,9 @@ // Setup and Initialization //---------------------------------------------------------------------------------------------// Menu.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 - + if(Menu.crr == 255) { + 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]}; @@ -256,17 +256,15 @@ //if(RTC.OSF()) { //Force the menu open if the RTC needs reset. // RunReady = 0; //} - + uint8_t temp_crr = Menu.crr; - if(Menu.crr == 1){ // if in Demo mode allow 1 second for each menu to change out of demo mode - RGB_LED.set_led(1,1,1); + if((Menu.crr &0x01) == 0) { // crr bit 0, should the menu be optional + RGB_LED.set_led(1,1,1); wait(5); - RGB_LED.set_led(1,1,0); + 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); - volflowSet = 1.0; //L/min - logInerval = 10; - }else if(RunReady == 0 || RTC.OSF()) { + } else if(RunReady == 0 || RTC.OSF()) { RGB_LED.set_led(0,1,1); // error code/color //pc.printf("Change Name\r\n"); while(RunReady == 0 || RTC.OSF()) { @@ -275,50 +273,56 @@ RGB_LED.set_led(0,10,10); // 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.menu_ops == 513 && Menu.crr == 0){ + + 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; } } // Compare function for 519(UBCUO) mode to have it wait for the start time to start - if(Menu.menu_ops == 519){ - 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 START or STOP times before exiting!\r\n"); - Menu.Start(pc, E2PROM, RTC, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, Menu.menu_ops, 0, serial_num, calibrations); //Forces you to open the menu - 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 & 0x04) == 1) { + 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 START or STOP times before exiting!\r\n"); + Menu.Start(pc, E2PROM, RTC, logInerval, refreshtime, volflowSet, device_name, dutyUp, dutyDown, home_lat, home_lon, work_lat, work_lon, Menu.menu_ops, 0, serial_num, calibrations); //Forces you to open the menu + 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 + } + pc.printf("You're done, you can now disconect the USB cable.\r\n"); } - pc.printf("You're done, you can now disconect the USB cable.\r\n"); - } - - if(bleMenu.crr != temp_crr){ + if(bleMenu.crr != temp_crr) { Menu.crr = bleMenu.crr; // if this was changed in the UBM move it to the primary USM before saving } - RunReady = 0; 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 RGB_LED.set_led(1,1,0); - - if(Menu.menu_ops == 519){ - 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); - pc.printf("Waiting to start\r\n"); - // serial print a count down?? + + 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);//debig + //pc.printf("Waiting to start\r\n"); + // serial print a count down?? + } } - + calibrations.initialize(serial_num); - - if(Menu.crr == 0){ // don't shut off when in demo mode + + 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. } - - + + if(volflowSet<=1.0) { gainFlow = 100; @@ -336,22 +340,22 @@ atmoRho = ((press-((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)))*100)/(287.0531*(temp+273.15))+((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)*100)/(461.4964*(temp+273.15)); 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); - } + //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; } else if(digital_pot_setpoint<=digitalpotMin) { @@ -361,62 +365,62 @@ DigPot.writeRegister(digital_pot_setpoint); wait(1); blower = 1; - if(Menu.menu_ops == 513) { + if((Menu.crr &0x08) != 0) { RTC.get_time(); - f_sec = RTC.seconds; - f_min = RTC.minutes; - f_hour = RTC.hour; + 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) { - f_date = 1; - f_month = RTC.month +1; - f_year = RTC.year; + Menu.f_day = 1; + Menu.f_month = RTC.month +1; + Menu.f_year = RTC.year; } else { - f_date = RTC.date+1; - f_month = RTC.month; - f_year = RTC.year; + 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) { - f_date = 1; - f_month = RTC.month +1; - f_year = RTC.year; + Menu.f_day = 1; + Menu.f_month = RTC.month +1; + Menu.f_year = RTC.year; } else { - f_date = RTC.date+1; - f_month = RTC.month; - f_year = RTC.year; + 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) { - f_date = 1; - f_month = RTC.month +1; - f_year = RTC.year; + Menu.f_day = 1; + Menu.f_month = RTC.month +1; + Menu.f_year = RTC.year; } else { - f_date = RTC.date+1; - f_month = RTC.month; - f_year = RTC.year; + Menu.f_day = RTC.date+1; + Menu.f_month = RTC.month; + Menu.f_year = RTC.year; } } else { if(RTC.date == 28) { - f_date = 1; - f_month = RTC.month +1; - f_year = RTC.year; + Menu.f_day = 1; + Menu.f_month = RTC.month +1; + Menu.f_year = RTC.year; } else { - f_date = RTC.date+1; - f_month = RTC.month; - f_year = RTC.year; + 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) { - f_date = 1; - f_month = 1; - f_year = RTC.year+1; + Menu.f_day = 1; + Menu.f_month = 1; + Menu.f_year = RTC.year+1; } else { - f_date = RTC.date+1; - f_month = RTC.month; - f_year = RTC.year; + Menu.f_day = RTC.date+1; + Menu.f_month = RTC.month; + Menu.f_year = RTC.year; } } } @@ -465,7 +469,7 @@ 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",f_sec,f_min,f_hour,f_date,f_month,f_year,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;