All tasks complete

Dependencies:   mbed MCP23017 mbed-rtos WattBob_TextLCD

Revision:
12:f4052a23ddc7
Parent:
11:d6d1583fc824
Child:
13:822b0e56ea68
diff -r d6d1583fc824 -r f4052a23ddc7 assignment3tasks.cpp
--- a/assignment3tasks.cpp	Wed Mar 27 13:41:38 2019 +0000
+++ b/assignment3tasks.cpp	Wed Mar 27 15:14:10 2019 +0000
@@ -18,8 +18,8 @@
 
 //indicators 
 DigitalOut          ngeneind(pin_LED1);
-PwmOut              leftind(pin_LED2); //was digitalout
-PwmOut              rightind(pin_LED3);//was digitalout
+PwmOut          leftind(pin_LED2); //was digitalout
+PwmOut          rightind(pin_LED3);//was digitalout
 DigitalOut          sideind(pin_LED4);
 
 
@@ -109,7 +109,7 @@
     while(true){
     speedXS.lock();//lock
     
-    for(int i = 0; i < SAMPLESIZE ; i++){
+    for(int i = 0; i < SAMPLESIZE - 1 ; i++){
         //speed.rawspeed = (speed.accelvalue - speed.brakevalue)*MAXSPEED;
         speed.average += speed.array[i];
         }
@@ -164,15 +164,14 @@
         speed.rawspeed += (temp_accel - speed.brakevalue) * MAXSPEED; 
         
         if(speed.rawspeed < 0)
-        speed.rawspeed = 0;
+            speed.rawspeed = 0;
         if(speed.rawspeed > MAXSPEED)
-        speed.rawspeed = MAXSPEED;   
+            speed.rawspeed = MAXSPEED;   
         
         // Saving the new speed
         for (int i = 0; i < SAMPLESIZE - 1; i++)
-        
-        speed.array[i]= speed.array[i+1]; 
-        speed.array[4]= speed.rawspeed;
+            speed.array[i]= speed.array[i+1]; 
+            speed.array[4]= speed.rawspeed;
             
         float temp = speed.rawspeed;
         
@@ -181,7 +180,7 @@
         
         // Update Overspeed display
         
-        if (temp > SPEEDLIMIT)
+        if (temp > 39.3395) //88 mph to ms
             overspeedind = 1;
         else
             overspeedind = 0;
@@ -193,9 +192,10 @@
 void task7displayvalues()
 {
     float delay = 1000 / TASKFREQ7;
+    display->cls();
     while(true){
         
-        display->cls();
+        
     
         //LOCK data
         carstateXS.lock();
@@ -203,9 +203,9 @@
         speedXS.lock();
         
         display->locate(1,0);
-        display->printf("AvgS: %.2f",speed.average);
+        display->printf("AvgS: %.2f m/s",speed.average);
         display->locate(0,0);
-        display->printf("ODOM: %d",(int) info.odometer);
+        display->printf("ODOM: %d m",(int) info.odometer);
      
         //UNLOCK data
         carstateXS.unlock();
@@ -247,7 +247,7 @@
         
         }
 }
-/*
+
 void task9indLED()
 {
     while(true){
@@ -260,8 +260,8 @@
 
         carstateXS.lock();
          
-       (turnleft = 1)?     info.leftind    =   1   :info.leftind   =    0; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<this lock unlock stuff is messing it up 
-       (turnright = 1)?    info.rightind   =   1   :info.rightind  =    0; 
+       (turnleft == 1)?     info.leftind    =   1   :info.leftind   =    0; 
+       (turnright == 1)?    info.rightind   =   1   :info.rightind  =    0; 
         
         carstateXS.unlock();
              
@@ -325,12 +325,12 @@
     
     speedXS.unlock();
     
-    carstate.lock();  
+    carstateXS.lock();  
     
     PC.printf("LEFT INDICATOR  : %.1f\r\n",info.leftind);
     PC.printf("RIGHT INDICATOR : %.1f\r\n",info.rightind);
     
-    carstate.unlock();
+    carstateXS.unlock();
     
     float delay = 1000/ TASKFREQX;
     Thread:: wait((int)delay);
@@ -340,5 +340,48 @@
 
 
 } 
-*/
-      
\ No newline at end of file
+////////////////////////////////////
+/*void IndicatorsCheck(){
+    LeftIndicatorLight = LeftIndicatorSwitch;
+    RightIndicatorLight = RightIndicatorSwitch;
+}
+// Flash respective indicator every 1 second// linked from above 
+void IndicatorFlash(){
+    Global_Sem.wait();
+    if (LeftIndicatorLight == 1 && RightIndicatorLight == 0){
+        LeftIndicatorLight = 0;
+    }
+    else if (RightIndicatorLight == 1 && LeftIndicatorLight == 0){
+        RightIndicatorLight = 0;
+    }
+    else if (LeftIndicatorLight == 0 && RightIndicatorLight == 0){
+    }
+    Global_Sem.release();
+}
+// Flash hazards every o.5 seconds
+void HazardLights(){
+    Global_Sem.wait();
+    if (LeftIndicatorSwitch == 1 && RightIndicatorSwitch == 1){
+        LeftIndicatorLight = 0;
+        RightIndicatorLight = 0;
+    }
+    Global_Sem.release();
+}
+void TwoHzLoop(){
+    while(true){
+        
+        count++; // Counter ensure everything works off of 2Hz loop
+        Display();
+        IndicatorsCheck();
+        HazardLights();
+        if (count == 2||count == 4){ // flash indicators every second
+            IndicatorFlash();
+        }
+        if (count == 4){ // send data every 2 seconds
+            SendData();
+            count = 0;
+        }
+        Thread::wait(500);
+    }
+}
+  */
\ No newline at end of file