Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADS1115 BME280 CronoDot SDFileSystem mbed
Fork of Outdoor_UPAS_v1_2_powerfunction by
main.cpp@61:69ec677bf39f, 2016-05-25 (annotated)
- Committer:
- scottkelleher
- Date:
- Wed May 25 19:58:03 2016 +0000
- Revision:
- 61:69ec677bf39f
- Parent:
- 59:4221935a12d8
- Child:
- 62:d26214c68686
working version 1.0
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 | 59:4221935a12d8 | 76 | int sharp1, sharp2, sharp3, sharp4, sharp5, sharp6; |
| scottkelleher | 59:4221935a12d8 | 77 | float sharpVolt1, sharpVolt2, sharpVolt3, sharpVolt4, sharpVolt5, sharpVolt6; //V |
| caseyquinn | 12:5b4f3245606a | 78 | |
| caseyquinn | 11:aa21628a9b15 | 79 | |
| caseyquinn | 11:aa21628a9b15 | 80 | |
| caseyquinn | 5:c3252e5d45ca | 81 | |
| caseyquinn | 9:8646fd501832 | 82 | ////////////////////////////////////////////////////////////// |
| scottkelleher | 57:1695e252298d | 83 | //SD Logging Function |
| caseyquinn | 9:8646fd501832 | 84 | ////////////////////////////////////////////////////////////// |
| scottkelleher | 57:1695e252298d | 85 | void log_data() |
| caseyquinn | 52:95949e34b1f6 | 86 | { |
| scottkelleher | 57:1695e252298d | 87 | //Get RTC time(s) |
| scottkelleher | 57:1695e252298d | 88 | /////////////////////////// |
| scottkelleher | 57:1695e252298d | 89 | RTC_UPAS.get_time(); |
| scottkelleher | 57:1695e252298d | 90 | time_t seconds = time(NULL); |
| scottkelleher | 57:1695e252298d | 91 | strftime(timestr, 32, "%y%m%d%H%M%S", localtime(&seconds)); |
| scottkelleher | 57:1695e252298d | 92 | /* |
| caseyquinn | 43:05aa1fb68946 | 93 | strftime(yrstr, 4, "%y", localtime(&seconds)); |
| caseyquinn | 43:05aa1fb68946 | 94 | stYr = atoi(yrstr); |
| caseyquinn | 43:05aa1fb68946 | 95 | |
| caseyquinn | 43:05aa1fb68946 | 96 | strftime(mostr, 4, "%m", localtime(&seconds)); |
| caseyquinn | 43:05aa1fb68946 | 97 | stMo = atoi(mostr); |
| caseyquinn | 43:05aa1fb68946 | 98 | |
| caseyquinn | 43:05aa1fb68946 | 99 | strftime(daystr, 4, "%d", localtime(&seconds)); |
| caseyquinn | 43:05aa1fb68946 | 100 | stDay = atoi(daystr); |
| caseyquinn | 43:05aa1fb68946 | 101 | |
| caseyquinn | 43:05aa1fb68946 | 102 | strftime(hrstr, 4, "%H", localtime(&seconds)); |
| caseyquinn | 43:05aa1fb68946 | 103 | stHr = atoi(hrstr); |
| caseyquinn | 43:05aa1fb68946 | 104 | |
| caseyquinn | 43:05aa1fb68946 | 105 | strftime(minstr, 4, "%M", localtime(&seconds)); |
| caseyquinn | 43:05aa1fb68946 | 106 | stMin = atoi(minstr); |
| caseyquinn | 43:05aa1fb68946 | 107 | |
| caseyquinn | 43:05aa1fb68946 | 108 | strftime(secstr, 4, "%S", localtime(&seconds)); |
| caseyquinn | 43:05aa1fb68946 | 109 | stSec = atoi(secstr); |
| scottkelleher | 57:1695e252298d | 110 | */ |
| caseyquinn | 44:075fa63d5df1 | 111 | //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 | 112 | |
| caseyquinn | 46:99d129bfdbbd | 113 | |
| caseyquinn | 28:42932d3b105d | 114 | //Get Sensor Data except GPS |
| caseyquinn | 28:42932d3b105d | 115 | //////////////////////////// |
| caseyquinn | 7:29b01d5812ee | 116 | press = bmesensor.getPressure(); |
| scottkelleher | 58:3233c10a668c | 117 | temp = bmesensor.getTemperature(); |
| caseyquinn | 7:29b01d5812ee | 118 | rh = bmesensor.getHumidity(); |
| scottkelleher | 57:1695e252298d | 119 | 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 | 120 | |
| scottkelleher | 59:4221935a12d8 | 121 | //pc.printf("%f,%f,%f,%f\r\n", temp, press, rh, atmoRho); |
| scottkelleher | 59:4221935a12d8 | 122 | |
| scottkelleher | 57:1695e252298d | 123 | sharp1LED = 0; |
| scottkelleher | 57:1695e252298d | 124 | sharp2LED = 0; |
| scottkelleher | 57:1695e252298d | 125 | sharp3LED = 0; |
| scottkelleher | 57:1695e252298d | 126 | sharp4LED = 0; |
| scottkelleher | 59:4221935a12d8 | 127 | sharp5LED = 0; |
| scottkelleher | 59:4221935a12d8 | 128 | sharp6LED = 0; |
| scottkelleher | 59:4221935a12d8 | 129 | |
| scottkelleher | 59:4221935a12d8 | 130 | wait_us(samplingTime); |
| caseyquinn | 14:7cdb643da356 | 131 | |
| scottkelleher | 57:1695e252298d | 132 | sharp1 = ads.readADC_SingleEnded(0, 0xC383); // read channel 1 |
| scottkelleher | 57:1695e252298d | 133 | sharpVolt1 = (sharp1*4.096)/(32768*1); |
| scottkelleher | 57:1695e252298d | 134 | sharp2 = ads.readADC_SingleEnded(1, 0xD383); // read channel 1 |
| scottkelleher | 57:1695e252298d | 135 | sharpVolt2 = (sharp2*4.096)/(32768*1); |
| scottkelleher | 57:1695e252298d | 136 | sharp3 = ads.readADC_SingleEnded(2, 0xE383); // read channel 1 |
| scottkelleher | 57:1695e252298d | 137 | sharpVolt3 = (sharp3*4.096)/(32768*1); |
| scottkelleher | 57:1695e252298d | 138 | sharp4 = ads.readADC_SingleEnded(3, 0xF383); // read channel 1 |
| scottkelleher | 57:1695e252298d | 139 | sharpVolt4 = (sharp4*4.096)/(32768*1); |
| caseyquinn | 50:5f1b378e4f64 | 140 | |
| scottkelleher | 61:69ec677bf39f | 141 | sharp5 = ads2.readADC_SingleEnded(2, 0xE383); // read channel 1 |
| scottkelleher | 59:4221935a12d8 | 142 | sharpVolt5 = (sharp4*4.096)/(32768*1); |
| scottkelleher | 61:69ec677bf39f | 143 | sharp6 = ads2.readADC_SingleEnded(3, 0xf383); // read channel 1 |
| scottkelleher | 59:4221935a12d8 | 144 | sharpVolt6 = (sharp4*4.096)/(32768*1); |
| scottkelleher | 59:4221935a12d8 | 145 | |
| scottkelleher | 59:4221935a12d8 | 146 | wait_us(deltaTime); |
| caseyquinn | 50:5f1b378e4f64 | 147 | |
| scottkelleher | 57:1695e252298d | 148 | sharp1LED = 1; |
| scottkelleher | 57:1695e252298d | 149 | sharp2LED = 1; |
| scottkelleher | 57:1695e252298d | 150 | sharp3LED = 1; |
| scottkelleher | 57:1695e252298d | 151 | sharp4LED = 1; |
| scottkelleher | 59:4221935a12d8 | 152 | sharp5LED = 1; |
| scottkelleher | 59:4221935a12d8 | 153 | sharp6LED = 1; |
| caseyquinn | 14:7cdb643da356 | 154 | |
| scottkelleher | 61:69ec677bf39f | 155 | |
| scottkelleher | 61:69ec677bf39f | 156 | pc.printf("%2.2f,%4.2f,%2.1f,%1.3f,", temp,press,rh,atmoRho); |
| scottkelleher | 61:69ec677bf39f | 157 | pc.printf("%d,%d,%d,%d,",sharp1,sharp2,sharp3,sharp4); |
| scottkelleher | 61:69ec677bf39f | 158 | pc.printf("%d,%d,",sharp5,sharp6); |
| scottkelleher | 61:69ec677bf39f | 159 | pc.printf("%f,%f,%f,%f,",sharpVolt1,sharpVolt2,sharpVolt3,sharpVolt4); |
| scottkelleher | 61:69ec677bf39f | 160 | pc.printf("%f,%f\r\n",sharpVolt5,sharpVolt6); |
| scottkelleher | 61:69ec677bf39f | 161 | |
| scottkelleher | 61:69ec677bf39f | 162 | //pc.printf("%d,%d,%d,%d,%d,%d\r\n", sharp1, sharp2, sharp3, sharp4, sharp5, sharp6); |
| scottkelleher | 61:69ec677bf39f | 163 | //pc.printf("%d,%f,%d,%f,\r\n" ,sharp5,sharpVolt5, sharp6, sharpVolt6); |
| scottkelleher | 59:4221935a12d8 | 164 | //pc.printf("%d,%f,%d,%f,%d,%f,%d,%f\r\n" ,sharp1,sharpVolt1, sharp2, sharpVolt2,sharp3,sharpVolt3, sharp4, sharpVolt4); |
| scottkelleher | 59:4221935a12d8 | 165 | //pc.printf("%2.2f,%4.2f,%2.1f,%1.3f\r\n", temp,press,rh,atmoRho); |
| scottkelleher | 59:4221935a12d8 | 166 | //pc.printf("%d,%f,%d,%f\r\n" ,sharp3,sharpVolt3, sharp4, sharpVolt4); |
| caseyquinn | 27:922f53fa649c | 167 | |
| caseyquinn | 7:29b01d5812ee | 168 | FILE *fp = fopen(filename, "a"); |
| scottkelleher | 59:4221935a12d8 | 169 | // 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 | 170 | //fprintf(fp, "%s,", timestr); |
| scottkelleher | 61:69ec677bf39f | 171 | |
| scottkelleher | 61:69ec677bf39f | 172 | |
| scottkelleher | 61:69ec677bf39f | 173 | fprintf(fp, "%2.2f,%4.2f,%2.1f,%1.3f," ,temp,press,rh,atmoRho); |
| scottkelleher | 61:69ec677bf39f | 174 | fprintf(fp, "%d,%d,%d,%d,",sharp1,sharp2,sharp3,sharp4); |
| scottkelleher | 61:69ec677bf39f | 175 | fprintf(fp, "%d,%d,",sharp5,sharp6); |
| scottkelleher | 61:69ec677bf39f | 176 | fprintf(fp, "%f,%f,%f,%f,",sharpVolt1,sharpVolt2,sharpVolt3,sharpVolt4); |
| scottkelleher | 61:69ec677bf39f | 177 | fprintf(fp, "%f,%f\r\n",sharpVolt5,sharpVolt6); |
| scottkelleher | 61:69ec677bf39f | 178 | |
| scottkelleher | 57:1695e252298d | 179 | fclose(fp); |
| caseyquinn | 7:29b01d5812ee | 180 | free(fp); |
| scottkelleher | 61:69ec677bf39f | 181 | /*fprintf(fp, "%2.2f,%4.2f,%2.1f,%1.3f", temp,press,rh,atmoRho); |
| scottkelleher | 61:69ec677bf39f | 182 | fprintf(fp, "%d,%f,%d,%f,",sharp1, sharpVolt1, sharp2, sharpVolt2); |
| scottkelleher | 61:69ec677bf39f | 183 | fprintf(fp, "%d,%f,%d,%f",sharp3,sharpVolt3, sharp4, sharpVolt4); |
| scottkelleher | 61:69ec677bf39f | 184 | fprintf(fp, "%d,%f,%d,%f",sharp5, sharpVolt5, sharp6, sharpVolt6); |
| caseyquinn | 25:fbf7d44e7da4 | 185 | |
| scottkelleher | 61:69ec677bf39f | 186 | fclose(fp); |
| scottkelleher | 61:69ec677bf39f | 187 | free(fp); |
| scottkelleher | 61:69ec677bf39f | 188 | */ |
| caseyquinn | 25:fbf7d44e7da4 | 189 | |
| caseyquinn | 14:7cdb643da356 | 190 | |
| caseyquinn | 12:5b4f3245606a | 191 | |
| caseyquinn | 25:fbf7d44e7da4 | 192 | |
| caseyquinn | 12:5b4f3245606a | 193 | |
| jelord | 3:122bfc998c4c | 194 | } |
| caseyquinn | 8:c4a8f9b67cee | 195 | |
| caseyquinn | 25:fbf7d44e7da4 | 196 | |
| scottkelleher | 61:69ec677bf39f | 197 | |
| scottkelleher | 61:69ec677bf39f | 198 | |
| scottkelleher | 61:69ec677bf39f | 199 | |
| scottkelleher | 61:69ec677bf39f | 200 | |
| scottkelleher | 61:69ec677bf39f | 201 | |
| scottkelleher | 61:69ec677bf39f | 202 | |
| scottkelleher | 61:69ec677bf39f | 203 | |
| scottkelleher | 61:69ec677bf39f | 204 | |
| scottkelleher | 61:69ec677bf39f | 205 | |
| scottkelleher | 61:69ec677bf39f | 206 | |
| scottkelleher | 61:69ec677bf39f | 207 | |
| scottkelleher | 61:69ec677bf39f | 208 | |
| scottkelleher | 61:69ec677bf39f | 209 | |
| scottkelleher | 61:69ec677bf39f | 210 | |
| scottkelleher | 61:69ec677bf39f | 211 | |
| scottkelleher | 61:69ec677bf39f | 212 | |
| scottkelleher | 61:69ec677bf39f | 213 | |
| scottkelleher | 61:69ec677bf39f | 214 | |
| scottkelleher | 61:69ec677bf39f | 215 | |
| scottkelleher | 61:69ec677bf39f | 216 | |
| scottkelleher | 61:69ec677bf39f | 217 | |
| scottkelleher | 61:69ec677bf39f | 218 | |
| scottkelleher | 61:69ec677bf39f | 219 | |
| caseyquinn | 9:8646fd501832 | 220 | ////////////////////////////////////////////////////////////// |
| caseyquinn | 9:8646fd501832 | 221 | //Main Function |
| caseyquinn | 9:8646fd501832 | 222 | ////////////////////////////////////////////////////////////// |
| jelord | 1:9fbb5b665068 | 223 | int main(){ |
| caseyquinn | 27:922f53fa649c | 224 | |
| caseyquinn | 29:fd74725294d5 | 225 | |
| scottkelleher | 57:1695e252298d | 226 | |
| caseyquinn | 10:06fbb1c9e3bd | 227 | pc.baud(115200); // set what you want here depending on your terminal program speed |
| caseyquinn | 10:06fbb1c9e3bd | 228 | pc.printf("\f\n\r-------------Startup-------------\n\r"); |
| jelord | 1:9fbb5b665068 | 229 | wait(0.5); |
| caseyquinn | 5:c3252e5d45ca | 230 | |
| caseyquinn | 36:2e344db70d35 | 231 | |
| scottkelleher | 57:1695e252298d | 232 | RTC_UPAS.set_time(0,0,0,1,1,1,16);//sets chronodot RTC |
| caseyquinn | 29:fd74725294d5 | 233 | |
| scottkelleher | 57:1695e252298d | 234 | /////////////////////// |
| scottkelleher | 57:1695e252298d | 235 | //sets ST RTC |
| scottkelleher | 57:1695e252298d | 236 | ////////////////////// |
| scottkelleher | 57:1695e252298d | 237 | STtime.tm_sec = 0; // 0-59 |
| scottkelleher | 57:1695e252298d | 238 | STtime.tm_min = 0; // 0-59 |
| scottkelleher | 57:1695e252298d | 239 | STtime.tm_hour = 0; // 0-23 |
| scottkelleher | 57:1695e252298d | 240 | STtime.tm_mday = 1; // 1-31 |
| scottkelleher | 57:1695e252298d | 241 | STtime.tm_mon = 0; // 0-11 |
| scottkelleher | 57:1695e252298d | 242 | STtime.tm_year = 116; // year since 1900 (116 = 2016) |
| scottkelleher | 57:1695e252298d | 243 | time_t STseconds = mktime(&STtime); |
| scottkelleher | 57:1695e252298d | 244 | set_time(STseconds); // Set RTC time |
| caseyquinn | 29:fd74725294d5 | 245 | |
| scottkelleher | 57:1695e252298d | 246 | |
| caseyquinn | 52:95949e34b1f6 | 247 | RTC_UPAS.get_time(); |
| caseyquinn | 46:99d129bfdbbd | 248 | |
| caseyquinn | 52:95949e34b1f6 | 249 | |
| caseyquinn | 43:05aa1fb68946 | 250 | time_t seconds = time(NULL); |
| caseyquinn | 43:05aa1fb68946 | 251 | strftime(timestr, 32, "%y-%m-%d-%H=%M=%S", localtime(&seconds)); |
| caseyquinn | 52:95949e34b1f6 | 252 | |
| caseyquinn | 52:95949e34b1f6 | 253 | strftime(yrstr, 4, "%y", localtime(&seconds)); |
| caseyquinn | 52:95949e34b1f6 | 254 | stYr = atoi(yrstr); |
| caseyquinn | 52:95949e34b1f6 | 255 | |
| caseyquinn | 52:95949e34b1f6 | 256 | strftime(mostr, 4, "%m", localtime(&seconds)); |
| caseyquinn | 52:95949e34b1f6 | 257 | stMo = atoi(mostr); |
| caseyquinn | 52:95949e34b1f6 | 258 | |
| caseyquinn | 52:95949e34b1f6 | 259 | strftime(daystr, 4, "%d", localtime(&seconds)); |
| caseyquinn | 52:95949e34b1f6 | 260 | stDay = atoi(daystr); |
| caseyquinn | 52:95949e34b1f6 | 261 | |
| caseyquinn | 52:95949e34b1f6 | 262 | strftime(hrstr, 4, "%H", localtime(&seconds)); |
| caseyquinn | 52:95949e34b1f6 | 263 | stHr = atoi(hrstr); |
| caseyquinn | 52:95949e34b1f6 | 264 | |
| caseyquinn | 52:95949e34b1f6 | 265 | strftime(minstr, 4, "%M", localtime(&seconds)); |
| caseyquinn | 52:95949e34b1f6 | 266 | stMin = atoi(minstr); |
| caseyquinn | 52:95949e34b1f6 | 267 | |
| caseyquinn | 52:95949e34b1f6 | 268 | strftime(secstr, 4, "%S", localtime(&seconds)); |
| caseyquinn | 52:95949e34b1f6 | 269 | stSec = atoi(secstr); |
| caseyquinn | 52:95949e34b1f6 | 270 | |
| caseyquinn | 52:95949e34b1f6 | 271 | |
| caseyquinn | 52:95949e34b1f6 | 272 | |
| caseyquinn | 52:95949e34b1f6 | 273 | |
| scottkelleher | 57:1695e252298d | 274 | // sprintf(filename,"/sd/SHARP_LOG00.txt"); |
| scottkelleher | 57:1695e252298d | 275 | |
| scottkelleher | 57:1695e252298d | 276 | for (uint8_t i = 0; i < 100; i++) { |
| scottkelleher | 57:1695e252298d | 277 | filename[13] = i/10 + '0'; |
| scottkelleher | 57:1695e252298d | 278 | filename[14] = i%10 + '0'; |
| scottkelleher | 57:1695e252298d | 279 | FILE *fp = fopen(filename, "r"); |
| scottkelleher | 57:1695e252298d | 280 | if (fp == NULL) { |
| scottkelleher | 57:1695e252298d | 281 | // only open a new file if it doesn't exist |
| scottkelleher | 57:1695e252298d | 282 | FILE *fp = fopen(filename, "w"); |
| scottkelleher | 57:1695e252298d | 283 | fclose(fp); |
| scottkelleher | 57:1695e252298d | 284 | break; // leave the loop! |
| scottkelleher | 57:1695e252298d | 285 | } |
| scottkelleher | 57:1695e252298d | 286 | } |
| caseyquinn | 36:2e344db70d35 | 287 | |
| caseyquinn | 29:fd74725294d5 | 288 | |
| caseyquinn | 14:7cdb643da356 | 289 | |
| caseyquinn | 46:99d129bfdbbd | 290 | while(fmod((double)stSec,10)!=0) { |
| caseyquinn | 46:99d129bfdbbd | 291 | //pc.printf("%f, %f\r\n", floor(secondsD), floor(lastsecondD)); |
| caseyquinn | 46:99d129bfdbbd | 292 | time_t seconds = time(NULL); |
| caseyquinn | 46:99d129bfdbbd | 293 | strftime(secstr, 4, "%S", localtime(&seconds)); |
| caseyquinn | 46:99d129bfdbbd | 294 | stSec = atoi(secstr); |
| caseyquinn | 46:99d129bfdbbd | 295 | wait_ms(100); |
| caseyquinn | 46:99d129bfdbbd | 296 | } |
| caseyquinn | 46:99d129bfdbbd | 297 | |
| scottkelleher | 59:4221935a12d8 | 298 | logg.attach(&log_data, 3); |
| scottkelleher | 57:1695e252298d | 299 | |
| caseyquinn | 35:e0bdd6389a75 | 300 | |
| caseyquinn | 35:e0bdd6389a75 | 301 | |
| caseyquinn | 30:aa6324845a84 | 302 | |
| jelord | 3:122bfc998c4c | 303 | //** end of initalization **// |
| jelord | 3:122bfc998c4c | 304 | //---------------------------------------------------------------------------------------------// |
| jelord | 3:122bfc998c4c | 305 | //---------------------------------------------------------------------------------------------// |
| jelord | 3:122bfc998c4c | 306 | // Main Control Loop |
| jelord | 3:122bfc998c4c | 307 | |
| caseyquinn | 7:29b01d5812ee | 308 | while (1) { |
| caseyquinn | 7:29b01d5812ee | 309 | // Do other things... |
| caseyquinn | 46:99d129bfdbbd | 310 | |
| caseyquinn | 46:99d129bfdbbd | 311 | } |
| caseyquinn | 7:29b01d5812ee | 312 | |
| caseyquinn | 8:c4a8f9b67cee | 313 | |
| caseyquinn | 4:5d004fd997d5 | 314 | |
| jelord | 3:122bfc998c4c | 315 | |
| jelord | 0:2cb2b2ea316f | 316 | } |
