
aaa
Fork of 0NicksCoursework-lg by
Components/components.cpp@8:582ac4c5a524, 2018-01-09 (annotated)
- Committer:
- liam_grazier
- Date:
- Tue Jan 09 05:43:43 2018 +0000
- Revision:
- 8:582ac4c5a524
- Child:
- 9:e27b3f34de24
dfshjsdfjhdf;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
liam_grazier | 8:582ac4c5a524 | 1 | #include "mbed.h" |
liam_grazier | 8:582ac4c5a524 | 2 | #include "components.hpp" |
liam_grazier | 8:582ac4c5a524 | 3 | #include "lglcd.h" |
liam_grazier | 8:582ac4c5a524 | 4 | #include "time.h" |
liam_grazier | 8:582ac4c5a524 | 5 | #include "stdio.h" |
liam_grazier | 8:582ac4c5a524 | 6 | #define RED_DONE 1 |
liam_grazier | 8:582ac4c5a524 | 7 | #define YELLOW_DONE 2 |
liam_grazier | 8:582ac4c5a524 | 8 | //Digital outputs |
liam_grazier | 8:582ac4c5a524 | 9 | DigitalIn onBoardSwitch(USER_BUTTON); |
liam_grazier | 8:582ac4c5a524 | 10 | DigitalOut onBoardLED(LED1); |
liam_grazier | 8:582ac4c5a524 | 11 | DigitalOut redLED(PE_15); |
liam_grazier | 8:582ac4c5a524 | 12 | DigitalOut yellowLED(PB_10); |
liam_grazier | 8:582ac4c5a524 | 13 | DigitalOut greenLED(PB_11); |
liam_grazier | 8:582ac4c5a524 | 14 | SDBlockDevice sd(PB_5, D12, D13, D10);// miso, sclk, cs |
liam_grazier | 8:582ac4c5a524 | 15 | Mutex Lock1; |
liam_grazier | 8:582ac4c5a524 | 16 | Mutex Lock2; |
liam_grazier | 8:582ac4c5a524 | 17 | Mutex Remove; |
liam_grazier | 8:582ac4c5a524 | 18 | //Inputs |
liam_grazier | 8:582ac4c5a524 | 19 | time_t rawtime; |
liam_grazier | 8:582ac4c5a524 | 20 | struct tm * timeinfo; |
liam_grazier | 8:582ac4c5a524 | 21 | int year, month ,day, hour, minute, second; |
liam_grazier | 8:582ac4c5a524 | 22 | char input = 0; |
liam_grazier | 8:582ac4c5a524 | 23 | char jtime[32]; |
liam_grazier | 8:582ac4c5a524 | 24 | char jdate[32]; |
liam_grazier | 8:582ac4c5a524 | 25 | char jdate1[32]; |
liam_grazier | 8:582ac4c5a524 | 26 | DigitalIn SW1(PE_12); |
liam_grazier | 8:582ac4c5a524 | 27 | DigitalIn SW2(PE_14); |
liam_grazier | 8:582ac4c5a524 | 28 | //Serial pc(USBTX, USBRX); |
liam_grazier | 8:582ac4c5a524 | 29 | AnalogIn adcIn(PA_0); |
liam_grazier | 8:582ac4c5a524 | 30 | //Environmental Sensor driver |
liam_grazier | 8:582ac4c5a524 | 31 | #ifdef BME |
liam_grazier | 8:582ac4c5a524 | 32 | BME280 sensor(D14, D15); |
liam_grazier | 8:582ac4c5a524 | 33 | #else |
liam_grazier | 8:582ac4c5a524 | 34 | BMP280 sensor(D14, D15); |
liam_grazier | 8:582ac4c5a524 | 35 | #endif |
liam_grazier | 8:582ac4c5a524 | 36 | lglcd mylcd(D7,D6,D5,D4,D3,D2); |
liam_grazier | 8:582ac4c5a524 | 37 | |
liam_grazier | 8:582ac4c5a524 | 38 | //POWER ON SELF TEST |
liam_grazier | 8:582ac4c5a524 | 39 | void post() |
liam_grazier | 8:582ac4c5a524 | 40 | { |
liam_grazier | 8:582ac4c5a524 | 41 | //posttest |
liam_grazier | 8:582ac4c5a524 | 42 | } |
liam_grazier | 8:582ac4c5a524 | 43 | void runanalysis(void){ |
liam_grazier | 8:582ac4c5a524 | 44 | while(1){ |
liam_grazier | 8:582ac4c5a524 | 45 | Lock1.lock(); |
liam_grazier | 8:582ac4c5a524 | 46 | double temp = sensor.getTemperature(); |
liam_grazier | 8:582ac4c5a524 | 47 | double pressure = sensor.getPressure(); |
liam_grazier | 8:582ac4c5a524 | 48 | double lightin = adcIn; |
liam_grazier | 8:582ac4c5a524 | 49 | char TEM[6]; |
liam_grazier | 8:582ac4c5a524 | 50 | char PRE[5]; |
liam_grazier | 8:582ac4c5a524 | 51 | char LIGHT[6]; |
liam_grazier | 8:582ac4c5a524 | 52 | //printf("REFRESH SENSORS\n\r"); |
liam_grazier | 8:582ac4c5a524 | 53 | sprintf(TEM,"%.2f", temp); |
liam_grazier | 8:582ac4c5a524 | 54 | sprintf(PRE,"%.2f", pressure); |
liam_grazier | 8:582ac4c5a524 | 55 | sprintf(LIGHT,"%.2f", lightin); |
liam_grazier | 8:582ac4c5a524 | 56 | mylcd.setline(1,1); |
liam_grazier | 8:582ac4c5a524 | 57 | mylcd.write("L:"); |
liam_grazier | 8:582ac4c5a524 | 58 | if(lightin > 0.7 && lightin < 0.9) |
liam_grazier | 8:582ac4c5a524 | 59 | { |
liam_grazier | 8:582ac4c5a524 | 60 | mylcd.setline(1,4); |
liam_grazier | 8:582ac4c5a524 | 61 | mylcd.write("|||||||||MAX"); |
liam_grazier | 8:582ac4c5a524 | 62 | } |
liam_grazier | 8:582ac4c5a524 | 63 | else if(lightin > 0.55 && lightin < 0.69) |
liam_grazier | 8:582ac4c5a524 | 64 | { |
liam_grazier | 8:582ac4c5a524 | 65 | mylcd.setline(1,4); |
liam_grazier | 8:582ac4c5a524 | 66 | mylcd.write("||||||| "); |
liam_grazier | 8:582ac4c5a524 | 67 | } |
liam_grazier | 8:582ac4c5a524 | 68 | else if(lightin > 0.5 && lightin < 0.54) |
liam_grazier | 8:582ac4c5a524 | 69 | { |
liam_grazier | 8:582ac4c5a524 | 70 | mylcd.setline(1,4); |
liam_grazier | 8:582ac4c5a524 | 71 | mylcd.write("||||| "); |
liam_grazier | 8:582ac4c5a524 | 72 | } |
liam_grazier | 8:582ac4c5a524 | 73 | else if(lightin > 0.4 && lightin < 0.54) |
liam_grazier | 8:582ac4c5a524 | 74 | { |
liam_grazier | 8:582ac4c5a524 | 75 | mylcd.setline(1,4); |
liam_grazier | 8:582ac4c5a524 | 76 | mylcd.write("||| "); |
liam_grazier | 8:582ac4c5a524 | 77 | } |
liam_grazier | 8:582ac4c5a524 | 78 | else if(lightin > 0.3 && lightin < 0.39) |
liam_grazier | 8:582ac4c5a524 | 79 | { |
liam_grazier | 8:582ac4c5a524 | 80 | mylcd.setline(1,4); |
liam_grazier | 8:582ac4c5a524 | 81 | mylcd.write("|| "); |
liam_grazier | 8:582ac4c5a524 | 82 | } |
liam_grazier | 8:582ac4c5a524 | 83 | else if(lightin > 0.06 && lightin < 0.29) |
liam_grazier | 8:582ac4c5a524 | 84 | { |
liam_grazier | 8:582ac4c5a524 | 85 | mylcd.setline(1,4); |
liam_grazier | 8:582ac4c5a524 | 86 | mylcd.write("LOW LIGHT "); |
liam_grazier | 8:582ac4c5a524 | 87 | } |
liam_grazier | 8:582ac4c5a524 | 88 | else if(lightin < 0.05) |
liam_grazier | 8:582ac4c5a524 | 89 | { |
liam_grazier | 8:582ac4c5a524 | 90 | mylcd.setline(1,4); |
liam_grazier | 8:582ac4c5a524 | 91 | mylcd.write(" "); |
liam_grazier | 8:582ac4c5a524 | 92 | mylcd.setline(1,4); |
liam_grazier | 8:582ac4c5a524 | 93 | mylcd.write("disconnected"); |
liam_grazier | 8:582ac4c5a524 | 94 | } |
liam_grazier | 8:582ac4c5a524 | 95 | mylcd.setline(2,1); |
liam_grazier | 8:582ac4c5a524 | 96 | mylcd.write("P:"); |
liam_grazier | 8:582ac4c5a524 | 97 | mylcd.write(PRE); |
liam_grazier | 8:582ac4c5a524 | 98 | mylcd.setline(2,10); |
liam_grazier | 8:582ac4c5a524 | 99 | mylcd.write("T:"); |
liam_grazier | 8:582ac4c5a524 | 100 | mylcd.write(TEM); |
liam_grazier | 8:582ac4c5a524 | 101 | wait(0.01); |
liam_grazier | 8:582ac4c5a524 | 102 | Lock1.unlock(); |
liam_grazier | 8:582ac4c5a524 | 103 | Thread::signal_wait(SIG_READY); |
liam_grazier | 8:582ac4c5a524 | 104 | } |
liam_grazier | 8:582ac4c5a524 | 105 | } |
liam_grazier | 8:582ac4c5a524 | 106 | void sdwrite(void) |
liam_grazier | 8:582ac4c5a524 | 107 | { |
liam_grazier | 8:582ac4c5a524 | 108 | while(1) |
liam_grazier | 8:582ac4c5a524 | 109 | { |
liam_grazier | 8:582ac4c5a524 | 110 | Lock2.lock(); |
liam_grazier | 8:582ac4c5a524 | 111 | double P = sensor.getPressure(); |
liam_grazier | 8:582ac4c5a524 | 112 | double L = adcIn; |
liam_grazier | 8:582ac4c5a524 | 113 | double t = sensor.getTemperature(); |
liam_grazier | 8:582ac4c5a524 | 114 | char tem[6]; |
liam_grazier | 8:582ac4c5a524 | 115 | char pre[5]; |
liam_grazier | 8:582ac4c5a524 | 116 | char light[6]; |
liam_grazier | 8:582ac4c5a524 | 117 | char com[1]; |
liam_grazier | 8:582ac4c5a524 | 118 | strcpy(com, ","); |
liam_grazier | 8:582ac4c5a524 | 119 | sprintf(pre,"%.2f", P); |
liam_grazier | 8:582ac4c5a524 | 120 | sprintf(tem,"%.2f",t); |
liam_grazier | 8:582ac4c5a524 | 121 | printf(tem); |
liam_grazier | 8:582ac4c5a524 | 122 | sprintf(light,"%.2f\n\r", L); |
liam_grazier | 8:582ac4c5a524 | 123 | time_t seconds = time(NULL); |
liam_grazier | 8:582ac4c5a524 | 124 | strftime(jdate1, 32, "%F", localtime(&seconds)); |
liam_grazier | 8:582ac4c5a524 | 125 | strftime(jdate, 32, "%F\n\r", localtime(&seconds)); |
liam_grazier | 8:582ac4c5a524 | 126 | strftime(jtime, 32, "%X\n\r", localtime(&seconds)); |
liam_grazier | 8:582ac4c5a524 | 127 | FATFileSystem fs("sd", &sd); |
liam_grazier | 8:582ac4c5a524 | 128 | char filename[32]; |
liam_grazier | 8:582ac4c5a524 | 129 | char suffix[4]; |
liam_grazier | 8:582ac4c5a524 | 130 | char prefix[4]; |
liam_grazier | 8:582ac4c5a524 | 131 | strcpy(prefix,"/sd/"); |
liam_grazier | 8:582ac4c5a524 | 132 | strcpy(suffix,".txt"); |
liam_grazier | 8:582ac4c5a524 | 133 | Lock1.lock(); |
liam_grazier | 8:582ac4c5a524 | 134 | sprintf(filename,"%s%s%s",prefix,jdate1,suffix); |
liam_grazier | 8:582ac4c5a524 | 135 | Lock1.unlock(); |
liam_grazier | 8:582ac4c5a524 | 136 | FILE* fp = fopen(filename,"a"); |
liam_grazier | 8:582ac4c5a524 | 137 | if (fp == NULL) { |
liam_grazier | 8:582ac4c5a524 | 138 | errorCode(FATAL); |
liam_grazier | 8:582ac4c5a524 | 139 | printf("SD FAIL\n\r"); |
liam_grazier | 8:582ac4c5a524 | 140 | mylcd.clear(); |
liam_grazier | 8:582ac4c5a524 | 141 | mylcd.setline(1,0); |
liam_grazier | 8:582ac4c5a524 | 142 | mylcd.write("SD FAIL"); |
liam_grazier | 8:582ac4c5a524 | 143 | } |
liam_grazier | 8:582ac4c5a524 | 144 | if (fp != NULL){ |
liam_grazier | 8:582ac4c5a524 | 145 | //printf("SD Success\n\r"); |
liam_grazier | 8:582ac4c5a524 | 146 | // fprintf(fp,"%s\n\r", "*C, mbar, light level 0-1 scale"); |
liam_grazier | 8:582ac4c5a524 | 147 | fprintf(fp,"%s",jdate);//date |
liam_grazier | 8:582ac4c5a524 | 148 | fprintf(fp,"%s",com); |
liam_grazier | 8:582ac4c5a524 | 149 | fprintf(fp,"%s",jtime);//time |
liam_grazier | 8:582ac4c5a524 | 150 | fprintf(fp,"%s",com); |
liam_grazier | 8:582ac4c5a524 | 151 | fprintf(fp,"%s",pre); |
liam_grazier | 8:582ac4c5a524 | 152 | fprintf(fp,"%s",com); |
liam_grazier | 8:582ac4c5a524 | 153 | fprintf(fp,"%s",tem); |
liam_grazier | 8:582ac4c5a524 | 154 | fprintf(fp,"%s",com); |
liam_grazier | 8:582ac4c5a524 | 155 | fprintf(fp,"%s\n\r",light); |
liam_grazier | 8:582ac4c5a524 | 156 | wait(0.01); |
liam_grazier | 8:582ac4c5a524 | 157 | } |
liam_grazier | 8:582ac4c5a524 | 158 | fclose(fp); |
liam_grazier | 8:582ac4c5a524 | 159 | Lock2.unlock(); |
liam_grazier | 8:582ac4c5a524 | 160 | Thread::signal_wait(SIG_READY2); |
liam_grazier | 8:582ac4c5a524 | 161 | |
liam_grazier | 8:582ac4c5a524 | 162 | } |
liam_grazier | 8:582ac4c5a524 | 163 | } |
liam_grazier | 8:582ac4c5a524 | 164 | void sdrun(void) |
liam_grazier | 8:582ac4c5a524 | 165 | { |
liam_grazier | 8:582ac4c5a524 | 166 | if ( sd.init() != 0) { |
liam_grazier | 8:582ac4c5a524 | 167 | printf("Init failed\n\r"); |
liam_grazier | 8:582ac4c5a524 | 168 | mylcd.clear(); |
liam_grazier | 8:582ac4c5a524 | 169 | mylcd.setline(1,1); |
liam_grazier | 8:582ac4c5a524 | 170 | mylcd.write("CANNOT INIT SD"); |
liam_grazier | 8:582ac4c5a524 | 171 | errorCode(FATAL); |
liam_grazier | 8:582ac4c5a524 | 172 | } |
liam_grazier | 8:582ac4c5a524 | 173 | if( sd.init() == 0){ |
liam_grazier | 8:582ac4c5a524 | 174 | printf("Init Success \n\r"); |
liam_grazier | 8:582ac4c5a524 | 175 | mylcd.clear(); |
liam_grazier | 8:582ac4c5a524 | 176 | mylcd.setline(1,1); |
liam_grazier | 8:582ac4c5a524 | 177 | mylcd.write("SD GOOD MAN"); |
liam_grazier | 8:582ac4c5a524 | 178 | wait(0.5); //flash the SD error / good code! |
liam_grazier | 8:582ac4c5a524 | 179 | } |
liam_grazier | 8:582ac4c5a524 | 180 | } |
liam_grazier | 8:582ac4c5a524 | 181 | void sdcheck(void){ |
liam_grazier | 8:582ac4c5a524 | 182 | if ( sd.init() != 0) { |
liam_grazier | 8:582ac4c5a524 | 183 | printf("Init failed \n\r"); |
liam_grazier | 8:582ac4c5a524 | 184 | mylcd.clear(); |
liam_grazier | 8:582ac4c5a524 | 185 | mylcd.setline(1,1); |
liam_grazier | 8:582ac4c5a524 | 186 | mylcd.write("CANNOT INIT SD\n\r"); |
liam_grazier | 8:582ac4c5a524 | 187 | errorCode(FATAL); |
liam_grazier | 8:582ac4c5a524 | 188 | } |
liam_grazier | 8:582ac4c5a524 | 189 | if( sd.init() == 0){ |
liam_grazier | 8:582ac4c5a524 | 190 | //printf("SD Good\n\r"); |
liam_grazier | 8:582ac4c5a524 | 191 | } |
liam_grazier | 8:582ac4c5a524 | 192 | } |
liam_grazier | 8:582ac4c5a524 | 193 | void sdremove(void) |
liam_grazier | 8:582ac4c5a524 | 194 | { |
liam_grazier | 8:582ac4c5a524 | 195 | while(1){ |
liam_grazier | 8:582ac4c5a524 | 196 | Thread::signal_wait(SIG_REMOVE); |
liam_grazier | 8:582ac4c5a524 | 197 | mylcd.clear(); |
liam_grazier | 8:582ac4c5a524 | 198 | Remove.lock(); |
liam_grazier | 8:582ac4c5a524 | 199 | sd.deinit(); |
liam_grazier | 8:582ac4c5a524 | 200 | mylcd.clear(); |
liam_grazier | 8:582ac4c5a524 | 201 | Lock1.lock(); |
liam_grazier | 8:582ac4c5a524 | 202 | mylcd.setline(2,0); |
liam_grazier | 8:582ac4c5a524 | 203 | greenLED = 1; |
liam_grazier | 8:582ac4c5a524 | 204 | mylcd.write("R"); |
liam_grazier | 8:582ac4c5a524 | 205 | Lock1.unlock(); |
liam_grazier | 8:582ac4c5a524 | 206 | printf("SD REMOVED\n\r"); |
liam_grazier | 8:582ac4c5a524 | 207 | errorCode(FATAL); |
liam_grazier | 8:582ac4c5a524 | 208 | Remove.unlock(); |
liam_grazier | 8:582ac4c5a524 | 209 | } |
liam_grazier | 8:582ac4c5a524 | 210 | } |
liam_grazier | 8:582ac4c5a524 | 211 | void lcdstart(void){ |
liam_grazier | 8:582ac4c5a524 | 212 | mylcd.clear(); |
liam_grazier | 8:582ac4c5a524 | 213 | mylcd.setline(1,1); |
liam_grazier | 8:582ac4c5a524 | 214 | mylcd.write("INIT. SYSTEM"); |
liam_grazier | 8:582ac4c5a524 | 215 | mylcd.setline(2,1); |
liam_grazier | 8:582ac4c5a524 | 216 | mylcd.write("ELEC351"); |
liam_grazier | 8:582ac4c5a524 | 217 | } |
liam_grazier | 8:582ac4c5a524 | 218 | void errorCode(ELEC350_ERROR_CODE err) |
liam_grazier | 8:582ac4c5a524 | 219 | { |
liam_grazier | 8:582ac4c5a524 | 220 | switch (err) { |
liam_grazier | 8:582ac4c5a524 | 221 | case OK: |
liam_grazier | 8:582ac4c5a524 | 222 | greenLED = 1; |
liam_grazier | 8:582ac4c5a524 | 223 | wait(1.0); |
liam_grazier | 8:582ac4c5a524 | 224 | greenLED = 0; |
liam_grazier | 8:582ac4c5a524 | 225 | return; |
liam_grazier | 8:582ac4c5a524 | 226 | case FATAL: |
liam_grazier | 8:582ac4c5a524 | 227 | while(1) { |
liam_grazier | 8:582ac4c5a524 | 228 | redLED = 1; |
liam_grazier | 8:582ac4c5a524 | 229 | wait(0.1); |
liam_grazier | 8:582ac4c5a524 | 230 | redLED = 0; |
liam_grazier | 8:582ac4c5a524 | 231 | wait(0.1); |
liam_grazier | 8:582ac4c5a524 | 232 | } |
liam_grazier | 8:582ac4c5a524 | 233 | } |
liam_grazier | 8:582ac4c5a524 | 234 | } |
liam_grazier | 8:582ac4c5a524 | 235 | |
liam_grazier | 8:582ac4c5a524 | 236 | ///dougs code |
liam_grazier | 8:582ac4c5a524 | 237 | |
liam_grazier | 8:582ac4c5a524 | 238 | void DispTime(void) |
liam_grazier | 8:582ac4c5a524 | 239 | { |
liam_grazier | 8:582ac4c5a524 | 240 | time_t Count = time(NULL); //Read the RTC Time |
liam_grazier | 8:582ac4c5a524 | 241 | printf("Current Time - %s\n\r", ctime(&Count)); //Print the current time |
liam_grazier | 8:582ac4c5a524 | 242 | } |
liam_grazier | 8:582ac4c5a524 | 243 | |
liam_grazier | 8:582ac4c5a524 | 244 | void setuptime(void) |
liam_grazier | 8:582ac4c5a524 | 245 | { |
liam_grazier | 8:582ac4c5a524 | 246 | |
liam_grazier | 8:582ac4c5a524 | 247 | /*Initialising the time for our program to easy edit*/ |
liam_grazier | 8:582ac4c5a524 | 248 | time ( &rawtime ); |
liam_grazier | 8:582ac4c5a524 | 249 | timeinfo = localtime ( &rawtime ); |
liam_grazier | 8:582ac4c5a524 | 250 | |
liam_grazier | 8:582ac4c5a524 | 251 | /*Setting the time to the deadline time*/ |
liam_grazier | 8:582ac4c5a524 | 252 | /*Same as button Code*/ |
liam_grazier | 8:582ac4c5a524 | 253 | //Set the initialisation time to: Tuesday 9th January 2018, 16:00:00. |
liam_grazier | 8:582ac4c5a524 | 254 | //set_time(1515513600); |
liam_grazier | 8:582ac4c5a524 | 255 | //Initialisation of the times. |
liam_grazier | 8:582ac4c5a524 | 256 | time ( &rawtime ); |
liam_grazier | 8:582ac4c5a524 | 257 | timeinfo = localtime ( &rawtime ); |
liam_grazier | 8:582ac4c5a524 | 258 | //Displays the initialisation time |
liam_grazier | 8:582ac4c5a524 | 259 | DispTime(); |
liam_grazier | 8:582ac4c5a524 | 260 | /*End the initialisation */ |
liam_grazier | 8:582ac4c5a524 | 261 | |
liam_grazier | 8:582ac4c5a524 | 262 | } |
liam_grazier | 8:582ac4c5a524 | 263 | |
liam_grazier | 8:582ac4c5a524 | 264 | void runtime(void){ |
liam_grazier | 8:582ac4c5a524 | 265 | while(1) //When added to the main code this will be changed to a while "SETDATE" |
liam_grazier | 8:582ac4c5a524 | 266 | { |
liam_grazier | 8:582ac4c5a524 | 267 | /*promts the user to input which edit they would like*/ |
liam_grazier | 8:582ac4c5a524 | 268 | printf ("What part do you want to edit? Time(T)/All(A).\n\r"); |
liam_grazier | 8:582ac4c5a524 | 269 | fflush(stdout); |
liam_grazier | 8:582ac4c5a524 | 270 | scanf ("%s",&input); |
liam_grazier | 8:582ac4c5a524 | 271 | /*Switch case input*/ |
liam_grazier | 8:582ac4c5a524 | 272 | switch(input) |
liam_grazier | 8:582ac4c5a524 | 273 | { |
liam_grazier | 8:582ac4c5a524 | 274 | case 'T': |
liam_grazier | 8:582ac4c5a524 | 275 | //Sequential Entering, Hour, Minute, Second respectively |
liam_grazier | 8:582ac4c5a524 | 276 | printf ("Enter hour:(00-23) \n\r"); |
liam_grazier | 8:582ac4c5a524 | 277 | fflush(stdout); |
liam_grazier | 8:582ac4c5a524 | 278 | scanf ("%d",&hour); |
liam_grazier | 8:582ac4c5a524 | 279 | |
liam_grazier | 8:582ac4c5a524 | 280 | printf ("Enter minute:(00-59) \n\r"); |
liam_grazier | 8:582ac4c5a524 | 281 | fflush(stdout); |
liam_grazier | 8:582ac4c5a524 | 282 | scanf ("%d",&minute); |
liam_grazier | 8:582ac4c5a524 | 283 | |
liam_grazier | 8:582ac4c5a524 | 284 | printf ("Enter second:(00-59) \n\r"); |
liam_grazier | 8:582ac4c5a524 | 285 | fflush(stdout); |
liam_grazier | 8:582ac4c5a524 | 286 | scanf ("%d",&second); |
liam_grazier | 8:582ac4c5a524 | 287 | |
liam_grazier | 8:582ac4c5a524 | 288 | break; |
liam_grazier | 8:582ac4c5a524 | 289 | |
liam_grazier | 8:582ac4c5a524 | 290 | /*Case A ----- All values Update sequence*/ |
liam_grazier | 8:582ac4c5a524 | 291 | case 'A': |
liam_grazier | 8:582ac4c5a524 | 292 | printf ("Enter year:(0-9999) \n\r"); fflush(stdout); scanf ("%d",&year); |
liam_grazier | 8:582ac4c5a524 | 293 | printf ("Enter month:(01-12) \n\r"); fflush(stdout); scanf ("%d",&month); |
liam_grazier | 8:582ac4c5a524 | 294 | printf ("Enter day:(01-31) \n\r"); fflush(stdout); scanf ("%d",&day); |
liam_grazier | 8:582ac4c5a524 | 295 | printf ("Enter hour:(00-23)\n\r"); fflush(stdout); scanf ("%d",&hour); |
liam_grazier | 8:582ac4c5a524 | 296 | printf ("Enter minute:(00-59) \n\r"); fflush(stdout); scanf ("%d",&minute); |
liam_grazier | 8:582ac4c5a524 | 297 | printf ("Enter second:(00-59) \n\r"); fflush(stdout); scanf ("%d",&second); |
liam_grazier | 8:582ac4c5a524 | 298 | break; |
liam_grazier | 8:582ac4c5a524 | 299 | |
liam_grazier | 8:582ac4c5a524 | 300 | /*default to reset ----- Month Update sequence*/ |
liam_grazier | 8:582ac4c5a524 | 301 | default: |
liam_grazier | 8:582ac4c5a524 | 302 | printf ("Invalid\n\r"); |
liam_grazier | 8:582ac4c5a524 | 303 | set_time(1515513600); |
liam_grazier | 8:582ac4c5a524 | 304 | } |
liam_grazier | 8:582ac4c5a524 | 305 | /*Updating all the timings after the user has input all the data*/ |
liam_grazier | 8:582ac4c5a524 | 306 | /*Put here as once the user has finished editing it does a batch update*/ |
liam_grazier | 8:582ac4c5a524 | 307 | timeinfo->tm_year = year - 1900; |
liam_grazier | 8:582ac4c5a524 | 308 | timeinfo->tm_mon = month - 1; |
liam_grazier | 8:582ac4c5a524 | 309 | timeinfo->tm_mday = day; |
liam_grazier | 8:582ac4c5a524 | 310 | timeinfo->tm_hour = hour; |
liam_grazier | 8:582ac4c5a524 | 311 | timeinfo->tm_min = minute; |
liam_grazier | 8:582ac4c5a524 | 312 | timeinfo->tm_sec = second; |
liam_grazier | 8:582ac4c5a524 | 313 | time_t CurrTime = mktime(timeinfo); //Convert the to UNIX time |
liam_grazier | 8:582ac4c5a524 | 314 | set_time(CurrTime); //Sets time using the UNIX time |
liam_grazier | 8:582ac4c5a524 | 315 | DispTime(); |
liam_grazier | 8:582ac4c5a524 | 316 | return; //Display the new time |
liam_grazier | 8:582ac4c5a524 | 317 | } |
liam_grazier | 8:582ac4c5a524 | 318 | } |
liam_grazier | 8:582ac4c5a524 | 319 | |
liam_grazier | 8:582ac4c5a524 | 320 | void rundate(void){ |
liam_grazier | 8:582ac4c5a524 | 321 | while(1) //When added to the main code this will be changed to a while "SETDATE" |
liam_grazier | 8:582ac4c5a524 | 322 | { |
liam_grazier | 8:582ac4c5a524 | 323 | |
liam_grazier | 8:582ac4c5a524 | 324 | /*promts the user to input which edit they would like*/ |
liam_grazier | 8:582ac4c5a524 | 325 | printf ("What part do you want to edit? Date(D)/All(A).\n\r"); |
liam_grazier | 8:582ac4c5a524 | 326 | fflush(stdout); |
liam_grazier | 8:582ac4c5a524 | 327 | scanf ("%s",&input); |
liam_grazier | 8:582ac4c5a524 | 328 | /*Switch case input*/ |
liam_grazier | 8:582ac4c5a524 | 329 | switch(input) |
liam_grazier | 8:582ac4c5a524 | 330 | { |
liam_grazier | 8:582ac4c5a524 | 331 | /*Case D ----- Date Update sequence*/ |
liam_grazier | 8:582ac4c5a524 | 332 | case 'D': |
liam_grazier | 8:582ac4c5a524 | 333 | //Sequential Entering, Day, Month, Year respectively |
liam_grazier | 8:582ac4c5a524 | 334 | printf ("Enter day:(01-31) \n\r"); |
liam_grazier | 8:582ac4c5a524 | 335 | fflush(stdout); |
liam_grazier | 8:582ac4c5a524 | 336 | scanf ("%d",&day); |
liam_grazier | 8:582ac4c5a524 | 337 | printf ("Enter month:(01-12) \n\r"); |
liam_grazier | 8:582ac4c5a524 | 338 | fflush(stdout); |
liam_grazier | 8:582ac4c5a524 | 339 | scanf ("%d",&month); |
liam_grazier | 8:582ac4c5a524 | 340 | printf ("Enter year:(1970-9999) \n\r"); |
liam_grazier | 8:582ac4c5a524 | 341 | fflush(stdout); |
liam_grazier | 8:582ac4c5a524 | 342 | scanf ("%d",&year); |
liam_grazier | 8:582ac4c5a524 | 343 | break; |
liam_grazier | 8:582ac4c5a524 | 344 | /*Case A ----- All values Update sequence*/ |
liam_grazier | 8:582ac4c5a524 | 345 | case 'A': |
liam_grazier | 8:582ac4c5a524 | 346 | printf ("Enter year:(0-9999) \n\r"); fflush(stdout); scanf ("%d",&year); |
liam_grazier | 8:582ac4c5a524 | 347 | printf ("Enter month:(01-12) \n\r"); fflush(stdout); scanf ("%d",&month); |
liam_grazier | 8:582ac4c5a524 | 348 | printf ("Enter day:(01-31) \n\r"); fflush(stdout); scanf ("%d",&day); |
liam_grazier | 8:582ac4c5a524 | 349 | printf ("Enter hour:(00-23)\n\r"); fflush(stdout); scanf ("%d",&hour); |
liam_grazier | 8:582ac4c5a524 | 350 | printf ("Enter minute:(00-59) \n\r"); fflush(stdout); scanf ("%d",&minute); |
liam_grazier | 8:582ac4c5a524 | 351 | printf ("Enter second:(00-59) \n\r"); fflush(stdout); scanf ("%d",&second); |
liam_grazier | 8:582ac4c5a524 | 352 | break; |
liam_grazier | 8:582ac4c5a524 | 353 | /*default to reset ----- Month Update sequence*/ |
liam_grazier | 8:582ac4c5a524 | 354 | default: |
liam_grazier | 8:582ac4c5a524 | 355 | printf ("Invalid\n\r"); |
liam_grazier | 8:582ac4c5a524 | 356 | set_time(1515513600); |
liam_grazier | 8:582ac4c5a524 | 357 | } |
liam_grazier | 8:582ac4c5a524 | 358 | /*Updating all the timings after the user has input all the data*/ |
liam_grazier | 8:582ac4c5a524 | 359 | /*Put here as once the user has finished editing it does a batch update*/ |
liam_grazier | 8:582ac4c5a524 | 360 | timeinfo->tm_year = year - 1900; |
liam_grazier | 8:582ac4c5a524 | 361 | timeinfo->tm_mon = month - 1; |
liam_grazier | 8:582ac4c5a524 | 362 | timeinfo->tm_mday = day; |
liam_grazier | 8:582ac4c5a524 | 363 | timeinfo->tm_hour = hour; |
liam_grazier | 8:582ac4c5a524 | 364 | timeinfo->tm_min = minute; |
liam_grazier | 8:582ac4c5a524 | 365 | timeinfo->tm_sec = second; |
liam_grazier | 8:582ac4c5a524 | 366 | time_t CurrTime = mktime(timeinfo); //Convert the to UNIX time |
liam_grazier | 8:582ac4c5a524 | 367 | set_time(CurrTime); //Sets time using the UNIX time |
liam_grazier | 8:582ac4c5a524 | 368 | DispTime(); |
liam_grazier | 8:582ac4c5a524 | 369 | return; //Display the new time |
liam_grazier | 8:582ac4c5a524 | 370 | } |
liam_grazier | 8:582ac4c5a524 | 371 | } |