homework 7
Dependencies: mbed-rtos mbed C12832_lcd LM75B
Diff: main.cpp
- Revision:
- 67:1d9c85a4c3c1
- Parent:
- 66:4a0006fa5cc1
- Child:
- 68:cbebcfc948aa
diff -r 4a0006fa5cc1 -r 1d9c85a4c3c1 main.cpp --- a/main.cpp Wed Sep 11 17:28:46 2013 +0000 +++ b/main.cpp Wed Sep 11 18:00:47 2013 +0000 @@ -23,8 +23,8 @@ #define TEMPCLOCKS 1 // temperature-measuring period in S. #define PIPEDATASIZE 8 // dimension of tPipeData. #define THREAD_1_WAITmS 400 // thread 1 wait in mS. - #define THREAD_2_WAITmS 400 // thread 2 wait in mS. - #define THREAD_3_WAITmS 400 // thread 3 wait in mS. + #define THREAD_2_WAITmS 20 // LCD thread wait. + #define THREAD_3_WAITmS 80 // thread 3 wait in mS. #define THREAD_4_WAITmS 1 // thread 4 wait in mS. #define THREAD_5_WAITmS 400 // thread 5 wait in mS. #define HB_MODULO 1024 // heartbeat modulo divisor. @@ -185,14 +185,8 @@ { int dMessage; // message. - - - while(1) // thread loop. - { - - - + { //--- // TOTAL TIME CONTROL. // encoded integers will be sent, @@ -201,21 +195,19 @@ if (gtButtons.cLeftButton) // total time increment button. { dMessage = MSG_INC_TIME; // set message. -//pc.printf("\n\r before."); queueModTotalTime.put((int *) dMessage);// pretend it's a pointer. -//pc.printf("\n\r after."); gtButtons.cLeftButton = 0; // clear the button state. - pc.printf("\n\r time increment button."); +// pc.printf("\n\r time increment button."); } -//pc.printf("\n\r 002"); + if (gtButtons.cRightButton) // total time decrement button. { dMessage = MSG_DEC_TIME; // set message. queueModTotalTime.put((int *) dMessage);// pretend it's a pointer. gtButtons.cRightButton = 0; // clear the button state. - pc.printf("\n\r time decrement button."); + // pc.printf("\n\r time decrement button."); } - //pc.printf("\n\r 003"); + //--- // COOK-STATE FSM. if (gtButtons.cTopButton) // start-cook button. @@ -224,29 +216,24 @@ queueUpdateFSM.put((int *) dMessage); // pretend it's a pointer. gtButtons.cTopButton = 0; // clear the button state. } -//pc.printf("\n\r 004"); + if (gtButtons.cBottomButton) // stop-cook button. { dMessage = MSG_STOP; // set message. queueUpdateFSM.put((int *) dMessage); // pretend it's a pointer. gtButtons.cBottomButton = 0; // clear the button state. } - //pc.printf("\n\r 005"); + if (gtButtons.cCenterButton) // door-state-toggle. { dMessage = gtButtons.cDoorOpen; // determined in ISR. queueUpdateFSM.put((int *) dMessage); // pretend it's a pointer. gtButtons.cCenterButton = 0; // clear the button state. } - //pc.printf("\n\r 006"); - //--- Thread::wait(THREAD_4_WAITmS); // multitasking. - -//pc.printf("\n\r 007"); } // thread loop. - } // threadButtonStateManager. /*----------------------------------------------//----------------------------*/ // the incoming messages are mutually-exclusive. @@ -497,18 +484,51 @@ /*----------------------------------------------//----------------------------*/ void LCDthread(void const *args) // LCD display thread. { + + static int dLCDtotalCookTimeSec = 0; // sample current values. + static int dCookTimeRemainingSec = 0; + static float fLCDcelsius = 0.0; + + // remember previous values. + static int dLCDtotalCookTimeSecLast = 0; + static int dCookTimeRemainingSecLast = 0; + static float fLCDcelsiusLast = 0.0; + while(1) // thread loop. { - lcd.cls(); // clear the display. + // don't allow the values to + // change in the middle of the + // below else the anti-blink + // code won't work. + dLCDtotalCookTimeSec = gdLCDtotalCookTimeSec; + dCookTimeRemainingSec = gdCookTimeRemainingSec; + fLCDcelsius = gfLCDcelsius; + + + // clear display only when + // necessary, in order to avoid + // 'blinkieness'. + if (dLCDtotalCookTimeSec != dLCDtotalCookTimeSecLast || + dCookTimeRemainingSec != dCookTimeRemainingSecLast || + fLCDcelsius != fLCDcelsiusLast) + { + lcd.cls(); + pc.printf("\n\r cleared LCD."); + } LCD1; // line 1. - lcd.printf(" total cook time: %d",gdLCDtotalCookTimeSec); + lcd.printf(" total cook time: %d",dLCDtotalCookTimeSec); LCD2; // line 2. - lcd.printf(" remaing cook time: %d",gdCookTimeRemainingSec); + lcd.printf(" remaing cook time: %d",dCookTimeRemainingSec); LCD3; // line 3. - lcd.printf(" temperature : %5.3f",gfLCDcelsius); + lcd.printf(" temperature : %5.3f",fLCDcelsius); + + // pipeline variables. + dLCDtotalCookTimeSecLast = dLCDtotalCookTimeSec; + dCookTimeRemainingSecLast = dCookTimeRemainingSec; + fLCDcelsiusLast = fLCDcelsius; Thread::wait(THREAD_2_WAITmS); // multitasking. } // thread loop.