all working version 2.0
Dependencies: ADS1115 BME280 CronoDot SDFileSystem mbed
Fork of Outdoor_UPAS_v1_2_powerfunction by
main.cpp@62:d26214c68686, 2016-05-25 (annotated)
- Committer:
- scottkelleher
- Date:
- Wed May 25 22:38:12 2016 +0000
- Revision:
- 62:d26214c68686
- Parent:
- 61:69ec677bf39f
- Child:
- 63:4bb4e27d057e
sharp2-6 fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jelord | 0:2cb2b2ea316f | 1 | #include "mbed.h" |
jelord | 2:88fcbfadec6a | 2 | #include "SDFileSystem.h" |
jelord | 2:88fcbfadec6a | 3 | #include "Adafruit_ADS1015.h" |
jelord | 2:88fcbfadec6a | 4 | #include "BME280.h" |
jelord | 2:88fcbfadec6a | 5 | #include "CronoDot.h" |
scottkelleher | 57:1695e252298d | 6 | |
caseyquinn | 14:7cdb643da356 | 7 | |
caseyquinn | 56:49387b72460e | 8 | //Edit for fork |
caseyquinn | 12:5b4f3245606a | 9 | ///////////////////////////////////////////// |
caseyquinn | 12:5b4f3245606a | 10 | //General Items |
caseyquinn | 12:5b4f3245606a | 11 | ///////////////////////////////////////////// |
caseyquinn | 14:7cdb643da356 | 12 | I2C i2c(PB_9, PB_8);//(D14, D15); SDA,SCL |
caseyquinn | 12:5b4f3245606a | 13 | Serial pc(USBTX, USBRX); |
caseyquinn | 12:5b4f3245606a | 14 | BME280 bmesensor(PB_9, PB_8);//(D14, D15); |
caseyquinn | 17:3e6dda6e6335 | 15 | CronoDot RTC_UPAS(PB_9, PB_8);//(D14, D15); |
caseyquinn | 17:3e6dda6e6335 | 16 | |
caseyquinn | 13:455601f62aad | 17 | |
caseyquinn | 12:5b4f3245606a | 18 | ///////////////////////////////////////////// |
caseyquinn | 12:5b4f3245606a | 19 | //Analog to Digital Converter |
caseyquinn | 12:5b4f3245606a | 20 | ///////////////////////////////////////////// |
scottkelleher | 59:4221935a12d8 | 21 | Adafruit_ADS1115 ads(&i2c); |
scottkelleher | 61:69ec677bf39f | 22 | Adafruit_ADS1115 ads2(&i2c,0x49); |
caseyquinn | 12:5b4f3245606a | 23 | //DigitalIn ADS_ALRT(PA_10); //Connected but currently unused. (ADS1115) http://www.ti.com/lit/ds/symlink/ads1115.pdf |
caseyquinn | 12:5b4f3245606a | 24 | |
caseyquinn | 12:5b4f3245606a | 25 | |
caseyquinn | 23:1ca41779b8ec | 26 | |
caseyquinn | 12:5b4f3245606a | 27 | ///////////////////////////////////////////// |
caseyquinn | 12:5b4f3245606a | 28 | //SD Card |
caseyquinn | 12:5b4f3245606a | 29 | ///////////////////////////////////////////// |
scottkelleher | 61:69ec677bf39f | 30 | char filename[] = "/sd/SHARP_working1.txt"; |
scottkelleher | 57:1695e252298d | 31 | SDFileSystem sd(D11, D12, D13, D10, "sd"); // (MOSI, MISO, SCK, SEL) |
scottkelleher | 57:1695e252298d | 32 | //DigitalIn sdCD(PA_11, PullUp); |
caseyquinn | 52:95949e34b1f6 | 33 | |
caseyquinn | 14:7cdb643da356 | 34 | |
caseyquinn | 12:5b4f3245606a | 35 | ///////////////////////////////////////////// |
caseyquinn | 12:5b4f3245606a | 36 | //Callbacks |
caseyquinn | 12:5b4f3245606a | 37 | ///////////////////////////////////////////// |
caseyquinn | 8:c4a8f9b67cee | 38 | Ticker logg; //This is the logging callback object |
scottkelleher | 57:1695e252298d | 39 | |
jelord | 3:122bfc998c4c | 40 | |
caseyquinn | 12:5b4f3245606a | 41 | ///////////////////////////////////////////// |
caseyquinn | 12:5b4f3245606a | 42 | //Varible Definitions |
caseyquinn | 12:5b4f3245606a | 43 | ///////////////////////////////////////////// |
jelord | 3:122bfc998c4c | 44 | uint16_t serial_num = 1; // Default serial/calibration number |
jelord | 3:122bfc998c4c | 45 | int RunReady =0; |
jelord | 3:122bfc998c4c | 46 | |
caseyquinn | 25:fbf7d44e7da4 | 47 | bool ledOn = 0; |
caseyquinn | 25:fbf7d44e7da4 | 48 | |
caseyquinn | 4:5d004fd997d5 | 49 | struct tm STtime; |
caseyquinn | 7:29b01d5812ee | 50 | char timestr[32]; |
caseyquinn | 43:05aa1fb68946 | 51 | char yrstr[4]; |
caseyquinn | 43:05aa1fb68946 | 52 | char mostr[4]; |
caseyquinn | 43:05aa1fb68946 | 53 | char daystr[4]; |
caseyquinn | 43:05aa1fb68946 | 54 | char hrstr[4]; |
caseyquinn | 43:05aa1fb68946 | 55 | char minstr[4]; |
caseyquinn | 43:05aa1fb68946 | 56 | char secstr[4]; |
caseyquinn | 43:05aa1fb68946 | 57 | |
caseyquinn | 43:05aa1fb68946 | 58 | int stYr, stMo, stDay, stHr, stMin, stSec; |
jelord | 3:122bfc998c4c | 59 | |
caseyquinn | 36:2e344db70d35 | 60 | |
caseyquinn | 9:8646fd501832 | 61 | float press; |
caseyquinn | 9:8646fd501832 | 62 | float temp; |
caseyquinn | 9:8646fd501832 | 63 | float rh; |
scottkelleher | 57:1695e252298d | 64 | float atmoRho; //g/L |
scottkelleher | 59:4221935a12d8 | 65 | int logInerval = 2;//seconds |
jelord | 3:122bfc998c4c | 66 | |
scottkelleher | 57:1695e252298d | 67 | DigitalOut sharp1LED(D7, 1); |
scottkelleher | 57:1695e252298d | 68 | DigitalOut sharp2LED(D6, 1); |
scottkelleher | 57:1695e252298d | 69 | DigitalOut sharp3LED(D5, 1); |
scottkelleher | 57:1695e252298d | 70 | DigitalOut sharp4LED(D4, 1); |
scottkelleher | 59:4221935a12d8 | 71 | DigitalOut sharp5LED(D3, 1); |
scottkelleher | 59:4221935a12d8 | 72 | DigitalOut sharp6LED(D2, 1); |
jelord | 3:122bfc998c4c | 73 | |
scottkelleher | 57:1695e252298d | 74 | int samplingTime = 280; |
scottkelleher | 57:1695e252298d | 75 | int deltaTime = 40; |
scottkelleher | 62:d26214c68686 | 76 | int sleepTime= 9680 |
scottkelleher | 59:4221935a12d8 | 77 | int sharp1, sharp2, sharp3, sharp4, sharp5, sharp6; |
scottkelleher | 59:4221935a12d8 | 78 | float sharpVolt1, sharpVolt2, sharpVolt3, sharpVolt4, sharpVolt5, sharpVolt6; //V |
caseyquinn | 12:5b4f3245606a | 79 | |
caseyquinn | 11:aa21628a9b15 | 80 | |
caseyquinn | 11:aa21628a9b15 | 81 | |
caseyquinn | 5:c3252e5d45ca | 82 | |
caseyquinn | 9:8646fd501832 | 83 | ////////////////////////////////////////////////////////////// |
scottkelleher | 57:1695e252298d | 84 | //SD Logging Function |
caseyquinn | 9:8646fd501832 | 85 | ////////////////////////////////////////////////////////////// |
scottkelleher | 57:1695e252298d | 86 | void log_data() |
caseyquinn | 52:95949e34b1f6 | 87 | { |
scottkelleher | 57:1695e252298d | 88 | //Get RTC time(s) |
scottkelleher | 57:1695e252298d | 89 | /////////////////////////// |
scottkelleher | 57:1695e252298d | 90 | RTC_UPAS.get_time(); |
scottkelleher | 57:1695e252298d | 91 | time_t seconds = time(NULL); |
scottkelleher | 57:1695e252298d | 92 | strftime(timestr, 32, "%y%m%d%H%M%S", localtime(&seconds)); |
scottkelleher | 57:1695e252298d | 93 | /* |
caseyquinn | 43:05aa1fb68946 | 94 | strftime(yrstr, 4, "%y", localtime(&seconds)); |
caseyquinn | 43:05aa1fb68946 | 95 | stYr = atoi(yrstr); |
caseyquinn | 43:05aa1fb68946 | 96 | |
caseyquinn | 43:05aa1fb68946 | 97 | strftime(mostr, 4, "%m", localtime(&seconds)); |
caseyquinn | 43:05aa1fb68946 | 98 | stMo = atoi(mostr); |
caseyquinn | 43:05aa1fb68946 | 99 | |
caseyquinn | 43:05aa1fb68946 | 100 | strftime(daystr, 4, "%d", localtime(&seconds)); |
caseyquinn | 43:05aa1fb68946 | 101 | stDay = atoi(daystr); |
caseyquinn | 43:05aa1fb68946 | 102 | |
caseyquinn | 43:05aa1fb68946 | 103 | strftime(hrstr, 4, "%H", localtime(&seconds)); |
caseyquinn | 43:05aa1fb68946 | 104 | stHr = atoi(hrstr); |
caseyquinn | 43:05aa1fb68946 | 105 | |
caseyquinn | 43:05aa1fb68946 | 106 | strftime(minstr, 4, "%M", localtime(&seconds)); |
caseyquinn | 43:05aa1fb68946 | 107 | stMin = atoi(minstr); |
caseyquinn | 43:05aa1fb68946 | 108 | |
caseyquinn | 43:05aa1fb68946 | 109 | strftime(secstr, 4, "%S", localtime(&seconds)); |
caseyquinn | 43:05aa1fb68946 | 110 | stSec = atoi(secstr); |
scottkelleher | 57:1695e252298d | 111 | */ |
caseyquinn | 44:075fa63d5df1 | 112 | //pc.printf("%s,%s,%d,%s,%d,%s,%d,%s,%d,%s,%d,%s,%d\r\n", timestr,yrstr,stYr,mostr,stMo,daystr,stDay,hrstr,stHr,minstr,stMin,secstr,stSec); |
caseyquinn | 36:2e344db70d35 | 113 | |
caseyquinn | 46:99d129bfdbbd | 114 | |
caseyquinn | 28:42932d3b105d | 115 | //Get Sensor Data except GPS |
caseyquinn | 28:42932d3b105d | 116 | //////////////////////////// |
caseyquinn | 7:29b01d5812ee | 117 | press = bmesensor.getPressure(); |
scottkelleher | 58:3233c10a668c | 118 | temp = bmesensor.getTemperature(); |
caseyquinn | 7:29b01d5812ee | 119 | rh = bmesensor.getHumidity(); |
scottkelleher | 57:1695e252298d | 120 | 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)); |
caseyquinn | 35:e0bdd6389a75 | 121 | |
scottkelleher | 59:4221935a12d8 | 122 | //pc.printf("%f,%f,%f,%f\r\n", temp, press, rh, atmoRho); |
scottkelleher | 59:4221935a12d8 | 123 | |
scottkelleher | 57:1695e252298d | 124 | sharp1LED = 0; |
scottkelleher | 62:d26214c68686 | 125 | wait_us(samplingTime); |
scottkelleher | 62:d26214c68686 | 126 | sharp1 = ads.readADC_SingleEnded(0, 0xC383); // read channel 1 |
scottkelleher | 62:d26214c68686 | 127 | sharpVolt1 = (sharp1*4.096)/(32768*1); |
scottkelleher | 62:d26214c68686 | 128 | wait_us(deltaTime) |
scottkelleher | 62:d26214c68686 | 129 | sharp1LED = 1; |
scottkelleher | 62:d26214c68686 | 130 | wait_us(sleepTime) |
scottkelleher | 62:d26214c68686 | 131 | |
scottkelleher | 57:1695e252298d | 132 | sharp2LED = 0; |
scottkelleher | 62:d26214c68686 | 133 | wait_us(samplingTime); |
scottkelleher | 62:d26214c68686 | 134 | sharp2 = ads.readADC_SingleEnded(1, 0xD383); // read channel 1 |
scottkelleher | 62:d26214c68686 | 135 | sharpVolt2 = (sharp2*4.096)/(32768*1); |
scottkelleher | 62:d26214c68686 | 136 | wait_us(deltaTime) |
scottkelleher | 62:d26214c68686 | 137 | sharp2LED = 1; |
scottkelleher | 62:d26214c68686 | 138 | wait_us(sleepTime) |
scottkelleher | 62:d26214c68686 | 139 | |
scottkelleher | 57:1695e252298d | 140 | sharp3LED = 0; |
scottkelleher | 62:d26214c68686 | 141 | wait_us(samplingTime); |
scottkelleher | 62:d26214c68686 | 142 | sharp3 = ads.readADC_SingleEnded(2, 0xE383); // read channel 1 |
scottkelleher | 62:d26214c68686 | 143 | sharpVolt3 = (sharp3*4.096)/(32768*1); |
scottkelleher | 62:d26214c68686 | 144 | wait_us(deltaTime) |
scottkelleher | 62:d26214c68686 | 145 | sharp3LED = 1; |
scottkelleher | 62:d26214c68686 | 146 | wait_us(sleepTime) |
scottkelleher | 62:d26214c68686 | 147 | |
scottkelleher | 57:1695e252298d | 148 | sharp4LED = 0; |
scottkelleher | 62:d26214c68686 | 149 | wait_us(samplingTime); |
scottkelleher | 62:d26214c68686 | 150 | sharp4 = ads.readADC_SingleEnded(3, 0xF383); // read channel 1 |
scottkelleher | 62:d26214c68686 | 151 | sharpVolt4 = (sharp4*4.096)/(32768*1); |
scottkelleher | 62:d26214c68686 | 152 | wait_us(deltaTime) |
scottkelleher | 62:d26214c68686 | 153 | sharp4LED = 1; |
scottkelleher | 62:d26214c68686 | 154 | wait_us(sleepTime) |
scottkelleher | 62:d26214c68686 | 155 | |
scottkelleher | 59:4221935a12d8 | 156 | sharp5LED = 0; |
scottkelleher | 62:d26214c68686 | 157 | wait_us(samplingTime); |
scottkelleher | 62:d26214c68686 | 158 | sharp5 = ads2.readADC_SingleEnded(0, 0xC383); // read channel 1 |
scottkelleher | 62:d26214c68686 | 159 | sharpVolt5 = (sharp5*4.096)/(32768*1); |
scottkelleher | 62:d26214c68686 | 160 | wait_us(deltaTime) |
scottkelleher | 62:d26214c68686 | 161 | sharp5LED = 1; |
scottkelleher | 62:d26214c68686 | 162 | wait_us(sleepTime) |
scottkelleher | 62:d26214c68686 | 163 | |
scottkelleher | 59:4221935a12d8 | 164 | sharp6LED = 0; |
scottkelleher | 59:4221935a12d8 | 165 | wait_us(samplingTime); |
scottkelleher | 62:d26214c68686 | 166 | sharp6 = ads2.readADC_SingleEnded(0, 0xD383); // read channel 1 |
scottkelleher | 62:d26214c68686 | 167 | sharpVolt6 = (sharp6*4.096)/(32768*1); |
scottkelleher | 62:d26214c68686 | 168 | wait_us(deltaTime) |
scottkelleher | 62:d26214c68686 | 169 | sharp6LED = 1; |
scottkelleher | 62:d26214c68686 | 170 | wait_us(sleepTime) |
scottkelleher | 62:d26214c68686 | 171 | |
caseyquinn | 14:7cdb643da356 | 172 | |
scottkelleher | 62:d26214c68686 | 173 | /* sharp1 = ads.readADC_SingleEnded(0, 0xC383); // read channel 1 |
scottkelleher | 57:1695e252298d | 174 | sharpVolt1 = (sharp1*4.096)/(32768*1); |
scottkelleher | 57:1695e252298d | 175 | sharp2 = ads.readADC_SingleEnded(1, 0xD383); // read channel 1 |
scottkelleher | 57:1695e252298d | 176 | sharpVolt2 = (sharp2*4.096)/(32768*1); |
scottkelleher | 57:1695e252298d | 177 | sharp3 = ads.readADC_SingleEnded(2, 0xE383); // read channel 1 |
scottkelleher | 57:1695e252298d | 178 | sharpVolt3 = (sharp3*4.096)/(32768*1); |
scottkelleher | 57:1695e252298d | 179 | sharp4 = ads.readADC_SingleEnded(3, 0xF383); // read channel 1 |
scottkelleher | 57:1695e252298d | 180 | sharpVolt4 = (sharp4*4.096)/(32768*1); |
caseyquinn | 50:5f1b378e4f64 | 181 | |
scottkelleher | 61:69ec677bf39f | 182 | sharp5 = ads2.readADC_SingleEnded(2, 0xE383); // read channel 1 |
scottkelleher | 59:4221935a12d8 | 183 | sharpVolt5 = (sharp4*4.096)/(32768*1); |
scottkelleher | 61:69ec677bf39f | 184 | sharp6 = ads2.readADC_SingleEnded(3, 0xf383); // read channel 1 |
scottkelleher | 59:4221935a12d8 | 185 | sharpVolt6 = (sharp4*4.096)/(32768*1); |
scottkelleher | 59:4221935a12d8 | 186 | |
scottkelleher | 59:4221935a12d8 | 187 | wait_us(deltaTime); |
caseyquinn | 50:5f1b378e4f64 | 188 | |
scottkelleher | 57:1695e252298d | 189 | sharp1LED = 1; |
scottkelleher | 57:1695e252298d | 190 | sharp2LED = 1; |
scottkelleher | 57:1695e252298d | 191 | sharp3LED = 1; |
scottkelleher | 57:1695e252298d | 192 | sharp4LED = 1; |
scottkelleher | 59:4221935a12d8 | 193 | sharp5LED = 1; |
scottkelleher | 59:4221935a12d8 | 194 | sharp6LED = 1; |
scottkelleher | 62:d26214c68686 | 195 | */ |
scottkelleher | 61:69ec677bf39f | 196 | |
scottkelleher | 61:69ec677bf39f | 197 | pc.printf("%2.2f,%4.2f,%2.1f,%1.3f,", temp,press,rh,atmoRho); |
scottkelleher | 61:69ec677bf39f | 198 | pc.printf("%d,%d,%d,%d,",sharp1,sharp2,sharp3,sharp4); |
scottkelleher | 61:69ec677bf39f | 199 | pc.printf("%d,%d,",sharp5,sharp6); |
scottkelleher | 61:69ec677bf39f | 200 | pc.printf("%f,%f,%f,%f,",sharpVolt1,sharpVolt2,sharpVolt3,sharpVolt4); |
scottkelleher | 61:69ec677bf39f | 201 | pc.printf("%f,%f\r\n",sharpVolt5,sharpVolt6); |
scottkelleher | 61:69ec677bf39f | 202 | |
scottkelleher | 61:69ec677bf39f | 203 | //pc.printf("%d,%d,%d,%d,%d,%d\r\n", sharp1, sharp2, sharp3, sharp4, sharp5, sharp6); |
scottkelleher | 61:69ec677bf39f | 204 | //pc.printf("%d,%f,%d,%f,\r\n" ,sharp5,sharpVolt5, sharp6, sharpVolt6); |
scottkelleher | 59:4221935a12d8 | 205 | //pc.printf("%d,%f,%d,%f,%d,%f,%d,%f\r\n" ,sharp1,sharpVolt1, sharp2, sharpVolt2,sharp3,sharpVolt3, sharp4, sharpVolt4); |
scottkelleher | 59:4221935a12d8 | 206 | //pc.printf("%2.2f,%4.2f,%2.1f,%1.3f\r\n", temp,press,rh,atmoRho); |
scottkelleher | 59:4221935a12d8 | 207 | //pc.printf("%d,%f,%d,%f\r\n" ,sharp3,sharpVolt3, sharp4, sharpVolt4); |
caseyquinn | 27:922f53fa649c | 208 | |
caseyquinn | 7:29b01d5812ee | 209 | FILE *fp = fopen(filename, "a"); |
scottkelleher | 59:4221935a12d8 | 210 | // 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); |
scottkelleher | 59:4221935a12d8 | 211 | //fprintf(fp, "%s,", timestr); |
scottkelleher | 61:69ec677bf39f | 212 | |
scottkelleher | 61:69ec677bf39f | 213 | |
scottkelleher | 61:69ec677bf39f | 214 | fprintf(fp, "%2.2f,%4.2f,%2.1f,%1.3f," ,temp,press,rh,atmoRho); |
scottkelleher | 61:69ec677bf39f | 215 | fprintf(fp, "%d,%d,%d,%d,",sharp1,sharp2,sharp3,sharp4); |
scottkelleher | 61:69ec677bf39f | 216 | fprintf(fp, "%d,%d,",sharp5,sharp6); |
scottkelleher | 61:69ec677bf39f | 217 | fprintf(fp, "%f,%f,%f,%f,",sharpVolt1,sharpVolt2,sharpVolt3,sharpVolt4); |
scottkelleher | 61:69ec677bf39f | 218 | fprintf(fp, "%f,%f\r\n",sharpVolt5,sharpVolt6); |
scottkelleher | 61:69ec677bf39f | 219 | |
scottkelleher | 57:1695e252298d | 220 | fclose(fp); |
caseyquinn | 7:29b01d5812ee | 221 | free(fp); |
scottkelleher | 61:69ec677bf39f | 222 | /*fprintf(fp, "%2.2f,%4.2f,%2.1f,%1.3f", temp,press,rh,atmoRho); |
scottkelleher | 61:69ec677bf39f | 223 | fprintf(fp, "%d,%f,%d,%f,",sharp1, sharpVolt1, sharp2, sharpVolt2); |
scottkelleher | 61:69ec677bf39f | 224 | fprintf(fp, "%d,%f,%d,%f",sharp3,sharpVolt3, sharp4, sharpVolt4); |
scottkelleher | 61:69ec677bf39f | 225 | fprintf(fp, "%d,%f,%d,%f",sharp5, sharpVolt5, sharp6, sharpVolt6); |
caseyquinn | 25:fbf7d44e7da4 | 226 | |
scottkelleher | 61:69ec677bf39f | 227 | fclose(fp); |
scottkelleher | 61:69ec677bf39f | 228 | free(fp); |
scottkelleher | 61:69ec677bf39f | 229 | */ |
caseyquinn | 25:fbf7d44e7da4 | 230 | |
caseyquinn | 14:7cdb643da356 | 231 | |
caseyquinn | 12:5b4f3245606a | 232 | |
caseyquinn | 25:fbf7d44e7da4 | 233 | |
caseyquinn | 12:5b4f3245606a | 234 | |
jelord | 3:122bfc998c4c | 235 | } |
caseyquinn | 8:c4a8f9b67cee | 236 | |
caseyquinn | 25:fbf7d44e7da4 | 237 | |
scottkelleher | 61:69ec677bf39f | 238 | |
scottkelleher | 61:69ec677bf39f | 239 | |
scottkelleher | 61:69ec677bf39f | 240 | |
scottkelleher | 61:69ec677bf39f | 241 | |
scottkelleher | 61:69ec677bf39f | 242 | |
scottkelleher | 61:69ec677bf39f | 243 | |
scottkelleher | 61:69ec677bf39f | 244 | |
scottkelleher | 61:69ec677bf39f | 245 | |
scottkelleher | 61:69ec677bf39f | 246 | |
scottkelleher | 61:69ec677bf39f | 247 | |
scottkelleher | 61:69ec677bf39f | 248 | |
scottkelleher | 61:69ec677bf39f | 249 | |
scottkelleher | 61:69ec677bf39f | 250 | |
scottkelleher | 61:69ec677bf39f | 251 | |
scottkelleher | 61:69ec677bf39f | 252 | |
scottkelleher | 61:69ec677bf39f | 253 | |
scottkelleher | 61:69ec677bf39f | 254 | |
scottkelleher | 61:69ec677bf39f | 255 | |
scottkelleher | 61:69ec677bf39f | 256 | |
scottkelleher | 61:69ec677bf39f | 257 | |
scottkelleher | 61:69ec677bf39f | 258 | |
scottkelleher | 61:69ec677bf39f | 259 | |
scottkelleher | 61:69ec677bf39f | 260 | |
caseyquinn | 9:8646fd501832 | 261 | ////////////////////////////////////////////////////////////// |
caseyquinn | 9:8646fd501832 | 262 | //Main Function |
caseyquinn | 9:8646fd501832 | 263 | ////////////////////////////////////////////////////////////// |
jelord | 1:9fbb5b665068 | 264 | int main(){ |
caseyquinn | 27:922f53fa649c | 265 | |
caseyquinn | 29:fd74725294d5 | 266 | |
scottkelleher | 57:1695e252298d | 267 | |
caseyquinn | 10:06fbb1c9e3bd | 268 | pc.baud(115200); // set what you want here depending on your terminal program speed |
caseyquinn | 10:06fbb1c9e3bd | 269 | pc.printf("\f\n\r-------------Startup-------------\n\r"); |
jelord | 1:9fbb5b665068 | 270 | wait(0.5); |
caseyquinn | 5:c3252e5d45ca | 271 | |
caseyquinn | 36:2e344db70d35 | 272 | |
scottkelleher | 57:1695e252298d | 273 | RTC_UPAS.set_time(0,0,0,1,1,1,16);//sets chronodot RTC |
caseyquinn | 29:fd74725294d5 | 274 | |
scottkelleher | 57:1695e252298d | 275 | /////////////////////// |
scottkelleher | 57:1695e252298d | 276 | //sets ST RTC |
scottkelleher | 57:1695e252298d | 277 | ////////////////////// |
scottkelleher | 57:1695e252298d | 278 | STtime.tm_sec = 0; // 0-59 |
scottkelleher | 57:1695e252298d | 279 | STtime.tm_min = 0; // 0-59 |
scottkelleher | 57:1695e252298d | 280 | STtime.tm_hour = 0; // 0-23 |
scottkelleher | 57:1695e252298d | 281 | STtime.tm_mday = 1; // 1-31 |
scottkelleher | 57:1695e252298d | 282 | STtime.tm_mon = 0; // 0-11 |
scottkelleher | 57:1695e252298d | 283 | STtime.tm_year = 116; // year since 1900 (116 = 2016) |
scottkelleher | 57:1695e252298d | 284 | time_t STseconds = mktime(&STtime); |
scottkelleher | 57:1695e252298d | 285 | set_time(STseconds); // Set RTC time |
caseyquinn | 29:fd74725294d5 | 286 | |
scottkelleher | 57:1695e252298d | 287 | |
caseyquinn | 52:95949e34b1f6 | 288 | RTC_UPAS.get_time(); |
caseyquinn | 46:99d129bfdbbd | 289 | |
caseyquinn | 52:95949e34b1f6 | 290 | |
caseyquinn | 43:05aa1fb68946 | 291 | time_t seconds = time(NULL); |
caseyquinn | 43:05aa1fb68946 | 292 | strftime(timestr, 32, "%y-%m-%d-%H=%M=%S", localtime(&seconds)); |
caseyquinn | 52:95949e34b1f6 | 293 | |
caseyquinn | 52:95949e34b1f6 | 294 | strftime(yrstr, 4, "%y", localtime(&seconds)); |
caseyquinn | 52:95949e34b1f6 | 295 | stYr = atoi(yrstr); |
caseyquinn | 52:95949e34b1f6 | 296 | |
caseyquinn | 52:95949e34b1f6 | 297 | strftime(mostr, 4, "%m", localtime(&seconds)); |
caseyquinn | 52:95949e34b1f6 | 298 | stMo = atoi(mostr); |
caseyquinn | 52:95949e34b1f6 | 299 | |
caseyquinn | 52:95949e34b1f6 | 300 | strftime(daystr, 4, "%d", localtime(&seconds)); |
caseyquinn | 52:95949e34b1f6 | 301 | stDay = atoi(daystr); |
caseyquinn | 52:95949e34b1f6 | 302 | |
caseyquinn | 52:95949e34b1f6 | 303 | strftime(hrstr, 4, "%H", localtime(&seconds)); |
caseyquinn | 52:95949e34b1f6 | 304 | stHr = atoi(hrstr); |
caseyquinn | 52:95949e34b1f6 | 305 | |
caseyquinn | 52:95949e34b1f6 | 306 | strftime(minstr, 4, "%M", localtime(&seconds)); |
caseyquinn | 52:95949e34b1f6 | 307 | stMin = atoi(minstr); |
caseyquinn | 52:95949e34b1f6 | 308 | |
caseyquinn | 52:95949e34b1f6 | 309 | strftime(secstr, 4, "%S", localtime(&seconds)); |
caseyquinn | 52:95949e34b1f6 | 310 | stSec = atoi(secstr); |
caseyquinn | 52:95949e34b1f6 | 311 | |
caseyquinn | 52:95949e34b1f6 | 312 | |
caseyquinn | 52:95949e34b1f6 | 313 | |
caseyquinn | 52:95949e34b1f6 | 314 | |
scottkelleher | 57:1695e252298d | 315 | // sprintf(filename,"/sd/SHARP_LOG00.txt"); |
scottkelleher | 57:1695e252298d | 316 | |
scottkelleher | 57:1695e252298d | 317 | for (uint8_t i = 0; i < 100; i++) { |
scottkelleher | 57:1695e252298d | 318 | filename[13] = i/10 + '0'; |
scottkelleher | 57:1695e252298d | 319 | filename[14] = i%10 + '0'; |
scottkelleher | 57:1695e252298d | 320 | FILE *fp = fopen(filename, "r"); |
scottkelleher | 57:1695e252298d | 321 | if (fp == NULL) { |
scottkelleher | 57:1695e252298d | 322 | // only open a new file if it doesn't exist |
scottkelleher | 57:1695e252298d | 323 | FILE *fp = fopen(filename, "w"); |
scottkelleher | 57:1695e252298d | 324 | fclose(fp); |
scottkelleher | 57:1695e252298d | 325 | break; // leave the loop! |
scottkelleher | 57:1695e252298d | 326 | } |
scottkelleher | 57:1695e252298d | 327 | } |
caseyquinn | 36:2e344db70d35 | 328 | |
caseyquinn | 29:fd74725294d5 | 329 | |
caseyquinn | 14:7cdb643da356 | 330 | |
caseyquinn | 46:99d129bfdbbd | 331 | while(fmod((double)stSec,10)!=0) { |
caseyquinn | 46:99d129bfdbbd | 332 | //pc.printf("%f, %f\r\n", floor(secondsD), floor(lastsecondD)); |
caseyquinn | 46:99d129bfdbbd | 333 | time_t seconds = time(NULL); |
caseyquinn | 46:99d129bfdbbd | 334 | strftime(secstr, 4, "%S", localtime(&seconds)); |
caseyquinn | 46:99d129bfdbbd | 335 | stSec = atoi(secstr); |
caseyquinn | 46:99d129bfdbbd | 336 | wait_ms(100); |
caseyquinn | 46:99d129bfdbbd | 337 | } |
caseyquinn | 46:99d129bfdbbd | 338 | |
scottkelleher | 59:4221935a12d8 | 339 | logg.attach(&log_data, 3); |
scottkelleher | 57:1695e252298d | 340 | |
caseyquinn | 35:e0bdd6389a75 | 341 | |
caseyquinn | 35:e0bdd6389a75 | 342 | |
caseyquinn | 30:aa6324845a84 | 343 | |
jelord | 3:122bfc998c4c | 344 | //** end of initalization **// |
jelord | 3:122bfc998c4c | 345 | //---------------------------------------------------------------------------------------------// |
jelord | 3:122bfc998c4c | 346 | //---------------------------------------------------------------------------------------------// |
jelord | 3:122bfc998c4c | 347 | // Main Control Loop |
jelord | 3:122bfc998c4c | 348 | |
caseyquinn | 7:29b01d5812ee | 349 | while (1) { |
caseyquinn | 7:29b01d5812ee | 350 | // Do other things... |
caseyquinn | 46:99d129bfdbbd | 351 | |
caseyquinn | 46:99d129bfdbbd | 352 | } |
caseyquinn | 7:29b01d5812ee | 353 | |
caseyquinn | 8:c4a8f9b67cee | 354 | |
caseyquinn | 4:5d004fd997d5 | 355 | |
jelord | 3:122bfc998c4c | 356 | |
jelord | 0:2cb2b2ea316f | 357 | } |