Matthew Goldsmith / Mbed OS cis441projMS1a

Dependencies:   TextLCD

Revision:
1:54512aca944d
Parent:
0:ca7cb51e9fd1
Child:
2:150dd9f9c0f1
diff -r ca7cb51e9fd1 -r 54512aca944d main.cpp
--- a/main.cpp	Sun Nov 10 23:02:16 2019 +0000
+++ b/main.cpp	Mon Nov 11 00:50:05 2019 +0000
@@ -7,6 +7,7 @@
 #include "Road.h"
 #include "AccCar.h"
 #include "TextLCD.h"
+#include "Intersection.h" 
 
 TextLCD lcd(p15, p16, p17, p18, p19, p20);
 
@@ -21,42 +22,59 @@
 
     int time = 0;
 
-    Road road1;
+    Intersection intersection; 
+    Road* road1 = new Road(&intersection, 1);
+    Road* road2 = new Road(&intersection, 2); 
 
     stopwatch.start();
     stopwatch.reset();
     
-    int return_cars[MAX_CARS];
     
     do {
-        
-        int new_cars = road1.try_enter_car(time);
+        intersection.preChecks(); 
         
-        road1.let_cars_update();
-        road1.wait_for_car_update();
+        int new_cars1 = road1->try_enter_car(time);
+        int new_cars2 = road2->try_enter_car(time); 
+        
+        road1->let_cars_update();
+        road1->wait_for_car_update();
         
         
         printf("\r\nRoad 1 Update %d\r\n", time);
-        road1.print_status();
+        road1->print_status();
+        printf("\r\nRoad 2 Update %d\r\n", time);
+        road2->print_status(); 
         
-    if(new_cars == -1 && road1.intersection_car == -1){
+    if(new_cars1 == -1 && (intersection.intersection_car == -1 || intersection.intersection_car > 4)){
             lcd.printf("x, x");
     }
-    else if(new_cars != -1 && road1.intersection_car == -1){
-        lcd.printf("%d, x", new_cars);
+    else if(new_cars1 != -1 && (intersection.intersection_car == -1 || intersection.intersection_car > 4)){
+        lcd.printf("%d, x", new_cars1);
     }
-    else if(new_cars == -1 && road1.intersection_car != -1){
-        lcd.printf("x, %d", road1.intersection_car);
+    else if(new_cars1 == -1 && !(intersection.intersection_car == -1 || intersection.intersection_car > 4)){
+        lcd.printf("x, %d", intersection.intersection_car);
     }
     else{
-        lcd.printf("%d, %d", new_cars, road1.intersection_car);
+        lcd.printf("%d, %d", new_cars1, intersection.intersection_car);
+    }
+    
+    if(new_cars2 == -1 && intersection.intersection_car < 5){
+        lcd.printf("x, x");
+    }
+    else if(new_cars2 != -1 && intersection.intersection_car < 5){
+        lcd.printf("%d, x", new_cars2);
+    }
+    else if(new_cars2 == -1 && intersection.intersection_car >= 5){
+        lcd.printf("x, %d", intersection.intersection_car);
+    }
+    else{
+        lcd.printf("%d, %d", new_cars2, intersection.intersection_car);
     }
 
-
-        printf("\r\n");
-    road1.check_exit_cars(return_cars);
-        
-        time++;
+    printf("\r\n");
+    road1->check_exit_cars();  
+    road2->check_exit_cars(); 
+    time++;
         
         // ------------------------------------------------------------------
         // Timing statistics logic, do not modify
@@ -68,7 +86,7 @@
         lcd.cls();
         //lcd.printf("1 %d -> %d\n2 %d -> %d", 0,0,car2.position, car2.speed);
         
-    } while( road1.active_cars > 0x00);
+    } while( road1->active_cars > 0x00 || road2->active_cars > 0x00);
     
             // ----------------------------------------------------------------------
     // Timing statistics printout, do not modify