![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All tasks complete
Dependencies: mbed MCP23017 mbed-rtos WattBob_TextLCD
Diff: assignment3tasks.cpp
- Revision:
- 7:87f7ba90fdce
- Parent:
- 6:abbd51d9b045
- Child:
- 8:3f3f2c2e2046
--- a/assignment3tasks.cpp Tue Mar 26 16:20:28 2019 +0000 +++ b/assignment3tasks.cpp Tue Mar 26 16:48:30 2019 +0000 @@ -108,7 +108,7 @@ speedXS.lock();//lock for(int i = 0; i < SAMPLESIZE ; i++) - //speed.raw = (speed.accelvalue - speed.brakevalue)*MAXSPEED; + //speed.rawspeed = (speed.accelvalue - speed.brakevalue)*MAXSPEED; speed.average += speed.array[i]; speed.average = (speed.average / SAMPLESIZE); @@ -136,4 +136,80 @@ Thread::wait((int)delay); } +} + + +void task6speedmonitor() +{ + float delay = 1000 / TASKFREQ6; + while(true){ + + carstateXS.lock(); //lock carstate + speedXS.lock(); //lock speed + + + info.odometer += (speed.rawspeed / TASKFREQ6); + uint8_t temp_enginestate = info.ENGINESTATE; + + carstateXS.unlock(); //unlock carstate + + float temp_accel = 0.0; + if(temp_enginestate != 0) + temp_accel = speed.accelvalue; + + //update speed + speed.rawspeed += (temp_accel - speed.brakevalue) * MAXSPEED; + + if(speed.rawspeed < 0) + speed.rawspeed = 0; + if(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; + + float temp = speed.rawspeed; + + // UNLOCK Speed + speedXS.unlock(); + + // Update Overspeed display + + if (temp > SPEEDLIMIT) + overspeedind = 1; + else + overspeedind = 0; + + Thread::wait((int)delay); + } +} + +void task7displayvalues() +{ + float delay = 1000 / TASKFREQ7; + while(true){ + display->cls(); + + //LOCK data + carstateXS.lock(); + //LOCK Speed + speedXS.lock(); + + display->locate(1,0); + display->printf("S_AVER: %.2f",speed.average); + display->locate(0,0); + display->printf("ODOM: %d",(int) info.odometer); + + //UNLOCK data + carstateXS.unlock(); + //UNLOCK Speed + speedXS.unlock(); + + Thread::wait((int)delay); + + + } } \ No newline at end of file