CIS441 Proj MS 2b

Dependencies:   TextLCD MQTT

Revision:
0:ca7cb51e9fd1
Child:
1:54512aca944d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Nov 10 23:02:16 2019 +0000
@@ -0,0 +1,79 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2018 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include "mbed.h"
+#include "Road.h"
+#include "AccCar.h"
+#include "TextLCD.h"
+
+TextLCD lcd(p15, p16, p17, p18, p19, p20);
+
+// main() runs in its own thread in the OS
+int main() {
+    // ------------------------------------------------------------------------------
+    // The following three variables are used for timing statistics, do not modify them
+    Timer stopwatch;    // A timer to keep track of how long the updates take, for statistics purposes
+    int numberCycles = 0;
+    int totalUpdateTime = 0;
+    // ------------------------------------------------------------------------------
+
+    int time = 0;
+
+    Road road1;
+
+    stopwatch.start();
+    stopwatch.reset();
+    
+    int return_cars[MAX_CARS];
+    
+    do {
+        
+        int new_cars = road1.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();
+        
+    if(new_cars == -1 && road1.intersection_car == -1){
+            lcd.printf("x, x");
+    }
+    else if(new_cars != -1 && road1.intersection_car == -1){
+        lcd.printf("%d, x", new_cars);
+    }
+    else if(new_cars == -1 && road1.intersection_car != -1){
+        lcd.printf("x, %d", road1.intersection_car);
+    }
+    else{
+        lcd.printf("%d, %d", new_cars, road1.intersection_car);
+    }
+
+
+        printf("\r\n");
+    road1.check_exit_cars(return_cars);
+        
+        time++;
+        
+        // ------------------------------------------------------------------
+        // Timing statistics logic, do not modify
+        totalUpdateTime += stopwatch.read_ms();
+        numberCycles++;
+        stopwatch.reset();
+        // ------------------------------------------------------------------
+        
+        lcd.cls();
+        //lcd.printf("1 %d -> %d\n2 %d -> %d", 0,0,car2.position, car2.speed);
+        
+    } while( road1.active_cars > 0x00);
+    
+            // ----------------------------------------------------------------------
+    // Timing statistics printout, do not modify
+    printf("Average update cycle took: %fms \r\n", (totalUpdateTime*1.0)/(numberCycles*1.0));
+    totalUpdateTime = 0;
+    numberCycles = 0;
+    // ----------------------------------------------------------------------
+}