![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All tasks complete
Dependencies: mbed MCP23017 mbed-rtos WattBob_TextLCD
Diff: assignment3tasks.cpp
- Revision:
- 14:25241ed5b056
- Parent:
- 13:822b0e56ea68
- Child:
- 15:2a0cadb9b9dc
--- a/assignment3tasks.cpp Wed Mar 27 16:05:51 2019 +0000 +++ b/assignment3tasks.cpp Wed Apr 03 02:49:34 2019 +0000 @@ -43,7 +43,11 @@ extern Mutex simuXS; extern Mutex speedXS; extern Mutex carstateXS; -// + +//Mail +extern Mail<SIMU_DATA, 16> mail_box; + + //serial port Serial PC(USBTX, USBRX); @@ -215,7 +219,7 @@ - Thread::wait(500); + Thread::wait(delay); } @@ -312,10 +316,10 @@ rightind = rightsw; if (leftsw == 1 && rightsw == 1){ - carstateXS.lock(); - leftind = 0; - rightind = 0; // current issue :just stopping here - carstateXS.unlock(); + carstateXS.lock(); + leftind = 0; + rightind = 0; // current issue :just stopping here + carstateXS.unlock(); } if (count == 2||count == 4){ // flash indicators every second carstateXS.lock(); @@ -344,30 +348,67 @@ { while(true) { - speedXS.lock(); - - PC.printf("SPEED: %.1f\r\n",speed.rawspeed); - PC.printf("BRAKE: %.1f\r\n",speed.brakevalue); - PC.printf("ACCELEROMETER: %.1f\r\n",speed.accelvalue); - - speedXS.unlock(); - - carstateXS.lock(); - - PC.printf("LEFT INDICATOR : %.1f\r\n",info.leftind); - PC.printf("RIGHT INDICATOR : %.1f\r\n",info.rightind); - - carstateXS.unlock(); - - float delay = 1000/ TASKFREQX; - Thread:: wait((int)delay); + speedXS.lock(); + + PC.printf("SPEED: %.1f\r\n",speed.rawspeed); + PC.printf("BRAKE: %.1f\r\n",speed.brakevalue); + PC.printf("ACCELEROMETER: %.1f\r\n",speed.accelvalue); + + speedXS.unlock(); + + carstateXS.lock(); + + PC.printf("LEFT INDICATOR : %.1f\r\n",info.leftind); + PC.printf("RIGHT INDICATOR : %.1f\r\n",info.rightind); + + carstateXS.unlock(); + + float delay = 1000/ TASKFREQX; + Thread:: wait((int)delay); } } + + +//mail queue +void send_thread (void) { + + while (true) { + + SIMU_DATA *mail = mail_box.alloc(); + + speedXS.lock(); + mail->brakevalue = speed.brakevalue; + mail->accelvalue = speed.accelvalue; + mail->rawspeed = speed.rawspeed; + speedXS.unlock(); + + carstateXS.lock(); + mail->odometer = info.odometer; + carstateXS.unlock(); + + mail_box.put(mail); + + //float delay = 1000/ MailQueue; + Thread::wait(1000); + } +} + //////////////////////////////////// + + + + + + + + + + + /*void IndicatorsCheck(){ LeftIndicatorLight = LeftIndicatorSwitch; RightIndicatorLight = RightIndicatorSwitch;