attempt to fix posible power issues with the sharp
Dependencies: ADS1115 BME280 CronoDot SDFileSystem mbed
Fork of Outdoor_UPAS_v1_2_Tboard by
Diff: main.cpp
- Revision:
- 9:8646fd501832
- Parent:
- 8:c4a8f9b67cee
- Child:
- 10:06fbb1c9e3bd
--- a/main.cpp Wed Mar 02 16:49:59 2016 +0000 +++ b/main.cpp Wed Mar 02 17:16:43 2016 +0000 @@ -34,10 +34,10 @@ //DigitalOut GPS_EN(p4,0); //pin 4 is used to enable and disable the GPS, in order to recive serial communications Calibration calibrations(1); //Default serial/calibration if there are no values for the selected option -Timeout stop; //This is the stop callback object -//Timeout logg; + +Ticker stop; //This is the stop callback object Ticker logg; //This is the logging callback object -Ticker flowCtl; //This is the control loop callback object +Ticker flowCtl; //This is the control loop callback object uint16_t serial_num = 1; // Default serial/calibration number int RunReady =0; @@ -45,69 +45,64 @@ struct tm STtime; char timestr[32]; -float press = 1.1; -float temp = 75.5; -float rh = 12.1; +float press; +float temp; +float rh; -int uv = 8; -int vis = 7; -int ir = 6; +int uv; +int vis; +int ir; -float compass = 0.1; -float accel_x = 0.2; -float accel_y = 0.3; -float accel_z = 0.4; -float accel_comp = 0.5; -float angle_x = 0.6; -float angle_y = 0.7; -float angle_z = 0.8; -float mag_x = 0.9; -float mag_y = 1.0; -float mag_z = 1.2; +float compass; +float accel_x; +float accel_y; +float accel_z; +float accel_comp; +float angle_x; +float angle_y; +float angle_z; +float mag_x; +float mag_y; +float mag_z; -int vInReading = 18; -int vBlowerReading = 19; -int omronDiff = 20; -float omronVolt = 1.2; //V -int omronReading = 100; -float atmoRho = 1.5; //g/L +int vInReading; +int vBlowerReading; +int omronDiff; +float omronVolt; //V +int omronReading; +float atmoRho; //g/L -float massflow = 87.6; //g/min -float volflow = 88.8; //L/min +float massflow; //g/min +float volflow; //L/min float volflowSet = 1.0; //L/min int logInerval = 10; //seconds double secondsD = 0; double lastsecondD = 0; -float massflowSet = 19.2; +float massflowSet; float deltaVflow = 0.0; float deltaMflow = 0.0; -float gainFlow = 98.1; -float sampledVol = 2.0; //L, total sampled volume +float gainFlow; +float sampledVol; //L, total sampled volume -int digital_pot_setpoint = 5 ; //min = 0x7F, max = 0x00 -int digital_pot_set = 6; -int digital_pot_change = 7; +int digital_pot_setpoint; //min = 0x7F, max = 0x00 +int digital_pot_set; +int digital_pot_change; int digitalpotMax = 127; -int digitalpotMin = 2; +int digitalpotMin = 10; int dutyUp = 4; int dutyDown = 3; // variables are only place holders for the US_Menu // -int refreshtime = 6; +int refreshtime; //int refresh_Time = 10; // refresh time in s, note calling read_GPS()(or similar) will still take how ever long it needs(hopefully < 1s) float home_lat, home_lon, work_lat, work_lon; //*************************************************// - - char filename[] = "/sd/XXXX0000LOG000000000000---------------.txt"; - SDFileSystem sd(D4, D5, D3, D10, "sd"); // I believe this matches Todd's pinout, let me know if this doesn't work. (MOSI, MISO, SCK, SEL) void sendData(); - - static uint8_t rx_buf[20]; static uint8_t rx_len=0; static int haltBLE = 1; @@ -117,7 +112,11 @@ static int runReady = 0; static uint8_t startAndEndTime[12] = {0,}; -void uartMicro(void){ +////////////////////////////////////////////////////////////// +//BLE Functions +////////////////////////////////////////////////////////////// + +void uartMicro(){ if(runReady!=1){ haltBLE = 2; while(microChannel.readable()){ @@ -236,27 +235,32 @@ } - +////////////////////////////////////////////////////////////// +//Shutdown Function +////////////////////////////////////////////////////////////// void check_stop() // this checks if it's time to stop and shutdown { - + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //UPDATE THIS TO WORK WITH ST RTC INSTEAD + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if(RTC_UPAS.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."); } - stop.detach(); - stop.attach(&check_stop, 9); } - +////////////////////////////////////////////////////////////// +//SD Logging Function +////////////////////////////////////////////////////////////// void log_data() { - RGB_LED.set_led(1,1,0); + RGB_LED.set_led(1,1,0); time_t seconds = time(NULL); strftime(timestr, 32, "%y%m%d%H%M%S", localtime(&seconds)); + RTC_UPAS.get_time(); press = bmesensor.getPressure(); temp = bmesensor.getTemperature()-5.0; rh = bmesensor.getHumidity(); @@ -264,9 +268,7 @@ FILE *fp = fopen(filename, "a"); - //fprintf(fp, "Time as a basic string = %s\r\n", ctime(&seconds)); - //fprintf(fp, "Time as a basic string = %s\r\n", timestr); - //fprintf(fp, "%02d,%02d,%02d,%02d,%02d,%02d,",RTC_UPAS.year, RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds); + fprintf(fp, "%02d,%02d,%02d,%02d,%02d,%02d,",RTC_UPAS.year, RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds); fprintf(fp, "%s,", timestr); fprintf(fp, "%1.3f,%1.3f,%2.2f,%4.2f,%2.1f,%1.3f,", omronVolt,massflow,temp,press,rh,atmoRho); fprintf(fp, "%1.3f,%5.1f,%1.1f,%1.1f,%1.1f,%1.1f,", volflow, sampledVol, accel_x, accel_y, accel_z, accel_comp); @@ -279,6 +281,9 @@ } +////////////////////////////////////////////////////////////// +//Flow Control Function +////////////////////////////////////////////////////////////// void flowControl() { RGB_LED.set_led(0,1,0); @@ -326,6 +331,10 @@ //RGB_LED.set_led(0,1,0); } } + +////////////////////////////////////////////////////////////// +//Main Function +////////////////////////////////////////////////////////////// int main(){ //wait(10); @@ -352,7 +361,6 @@ //pc.attach(pc_recv); microChannel.attach(uartMicro,microChannel.RxIrq); microChannel.baud(115200); - //RGB_LED.set_led(1,0,0); microChannel.printf("$$$"); wait(0.5); microChannel.printf("SN,"); @@ -375,7 +383,6 @@ } - //wait(1); E2PROM.read(0x00015, startAndEndTime, 12); //Grab start and end times from EEPROM RGB_LED.set_led(0,1,0); @@ -423,9 +430,6 @@ 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 - - DigPot.writeRegister(digital_pot_setpoint); @@ -434,22 +438,19 @@ uint8_t subjectLabelOriginal[8] = {0,}; E2PROM.read(0x00001, subjectLabelOriginal,8); - //sprintf(filename, "/sd/UPAS%04dLOG_%02d-%02d-%02d_%02d=%02d=%02d_%c%c%c%c%c%c%c%c.txt",serial_num,RTC_UPAS.year,RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds,subjectLabelOriginal[0],subjectLabelOriginal[1],subjectLabelOriginal[2],subjectLabelOriginal[3],subjectLabelOriginal[4],subjectLabelOriginal[5],subjectLabelOriginal[6],subjectLabelOriginal[7]); time_t seconds = time(NULL); strftime(timestr, 32, "%y-%m-%d-%H=%M=%S", localtime(&seconds)); + //sprintf(filename, "/sd/UPAS%04dLOG_%02d-%02d-%02d_%02d=%02d=%02d_%c%c%c%c%c%c%c%c.txt",serial_num,RTC_UPAS.year,RTC_UPAS.month,RTC_UPAS.date,RTC_UPAS.hour,RTC_UPAS.minutes,RTC_UPAS.seconds,subjectLabelOriginal[0],subjectLabelOriginal[1],subjectLabelOriginal[2],subjectLabelOriginal[3],subjectLabelOriginal[4],subjectLabelOriginal[5],subjectLabelOriginal[6],subjectLabelOriginal[7]); sprintf(filename, "/sd/UPASboardtest_%s.txt", timestr); FILE *fp = fopen(filename, "w"); fclose(fp); - //---------------------------------------------------------------------------------------------// - //Following lines are needed to enter into the initiallization flow control loop - sampledVol = 0.0; RGB_LED.set_led(0,1,0); - //log_data(); - stop.attach(&check_stop, 31); // check if we should shut down every 9 seconds, starting 60s after the start. + + stop.attach(&check_stop, 9); // check if we should shut down every 9 number seconds, starting after the start. logg.attach(&log_data, logInerval); flowCtl.attach(&flowControl, 1);