Guides the user to their classes

Dependencies:   4DGL-uLCD-SE Course SDFileSystem mbed PinDetect LSM9DS1_Library_cal MBed_Adafruit-GPS-Library

Revision:
13:0eb9fbd63fb2
Parent:
11:e28acc7bf487
Child:
14:d8a6134cafa3
--- a/main.cpp	Thu Dec 08 21:44:06 2016 +0000
+++ b/main.cpp	Thu Dec 08 23:07:36 2016 +0000
@@ -35,6 +35,9 @@
 int volatile current_screen = 0;
 bool volatile screen_change = false;
 void timeToNextClass();
+float displacement(float diffLat,float diffLong);
+float calc_eta(float displacement, float speed);
+bool late(float eta);
 
 void left_callback(void)
 {
@@ -139,6 +142,23 @@
             currSecond = myGPS.seconds;
             nextClass = getNextClass(courseVec);
             timeToNextClass();
+            destinationLat = courseVec[nextClass].getLat();
+            destinationLong = courseVec[nextClass].getLong();
+            float diffLat = destinationLat - myLat;
+            float diffLong = destinationLong - myLong;
+            float dis = displacement(diffLat,diffLong);
+            float speed = 3.1; //mph. Source:https://lmgtfy.com/?q=average+human+walking+speed
+            float eta = calc_eta(dis,speed)*60;//(miles, mph)*60
+            if(late(eta)==1)
+            {
+                 uLCD.background_color(RED);
+                 uLCD.text_mode(TRANSPARENT);
+            }
+            else
+            {
+                 uLCD.background_color(BLACK);
+                 uLCD.text_mode(TRANSPARENT);
+            }
 
             switch(current_screen) {
                 case 0:
@@ -152,10 +172,6 @@
                     IMU.readMag();
                     h = calculateHeading(IMU.calcMag(IMU.mx), IMU.calcMag(IMU.my));
                     pc.printf("Heading: %f\n", h);
-                    destinationLat = courseVec[nextClass].getLat();
-                    destinationLong = courseVec[nextClass].getLong();
-                    float diffLat = destinationLat - myLat;
-                    float diffLong = destinationLong - myLong;
                     angleToDest = computeAngleToDestination(diffLat, diffLong);
                     h = angleToDest - h;
                     h = h - 90;
@@ -397,6 +413,17 @@
     return latInDec;
 }
 
+float displacement(float diffLat,float diffLong)
+{
+        d = sqrt(diffLat*diffLat+diffLong*diffLong);
+        return d;
+}
+float calc_eta(float displacement, float speed)
+{
+    float eta = displacement/speed; // for displacement. take average speed // convert to minutes later
+    eta = eta+ 0.25*eta; //adding delay for distance vs displacement and traffic lights
+    return eta;
+
 float longToDecimal(float longitudeInDDMM, char eastOrWest)
 {
     float longInDec = 0.0;
@@ -408,4 +435,17 @@
     if (eastOrWest == 'E')
         return longInDec;
     return -1 * longInDec;
+}
+
+bool late(float eta)
+{
+    float totalMinutes = hoursToNextClass*60+ minutesToNextClass+ secondsToNextClass/60;
+    if(totalMinutes>eta)
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
 }
\ No newline at end of file