All tasks complete
Dependencies: mbed MCP23017 mbed-rtos WattBob_TextLCD
assignment3tasks.cpp
- Committer:
- aingks
- Date:
- 2019-03-26
- Revision:
- 6:abbd51d9b045
- Parent:
- 5:f5dda79b93cb
- Child:
- 7:87f7ba90fdce
File content as of revision 6:abbd51d9b045:
#include "header.h" //definitions of tasks //lock and unlock variables in struct when performing calculations //pedals AnalogIn brake_pedal(pin_analog_1); AnalogIn accel_pedal(pin_analog_2); //switches DigitalIn ngene(pin_digital_1); DigitalIn leftsw(pin_digital_2); DigitalIn rightsw(pin_digital_3); DigitalIn sidesw(pin_digital_4); //indicators DigitalOut ngeneind(pin_LED1); PwmOut leftind(pin_LED2); //was digitalout PwmOut rightind(pin_LED3);//was digitalout DigitalOut sideind(pin_LED4); //RED box lights DigitalOut brakeind(pin_LED5); DigitalOut overspeedind(pin_LED6); // extern SDATA speed; extern CARINFO info; extern SIMU_DATA sim; // LCD extern WattBob_TextLCD *display; // MUTEX extern Mutex simuXS; extern Mutex speedXS; extern Mutex carstateXS; // void task1readbrake() { float delay = 1000 / TASKFREQ1; while(true){ speedXS.lock();//lock speed.brakevalue = brake_pedal.read(); speedXS.unlock();//unlock Thread::wait( (int) delay); } } void task2readaccel() { float delay = 1000 / TASKFREQ2; while(true){ speedXS.lock();//lock speed.accelvalue = accel_pedal.read(); speedXS.unlock();//unlock Thread::wait( (int) delay); } } void task3enginestate() { float delay = 1000 / TASKFREQ3; while(true){ //lock carstateXS.lock(); uint8_t engineonoff = ngene.read(); info.ENGINESTATE = engineonoff; carstateXS.unlock(); //unlock if(engineonoff == 1){ ngeneind = 1; } else{ ngeneind = 0; } Thread::wait( (int) delay); } } void task4average() { float delay = 1000 / TASKFREQ4; while(true){ speedXS.lock();//lock for(int i = 0; i < SAMPLESIZE ; i++) //speed.raw = (speed.accelvalue - speed.brakevalue)*MAXSPEED; speed.average += speed.array[i]; speed.average = (speed.average / SAMPLESIZE); speedXS.unlock();//unlock Thread::wait( (int) delay); } } void task5brakeLED() { float delay = 1000 / TASKFREQ5; while(true){ //lock speedXS.lock(); float braketest = speed.brakevalue; speedXS.unlock();//unlock if( braketest > 0.2) // speed increase brakeind = 1; else brakeind = 0; Thread::wait((int)delay); } }