wave cancel

Dependencies:   4DGL-uLCD-SE EthernetInterface HTTPClient NTPClient PinDetect SDFileSystem mbed-rtos mbed wave_player

Fork of 4180_Final_Project by Adam Zuravleff

Files at this revision

API Documentation at this revision

Comitter:
agamemaker
Date:
Fri Apr 29 05:52:41 2016 +0000
Parent:
13:34dc6730e791
Commit message:
done;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 34dc6730e791 -r 37293ee3f3c1 main.cpp
--- a/main.cpp	Thu Apr 28 23:45:23 2016 +0000
+++ b/main.cpp	Fri Apr 29 05:52:41 2016 +0000
@@ -36,7 +36,7 @@
 
 // Networking
 EthernetInterface eth;
-#define snoozeTime 10
+#define snoozeTime 420
 #define locationLength 50
 
 //global variables
@@ -49,9 +49,9 @@
 int curAlarmMin = 9;
 bool play = true;
 //traffic
-char start_add[locationLength] = ""; // start location address
-char dest_add[locationLength] = ""; // destination address
-int trip_sec = 0;
+char start_add[locationLength]; // start location address
+char dest_add[locationLength]; // destination address
+int trip_sec = 47400;
 int arrival_hour;
 int arrival_min;
 int ready_time = 0;
@@ -76,19 +76,47 @@
 
 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;
+    int trip_hour = trip_sec/(60*60);
+    int trip_min = (trip_sec - trip_hour*(60*60))/60;
+    uLCD.printf("trip %d:%d\n", trip_hour, trip_min);
+    baseAlarmHour = arrival_hour - trip_hour;
+    baseAlarmMin = arrival_min - trip_min - ready_time;
+    while(baseAlarmMin<0) {
+        baseAlarmHour -= 1;
+        baseAlarmMin += 60;
     }
-    alarm = (alarm - (alarm % 60))/60;
-    baseAlarmMin = (alarm % 60);
-    alarm = (alarm - (alarm % 60))/60;
-    baseAlarmHour = (alarm % 60);
+    if(baseAlarmHour<0) {
+        baseAlarmHour +=24;
+    }
+    curAlarmHour = baseAlarmHour;
     curAlarmMin = baseAlarmMin;
-    curAlarmHour = baseAlarmHour;
 }
 
+void comm_get()
+{
+    int sum = 0;
+    bool flag = false;
+    char url[512];
+    char buff[4];
+    int i = 0;
+    sprintf(url, "https://www.mapquestapi.com/directions/v2/route?key=ZoiBJSzSoqfdNiLD0Z9kZdw4uAN5QUQW&from=%s&to=%s", start_add, dest_add);
+    uLCD.printf("%s^\n",url);
+    time_weth.printf("%s^",url);
+    uLCD.printf("Reading travel time");
+    while(!flag) {
+        buff[i] = time_weth.getc();
+        //pc.putc(buff[i]);
+        flag = buff[i] == '^';
+        i++;
+    }
+    for(i = 0; i < 4; i++) {
+        sum += int(buff[3-i]-'0') * pow(10.0,i);
+    }
+    trip_sec = sum;
+    uLCD.printf("travel secs %d\n", trip_sec);
+    wait(10);
+}
+/*
 //communication thread
 void comm_thread(void const *args)
 {
@@ -100,11 +128,13 @@
         for(i = 0; i < locationLength; i++) {
             time_weth.putc(start_add[i]);
         }
+        time_weth.putc('@');
         for(i = 0; i < locationLength; i++) {
             time_weth.putc(dest_add[i]);
         }
         flag = false;
         i = 0;
+        uLCD.printf("send fomplete");
         while(!flag) {
             buff[i] = pc.getc();
             //pc.putc(buff[i]);
@@ -119,7 +149,7 @@
         Thread::wait(1800000);
     }
 }
-
+*/
 //pushbutton (p19)
 void snooze_hit_callback (void)
 {
@@ -247,12 +277,19 @@
     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);
 }
 
 int main()
 {
+    getSDInfo();
+    uLCD.cls();
+    comm_get();
+    uLCD.cls();
+    reset_alarm();
+    uLCD.printf("base = %d:%d\ncurr = %d:%d", baseAlarmHour, baseAlarmMin, curAlarmHour, curAlarmMin);
+    wait(10);
+    //Thread t2(comm_thread);
     snooze.mode(PullUp);
     off.mode(PullUp);
     settings.mode(PullUp);
@@ -299,7 +336,6 @@
     uLCD.text_height(2);
 
     Thread t1(time_thread);
-    //Thread t2(comm_thread);
     while(true) {
         timeCompare();
         Thread::wait(100);