![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
wave cancel
Dependencies: 4DGL-uLCD-SE EthernetInterface HTTPClient NTPClient PinDetect SDFileSystem mbed-rtos mbed wave_player
Fork of 4180_Final_Project by
Diff: main.cpp
- Revision:
- 13:34dc6730e791
- Parent:
- 12:27470e8c0556
- Child:
- 14:37293ee3f3c1
diff -r 27470e8c0556 -r 34dc6730e791 main.cpp --- a/main.cpp Thu Apr 28 17:00:55 2016 +0000 +++ b/main.cpp Thu Apr 28 23:45:23 2016 +0000 @@ -49,8 +49,12 @@ int curAlarmMin = 9; bool play = true; //traffic -char location[locationLength]; -char destination[locationLength]; +char start_add[locationLength] = ""; // start location address +char dest_add[locationLength] = ""; // destination address +int trip_sec = 0; +int arrival_hour; +int arrival_min; +int ready_time = 0; //time thread @@ -69,20 +73,52 @@ Thread::wait(100); } } -/* + +void reset_alarm() +{ + int arival_sec = arrival_min*60 + arrival_hour*60*24; + int alarm = arival_sec - trip_sec - ready_time*60; + if(alarm < 0) { + alarm += 86400; + } + alarm = (alarm - (alarm % 60))/60; + baseAlarmMin = (alarm % 60); + alarm = (alarm - (alarm % 60))/60; + baseAlarmHour = (alarm % 60); + curAlarmMin = baseAlarmMin; + curAlarmHour = baseAlarmHour; +} + //communication thread void comm_thread(void const *args) { - time_weth.putc("w"); - time_weth.putc("e"); - time_weth.putc("t"); - time_weth.putc("h"); - for(i = 0; i < locationLength; i++){ - time_weth.putc(location[i]); - time_weth.putc(destination[i]); - } + char buff[4]; + int i; + int sum = 0; + bool flag; + while(true) { + for(i = 0; i < locationLength; i++) { + time_weth.putc(start_add[i]); + } + for(i = 0; i < locationLength; i++) { + time_weth.putc(dest_add[i]); + } + flag = false; + i = 0; + while(!flag) { + buff[i] = pc.getc(); + //pc.putc(buff[i]); + flag = buff[i] == '^'; + i++; + } + for(i = 0; i < 4; i++) { + sum += int(buff[i]-'0') * pow(10.0,i); + } + trip_sec = sum; + reset_alarm(); + Thread::wait(1800000); + } } -*/ //pushbutton (p19) void snooze_hit_callback (void) @@ -153,7 +189,7 @@ void getSDInfo() { - char c; + char c; FILE *fp = fopen("/sd/mydir/sdtest.txt", "r"); if(fp == NULL) { error("Could not open file for read\n"); @@ -162,45 +198,40 @@ int i; char arr_time[8] = ""; char hour[3], min[3]; - int arrival_hour; - int arrival_min; char r_time[8] = ""; - int ready_time = 0; - char start_add[32] = ""; // start location address - char dest_add[32] = ""; // destination address - - while (!feof(fp)){ // while not end of file + + + while (!feof(fp)) { // while not end of file c=fgetc(fp); // get a character/byte from the file uLCD.printf("%c",c); - if (c == '@') { + if (c == '@') { count++; // specifies what data (eg. arrival time, ready time, etc) i = 0; - } - else { - //uLCD.printf("%d",count); - switch (count) { - case 0: // arrival time - arr_time[i] = c; - i++; - break; - case 1: // ready time (min) - r_time[i] = c; - i++; - break; - case 2: // start address - start_add[i] = c; - i++; - break; - case 3: // destination address - dest_add[i] = c; - i++; - break; - default: - error("too many & detected\n"); - break; - } - - //uLCD.printf("Read from file %02x\n\r",c); // and show it in hex format + } else { + //uLCD.printf("%d",count); + switch (count) { + case 0: // arrival time + arr_time[i] = c; + i++; + break; + case 1: // ready time (min) + r_time[i] = c; + i++; + break; + case 2: // start address + start_add[i] = c; + i++; + break; + case 3: // destination address + dest_add[i] = c; + i++; + break; + default: + error("too many & detected\n"); + break; + } + + //uLCD.printf("Read from file %02x\n\r",c); // and show it in hex format } } memcpy( hour, &arr_time[0], 2 ); @@ -216,8 +247,8 @@ uLCD.printf("Ready Time is %d\n",ready_time); uLCD.printf("start address is %s\n", start_add); uLCD.printf("dest address is %s\n", dest_add); - - fclose(fp); + + fclose(fp); } int main()