homework 7

Dependencies:   mbed-rtos mbed C12832_lcd LM75B

Committer:
gatedClock
Date:
Thu Sep 12 04:46:18 2013 +0000
Revision:
81:12bc26973cb8
Parent:
80:e3e1a2161435
Child:
82:73fa3fe8a217
cleanup.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gatedClock 0:fcca4db7b32a 1 /*----------------------------------------------//------------------------------
gatedClock 0:fcca4db7b32a 2 student : m-moore
gatedClock 0:fcca4db7b32a 3 class : rtos
gatedClock 10:2b0a9fc39109 4 directory : RTOS_HW_07
gatedClock 0:fcca4db7b32a 5 file : main.cpp
gatedClock 0:fcca4db7b32a 6 ----description---------------------------------//------------------------------
gatedClock 70:7c0743c28b11 7 gotchyas
gatedClock 70:7c0743c28b11 8 1. using pc.printf inside a ticker routine will freeze the routine.
gatedClock 71:4a5f256ecf7c 9 2. using queues (get, put) will not work within a ticker routine.
gatedClock 76:74c454c9d75b 10 3. Ticker has a bug. http://mbed.org/questions/1563/Mbed-Tickerfunction-hangs-system-from-re/
gatedClock 80:e3e1a2161435 11
gatedClock 80:e3e1a2161435 12 improvements
gatedClock 80:e3e1a2161435 13 countdown timer needs to be sync'd to start button press.
gatedClock 80:e3e1a2161435 14
gatedClock 80:e3e1a2161435 15
gatedClock 0:fcca4db7b32a 16 -----includes-----------------------------------//----------------------------*/
gatedClock 0:fcca4db7b32a 17 #include "mbed.h" // mbed class.
gatedClock 10:2b0a9fc39109 18 #include "rtos.h" // rtos class.
gatedClock 39:4e7e4d935a87 19 #include "LM75B.h" // thermometer class.
gatedClock 10:2b0a9fc39109 20 #include "C12832_lcd.h" // LCD class.
gatedClock 0:fcca4db7b32a 21 //---defines------------------------------------//------------------------------
gatedClock 9:cfdb9aa5857c 22 #define LCD1 lcd.locate(0, 0); // LCD line 1.
gatedClock 9:cfdb9aa5857c 23 #define LCD2 lcd.locate(0,11); // LCD line 2.
gatedClock 9:cfdb9aa5857c 24 #define LCD3 lcd.locate(0,22); // LCD line 3.
gatedClock 9:cfdb9aa5857c 25
gatedClock 10:2b0a9fc39109 26
gatedClock 66:4a0006fa5cc1 27 #define DEBOUNCEmS 16 // debounce wait in mS.
gatedClock 19:92b11e30aaaf 28 #define uS_TIMEOUT 100 // Timer uS timeout.
gatedClock 19:92b11e30aaaf 29 #define LBSIG 1 // left button signal code.
gatedClock 33:34c1bef3c4ff 30 #define PIPEuS 1000 // pipeline clock period.
gatedClock 19:92b11e30aaaf 31 #define SLOWCLOCKuS 500000 // slow-clock period.
gatedClock 39:4e7e4d935a87 32 #define TEMPCLOCKS 1 // temperature-measuring period in S.
gatedClock 26:bff592483cb1 33 #define PIPEDATASIZE 8 // dimension of tPipeData.
gatedClock 44:d16e813e61ef 34 #define THREAD_1_WAITmS 400 // thread 1 wait in mS.
gatedClock 67:1d9c85a4c3c1 35 #define THREAD_2_WAITmS 20 // LCD thread wait.
gatedClock 67:1d9c85a4c3c1 36 #define THREAD_3_WAITmS 80 // thread 3 wait in mS.
gatedClock 66:4a0006fa5cc1 37 #define THREAD_4_WAITmS 1 // thread 4 wait in mS.
gatedClock 78:7df160e0db7b 38 #define THREAD_5_WAITmS 1 // FSM thread wait.
gatedClock 44:d16e813e61ef 39 #define HB_MODULO 1024 // heartbeat modulo divisor.
gatedClock 50:2928c3cbdcc3 40
gatedClock 54:b0e7352d2516 41 #define MSG_INC_TIME 0x01
gatedClock 54:b0e7352d2516 42 #define MSG_DEC_TIME 0x02
gatedClock 58:ec630b6dd9b1 43 #define MSG_START 0x04
gatedClock 58:ec630b6dd9b1 44 #define MSG_STOP 0x08
gatedClock 58:ec630b6dd9b1 45 #define MSG_OPEN 0x10
gatedClock 58:ec630b6dd9b1 46 #define MSG_CLOSED 0x20
gatedClock 57:0432c68ad232 47
gatedClock 78:7df160e0db7b 48 #define FSM_IDLE 0x01 // cook-state state-machine.
gatedClock 78:7df160e0db7b 49 #define FSM_COOK 0x02 // cook-state state-machine.
gatedClock 78:7df160e0db7b 50 #define FSM_PAUSE 0x04 // cook-state state-machine.
gatedClock 78:7df160e0db7b 51 #define FSM_CONTINUE 0x08 // cook-state state-machine.
gatedClock 78:7df160e0db7b 52 #define FSM_DONE 0x10 // cook-state state-machine.
gatedClock 65:e39360da5929 53
gatedClock 71:4a5f256ecf7c 54 #define RT_PRELOAD 0x01 // remaining-time preload.
gatedClock 71:4a5f256ecf7c 55 #define RT_DECREMENT 0x02 // remaining-time decrement.
gatedClock 71:4a5f256ecf7c 56 #define RT_PAUSE 0x03 // remaining-time don't change.
gatedClock 71:4a5f256ecf7c 57 #define RT_CLEAR 0x04 // remaining-time set to zero.
gatedClock 71:4a5f256ecf7c 58
gatedClock 65:e39360da5929 59 #define DEBUG1 // debug preprocessor control.
gatedClock 0:fcca4db7b32a 60 //--global_definitions--------------------------//------------------------------
gatedClock 26:bff592483cb1 61 struct tButtons // button ISR updates.
gatedClock 26:bff592483cb1 62 {
gatedClock 26:bff592483cb1 63 char cLeftButton; // cooktime +60S.
gatedClock 26:bff592483cb1 64 char cRightButton; // cooktime -60S.
gatedClock 26:bff592483cb1 65 char cTopButton; // start cook.
gatedClock 26:bff592483cb1 66 char cBottomButton; // stop cook.
gatedClock 58:ec630b6dd9b1 67 char cCenterButton; // center button pressed.
gatedClock 53:8c2baf5623c8 68 char cDoorOpen; // door open.
gatedClock 26:bff592483cb1 69 };
gatedClock 34:b449d2a7c786 70
gatedClock 71:4a5f256ecf7c 71 struct tRemainingTime // remaining time related.
gatedClock 71:4a5f256ecf7c 72 {
gatedClock 71:4a5f256ecf7c 73 char cControl; // countdown control.
gatedClock 71:4a5f256ecf7c 74 int dTotalTime; // initialize to this.
gatedClock 71:4a5f256ecf7c 75 int dRemainingTime; // the countdown value.
gatedClock 71:4a5f256ecf7c 76 };
gatedClock 71:4a5f256ecf7c 77
gatedClock 80:e3e1a2161435 78 struct tLCD // LCD related.
gatedClock 80:e3e1a2161435 79 {
gatedClock 80:e3e1a2161435 80 int dTotalCookTime; // display time in seconds.
gatedClock 80:e3e1a2161435 81 int dRemainingTime; // display time in seconds.
gatedClock 80:e3e1a2161435 82 float fCelsius; // temperature in celsius.
gatedClock 80:e3e1a2161435 83 };
gatedClock 80:e3e1a2161435 84
gatedClock 80:e3e1a2161435 85
gatedClock 80:e3e1a2161435 86
gatedClock 61:8026a9fc0cf1 87 Queue<int, 1> queueModTotalTime; // message to modify total time.
gatedClock 61:8026a9fc0cf1 88 Queue<int, 1> queueUpdateFSM; // message to inform FSM.
gatedClock 61:8026a9fc0cf1 89 Queue<int, 1> queueUpdateRemainingTime; // message to update remaining time.
gatedClock 71:4a5f256ecf7c 90 Queue<int, 1> queueSetRemainingTime; // tell countdown it's start time.
gatedClock 69:55b836e8ced7 91 Queue<int, 1> queueFSMnewState; // latest FSM state.
gatedClock 0:fcca4db7b32a 92 //--global_variables----------------------------//------------------------------
gatedClock 26:bff592483cb1 93 char gcSignalWaitEnable; // 1 to wait on a signal.
gatedClock 26:bff592483cb1 94 char gcSlowClock; // slow-clock signal.
gatedClock 33:34c1bef3c4ff 95 char gcInitializePipeline; // 1 to initialize pipeline state.
gatedClock 39:4e7e4d935a87 96 float gfCelsius; // from thermometer.
gatedClock 42:266d5bbbfd19 97 float gfLCDcelsius; // feed into LCD.
gatedClock 42:266d5bbbfd19 98 int gdLCDtotalCookTimeSec; // feed into LCD.
gatedClock 42:266d5bbbfd19 99 int gdCookTimeRemainingSec; // feed into LCD.
gatedClock 26:bff592483cb1 100 tButtons gtButtons; // ISR button updates.
gatedClock 70:7c0743c28b11 101
gatedClock 71:4a5f256ecf7c 102 tRemainingTime giRemainingTime; // structure instance.
gatedClock 80:e3e1a2161435 103 tLCD giLCD; // structure instance.
gatedClock 71:4a5f256ecf7c 104
gatedClock 70:7c0743c28b11 105 int gdDiagTotalTime;
gatedClock 0:fcca4db7b32a 106 //--global_instances----------------------------//------------------------------
gatedClock 55:17f3354da63a 107 Serial pc(USBTX, USBRX); // PuTTY terminal communication.
gatedClock 39:4e7e4d935a87 108 LM75B temperature(p28,p27); // on-board thermometer.
gatedClock 9:cfdb9aa5857c 109 C12832_LCD lcd; // LCD object.
gatedClock 53:8c2baf5623c8 110 DigitalOut led0(LED4); // magnetron.
gatedClock 39:4e7e4d935a87 111 DigitalOut led1(LED3);
gatedClock 39:4e7e4d935a87 112 DigitalOut led2(LED2);
gatedClock 39:4e7e4d935a87 113 DigitalOut led3(LED1);
gatedClock 0:fcca4db7b32a 114
gatedClock 0:fcca4db7b32a 115 InterruptIn iJoyStickUp (p15); // joystick up rising edge.
gatedClock 0:fcca4db7b32a 116 InterruptIn iJoyStickDown (p12); // joystick down rising edge.
gatedClock 0:fcca4db7b32a 117 InterruptIn iJoyStickLeft (p13); // joystick left rising edge.
gatedClock 0:fcca4db7b32a 118 InterruptIn iJoyStickRight (p16); // joystick right rising edge.
gatedClock 0:fcca4db7b32a 119 InterruptIn iJoyStickCenter(p14); // 1 if joystick middle pressed.
gatedClock 66:4a0006fa5cc1 120
gatedClock 66:4a0006fa5cc1 121 Timer debounceTimer; // button debounce timer.
gatedClock 0:fcca4db7b32a 122
gatedClock 50:2928c3cbdcc3 123 Ticker tickerButtonStateManager; // manage the button states.
gatedClock 19:92b11e30aaaf 124 Ticker tickerSlowClock; // generate a ~1Hz clock.
gatedClock 77:73e4fd83642f 125 Ticker tickerCookCountdown; // remaining cook time.
gatedClock 63:63f362bcc2ac 126
gatedClock 63:63f362bcc2ac 127 // Timer timerFSMdone; // duration of FSM 'done' state.
gatedClock 40:7afff79f0d8b 128
gatedClock 0:fcca4db7b32a 129 //-------prototypes-----------------------------//------------------------------
gatedClock 49:56f790977983 130
gatedClock 19:92b11e30aaaf 131 void slowClock(); // 1Hz or thereabouts.
gatedClock 49:56f790977983 132
gatedClock 9:cfdb9aa5857c 133 void initialization(); // initialize settings.
gatedClock 13:21f27ba467c2 134
gatedClock 13:21f27ba467c2 135 void ISRleftButtonRising(); // cook-time increase.
gatedClock 13:21f27ba467c2 136 void ISRleftButtonFalling(); // button-release debounce.
gatedClock 13:21f27ba467c2 137 void ISRrightButtonRising(); // cook-time decrease.
gatedClock 13:21f27ba467c2 138 void ISRrightButtonFalling(); // button-release debounce.
gatedClock 13:21f27ba467c2 139 void ISRtopButtonRising(); // cook start.
gatedClock 13:21f27ba467c2 140 void ISRtopButtonFalling(); // button-release debounce.
gatedClock 13:21f27ba467c2 141 void ISRbottomButtonRising(); // cook stop.
gatedClock 13:21f27ba467c2 142 void ISRbottomButtonFalling(); // button-release debounce.
gatedClock 13:21f27ba467c2 143 void ISRcenterButtonRising(); // door state toggle.
gatedClock 13:21f27ba467c2 144 void ISRcenterButtonFalling(); // button-release debounce.
gatedClock 16:db7f0b3b2605 145 void disableSignalWaiting(); // break from signal waiting.
gatedClock 39:4e7e4d935a87 146
gatedClock 54:b0e7352d2516 147 void threadButtonStateManager(void const *args);
gatedClock 50:2928c3cbdcc3 148 void threadTotalTimeControl(void const *args);
gatedClock 57:0432c68ad232 149 void threadCookStateFSM(void const *args);
gatedClock 71:4a5f256ecf7c 150 void tickCookRemainingTime(); // remaining time countdown.
gatedClock 50:2928c3cbdcc3 151
gatedClock 40:7afff79f0d8b 152 void temperatureThread(void const *args); // temperature measurement.
gatedClock 42:266d5bbbfd19 153 void LCDthread (void const *args); // LCD display thread.
gatedClock 0:fcca4db7b32a 154 //==============================================//==============================
gatedClock 0:fcca4db7b32a 155 int main(void)
gatedClock 0:fcca4db7b32a 156 {
gatedClock 16:db7f0b3b2605 157 char cLeftButtonState; // 1 means button was pressed.
gatedClock 16:db7f0b3b2605 158
gatedClock 16:db7f0b3b2605 159
gatedClock 16:db7f0b3b2605 160
gatedClock 14:d3bb343cd5b2 161 iJoyStickLeft.rise (&ISRleftButtonRising);
gatedClock 14:d3bb343cd5b2 162 iJoyStickLeft.fall (&ISRleftButtonFalling);
gatedClock 9:cfdb9aa5857c 163
gatedClock 14:d3bb343cd5b2 164 iJoyStickRight.rise(&ISRrightButtonRising);
gatedClock 14:d3bb343cd5b2 165 iJoyStickRight.fall(&ISRrightButtonFalling);
gatedClock 14:d3bb343cd5b2 166
gatedClock 14:d3bb343cd5b2 167 iJoyStickUp.rise (&ISRtopButtonRising);
gatedClock 14:d3bb343cd5b2 168 iJoyStickUp.fall (&ISRtopButtonFalling);
gatedClock 9:cfdb9aa5857c 169
gatedClock 14:d3bb343cd5b2 170 iJoyStickDown.rise (&ISRbottomButtonRising);
gatedClock 14:d3bb343cd5b2 171 iJoyStickDown.fall (&ISRbottomButtonFalling);
gatedClock 7:9fbd1d540863 172
gatedClock 14:d3bb343cd5b2 173 iJoyStickCenter.rise(&ISRcenterButtonRising);
gatedClock 14:d3bb343cd5b2 174 iJoyStickCenter.fall(&ISRcenterButtonFalling);
gatedClock 9:cfdb9aa5857c 175
gatedClock 66:4a0006fa5cc1 176 debounceTimer.start(); // kick-off debounce timer.
gatedClock 66:4a0006fa5cc1 177
gatedClock 33:34c1bef3c4ff 178 gcInitializePipeline = 1; // tell pipeline to initialize.
gatedClock 16:db7f0b3b2605 179
gatedClock 9:cfdb9aa5857c 180 initialization(); // initialize variables.
gatedClock 21:b794d189c36b 181 gcSlowClock = 0;
gatedClock 44:d16e813e61ef 182 led1 = 0;
gatedClock 53:8c2baf5623c8 183 gtButtons.cDoorOpen = 0; // initialize with door closed.
gatedClock 63:63f362bcc2ac 184
gatedClock 63:63f362bcc2ac 185 // timerFSMdone.start(); // start 'done' timer.
gatedClock 49:56f790977983 186
gatedClock 70:7c0743c28b11 187 tickerSlowClock.attach_us(&slowClock ,SLOWCLOCKuS);
gatedClock 64:255295f1d782 188
gatedClock 75:c2894d531f42 189
gatedClock 77:73e4fd83642f 190 tickerCookCountdown.attach(&tickCookRemainingTime,1);
gatedClock 54:b0e7352d2516 191
gatedClock 40:7afff79f0d8b 192
gatedClock 70:7c0743c28b11 193 Thread thread_1(temperatureThread ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL);
gatedClock 70:7c0743c28b11 194 Thread thread_2(LCDthread ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL);
gatedClock 70:7c0743c28b11 195 Thread thread_3(threadTotalTimeControl ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL);
gatedClock 70:7c0743c28b11 196 Thread thread_4(threadButtonStateManager,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); // was osPriorityIdle
gatedClock 70:7c0743c28b11 197 Thread thread_5(threadCookStateFSM ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL);
gatedClock 70:7c0743c28b11 198
gatedClock 66:4a0006fa5cc1 199 //Thread thread_4(threadButtonStateManager);
gatedClock 52:8ba6a0c91a89 200
gatedClock 40:7afff79f0d8b 201
gatedClock 59:5e45b5e4a874 202 // the message-receiving threads need 'else' for message-receive-timeout.
gatedClock 9:cfdb9aa5857c 203
gatedClock 14:d3bb343cd5b2 204 while(1)
gatedClock 0:fcca4db7b32a 205 {
gatedClock 75:c2894d531f42 206 // pc.printf("\n\r gdDiagTotalTime %d",gdDiagTotalTime);
gatedClock 70:7c0743c28b11 207
gatedClock 70:7c0743c28b11 208 Thread::wait(1000);
gatedClock 16:db7f0b3b2605 209
gatedClock 16:db7f0b3b2605 210
gatedClock 16:db7f0b3b2605 211
gatedClock 14:d3bb343cd5b2 212
gatedClock 0:fcca4db7b32a 213 }
gatedClock 19:92b11e30aaaf 214 }
gatedClock 19:92b11e30aaaf 215 /*----------------------------------------------//----------------------------*/
gatedClock 59:5e45b5e4a874 216
gatedClock 59:5e45b5e4a874 217 // this serves as the bottom-half for all of the button-press IRSs.
gatedClock 59:5e45b5e4a874 218 // it sends button-status messages to other threads, and it also
gatedClock 59:5e45b5e4a874 219 // clears the button-state globals to prepare them for the next
gatedClock 59:5e45b5e4a874 220 // button press.
gatedClock 59:5e45b5e4a874 221
gatedClock 59:5e45b5e4a874 222
gatedClock 54:b0e7352d2516 223 void threadButtonStateManager(void const *args)
gatedClock 50:2928c3cbdcc3 224 {
gatedClock 56:18cff6eb91db 225 int dMessage; // message.
gatedClock 50:2928c3cbdcc3 226
gatedClock 54:b0e7352d2516 227 while(1) // thread loop.
gatedClock 67:1d9c85a4c3c1 228 {
gatedClock 54:b0e7352d2516 229 //--- // TOTAL TIME CONTROL.
gatedClock 56:18cff6eb91db 230
gatedClock 56:18cff6eb91db 231 // encoded integers will be sent,
gatedClock 56:18cff6eb91db 232 // not pointers.
gatedClock 50:2928c3cbdcc3 233
gatedClock 50:2928c3cbdcc3 234 if (gtButtons.cLeftButton) // total time increment button.
gatedClock 50:2928c3cbdcc3 235 {
gatedClock 54:b0e7352d2516 236 dMessage = MSG_INC_TIME; // set message.
gatedClock 69:55b836e8ced7 237 queueModTotalTime.put((int *) dMessage,1);// pretend it's a pointer.
gatedClock 50:2928c3cbdcc3 238 gtButtons.cLeftButton = 0; // clear the button state.
gatedClock 50:2928c3cbdcc3 239 }
gatedClock 67:1d9c85a4c3c1 240
gatedClock 59:5e45b5e4a874 241 if (gtButtons.cRightButton) // total time decrement button.
gatedClock 50:2928c3cbdcc3 242 {
gatedClock 54:b0e7352d2516 243 dMessage = MSG_DEC_TIME; // set message.
gatedClock 69:55b836e8ced7 244 queueModTotalTime.put((int *) dMessage,1);// pretend it's a pointer.
gatedClock 50:2928c3cbdcc3 245 gtButtons.cRightButton = 0; // clear the button state.
gatedClock 50:2928c3cbdcc3 246 }
gatedClock 67:1d9c85a4c3c1 247
gatedClock 59:5e45b5e4a874 248 //--- // COOK-STATE FSM.
gatedClock 59:5e45b5e4a874 249
gatedClock 59:5e45b5e4a874 250 if (gtButtons.cTopButton) // start-cook button.
gatedClock 58:ec630b6dd9b1 251 {
gatedClock 59:5e45b5e4a874 252 dMessage = MSG_START; // set message.
gatedClock 69:55b836e8ced7 253 queueUpdateFSM.put((int *) dMessage,1); // pretend it's a pointer.
gatedClock 59:5e45b5e4a874 254 gtButtons.cTopButton = 0; // clear the button state.
gatedClock 58:ec630b6dd9b1 255 }
gatedClock 67:1d9c85a4c3c1 256
gatedClock 59:5e45b5e4a874 257 if (gtButtons.cBottomButton) // stop-cook button.
gatedClock 58:ec630b6dd9b1 258 {
gatedClock 59:5e45b5e4a874 259 dMessage = MSG_STOP; // set message.
gatedClock 69:55b836e8ced7 260 queueUpdateFSM.put((int *) dMessage,1); // pretend it's a pointer.
gatedClock 59:5e45b5e4a874 261 gtButtons.cBottomButton = 0; // clear the button state.
gatedClock 58:ec630b6dd9b1 262 }
gatedClock 67:1d9c85a4c3c1 263
gatedClock 59:5e45b5e4a874 264 if (gtButtons.cCenterButton) // door-state-toggle.
gatedClock 58:ec630b6dd9b1 265 {
gatedClock 59:5e45b5e4a874 266 dMessage = gtButtons.cDoorOpen; // determined in ISR.
gatedClock 69:55b836e8ced7 267 queueUpdateFSM.put((int *) dMessage,1); // pretend it's a pointer.
gatedClock 59:5e45b5e4a874 268 gtButtons.cCenterButton = 0; // clear the button state.
gatedClock 58:ec630b6dd9b1 269 }
gatedClock 59:5e45b5e4a874 270 //---
gatedClock 58:ec630b6dd9b1 271
gatedClock 54:b0e7352d2516 272 Thread::wait(THREAD_4_WAITmS); // multitasking.
gatedClock 54:b0e7352d2516 273 } // thread loop.
gatedClock 54:b0e7352d2516 274 } // threadButtonStateManager.
gatedClock 50:2928c3cbdcc3 275 /*----------------------------------------------//----------------------------*/
gatedClock 51:e5ec74c49b01 276 // the incoming messages are mutually-exclusive.
gatedClock 51:e5ec74c49b01 277 // total time controller.
gatedClock 51:e5ec74c49b01 278 void threadTotalTimeControl(void const *args)
gatedClock 50:2928c3cbdcc3 279 {
gatedClock 51:e5ec74c49b01 280 static int dTotalTime = 0; // total time variable.
gatedClock 60:e10bf95bbc96 281 int dMessage; // message.
gatedClock 51:e5ec74c49b01 282 osEvent queueEvent; // queue event.
gatedClock 70:7c0743c28b11 283 int dRC;
gatedClock 50:2928c3cbdcc3 284
gatedClock 50:2928c3cbdcc3 285 while(1) // thread loop.
gatedClock 50:2928c3cbdcc3 286 {
gatedClock 50:2928c3cbdcc3 287
gatedClock 55:17f3354da63a 288 queueEvent = queueModTotalTime.get(1); // get message.
gatedClock 51:e5ec74c49b01 289 if (queueEvent.status == osEventMessage)
gatedClock 51:e5ec74c49b01 290 {
gatedClock 56:18cff6eb91db 291 dMessage = (int) queueEvent.value.p; // interpret as integer, not pointer.
gatedClock 54:b0e7352d2516 292
gatedClock 54:b0e7352d2516 293 // increment total time.
gatedClock 56:18cff6eb91db 294 if (dMessage == MSG_INC_TIME) dTotalTime += 60;
gatedClock 54:b0e7352d2516 295
gatedClock 54:b0e7352d2516 296 // decrement total time.
gatedClock 56:18cff6eb91db 297 if (dMessage == MSG_DEC_TIME) dTotalTime -= 60;
gatedClock 65:e39360da5929 298
gatedClock 65:e39360da5929 299 // saturations.
gatedClock 65:e39360da5929 300 if (dTotalTime > 180) dTotalTime = 180;
gatedClock 65:e39360da5929 301 if (dTotalTime < 0) dTotalTime = 0;
gatedClock 65:e39360da5929 302
gatedClock 70:7c0743c28b11 303 dRC = queueSetRemainingTime.put((int *) dTotalTime,1);
gatedClock 75:c2894d531f42 304 giRemainingTime.dTotalTime = dTotalTime;
gatedClock 51:e5ec74c49b01 305 }
gatedClock 81:12bc26973cb8 306
gatedClock 50:2928c3cbdcc3 307 Thread::wait(THREAD_3_WAITmS); // multitasking.
gatedClock 50:2928c3cbdcc3 308 } // thread loop.
gatedClock 50:2928c3cbdcc3 309 } // threadTotalTimeControl.
gatedClock 33:34c1bef3c4ff 310 /*----------------------------------------------//----------------------------*/
gatedClock 81:12bc26973cb8 311
gatedClock 57:0432c68ad232 312 void threadCookStateFSM(void const *args) // cook-cycle FSM.
gatedClock 57:0432c68ad232 313 {
gatedClock 69:55b836e8ced7 314 static int dFSMstate = FSM_IDLE; // state of this FSM.
gatedClock 69:55b836e8ced7 315 static int dFSMstateLast = FSM_IDLE; // previous FSM state.
gatedClock 61:8026a9fc0cf1 316 static int dButtonState; // received button state.
gatedClock 75:c2894d531f42 317 static int dRemainingTime = 0; // received remaining time.
gatedClock 62:48e7c196e2a5 318
gatedClock 62:48e7c196e2a5 319 static int dButtonStart = 0;
gatedClock 62:48e7c196e2a5 320 static int dButtonStop = 0;
gatedClock 62:48e7c196e2a5 321 static int dDoorOpen = 0;
gatedClock 81:12bc26973cb8 322
gatedClock 81:12bc26973cb8 323 osEvent queueEvent; // from button state manager.
gatedClock 75:c2894d531f42 324
gatedClock 62:48e7c196e2a5 325
gatedClock 63:63f362bcc2ac 326
gatedClock 57:0432c68ad232 327 while(1) // thread loop.
gatedClock 57:0432c68ad232 328 {
gatedClock 81:12bc26973cb8 329
gatedClock 74:4debb8f2e21d 330 switch (dFSMstate) // cook-mode state machine.
gatedClock 62:48e7c196e2a5 331 {
gatedClock 73:44739860198b 332 case FSM_IDLE : // IDLE.
gatedClock 73:44739860198b 333 {
gatedClock 75:c2894d531f42 334 if (dFSMstate != dFSMstateLast) // if just entered state.
gatedClock 80:e3e1a2161435 335 {
gatedClock 75:c2894d531f42 336 }
gatedClock 80:e3e1a2161435 337
gatedClock 80:e3e1a2161435 338 giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
gatedClock 80:e3e1a2161435 339 giLCD.dRemainingTime = 0; // suppress remaining time display.
gatedClock 80:e3e1a2161435 340 giLCD.fCelsius = 0;
gatedClock 80:e3e1a2161435 341
gatedClock 78:7df160e0db7b 342 giRemainingTime.cControl = RT_PRELOAD;
gatedClock 76:74c454c9d75b 343 dFSMstateLast = dFSMstate; // determine next state.
gatedClock 75:c2894d531f42 344 if ((dButtonStart == 1) && (dDoorOpen == 0) && (giRemainingTime.dTotalTime > 0)) dFSMstate = FSM_COOK;
gatedClock 73:44739860198b 345 break;
gatedClock 73:44739860198b 346 }
gatedClock 73:44739860198b 347 case FSM_COOK : // COOK.
gatedClock 73:44739860198b 348 {
gatedClock 75:c2894d531f42 349 if (dFSMstate != dFSMstateLast) // if just entered state.
gatedClock 75:c2894d531f42 350 {
gatedClock 75:c2894d531f42 351 giRemainingTime.cControl = RT_DECREMENT;
gatedClock 75:c2894d531f42 352 }
gatedClock 80:e3e1a2161435 353
gatedClock 80:e3e1a2161435 354 giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
gatedClock 80:e3e1a2161435 355 giLCD.dRemainingTime = giRemainingTime.dRemainingTime;
gatedClock 80:e3e1a2161435 356 giLCD.fCelsius = 0;
gatedClock 80:e3e1a2161435 357
gatedClock 80:e3e1a2161435 358
gatedClock 76:74c454c9d75b 359
gatedClock 76:74c454c9d75b 360 dFSMstateLast = dFSMstate; // determine next state.
gatedClock 78:7df160e0db7b 361 if ((dDoorOpen == 1) && (dRemainingTime > 0)) dFSMstate = FSM_PAUSE;
gatedClock 78:7df160e0db7b 362 else
gatedClock 76:74c454c9d75b 363 if (dButtonStop) dFSMstate = FSM_IDLE;
gatedClock 78:7df160e0db7b 364 else
gatedClock 78:7df160e0db7b 365 if (dRemainingTime <= 0) dFSMstate = FSM_DONE;
gatedClock 73:44739860198b 366 break;
gatedClock 73:44739860198b 367 }
gatedClock 73:44739860198b 368 case FSM_PAUSE : // PAUSE.
gatedClock 73:44739860198b 369 {
gatedClock 75:c2894d531f42 370
gatedClock 75:c2894d531f42 371 if (dFSMstate != dFSMstateLast) // if just entered state.
gatedClock 75:c2894d531f42 372 {
gatedClock 75:c2894d531f42 373 }
gatedClock 80:e3e1a2161435 374
gatedClock 80:e3e1a2161435 375
gatedClock 80:e3e1a2161435 376 giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
gatedClock 80:e3e1a2161435 377 giLCD.dRemainingTime = giRemainingTime.dRemainingTime;
gatedClock 80:e3e1a2161435 378 giLCD.fCelsius = 0;
gatedClock 80:e3e1a2161435 379
gatedClock 80:e3e1a2161435 380
gatedClock 75:c2894d531f42 381 giRemainingTime.cControl = RT_PAUSE;
gatedClock 75:c2894d531f42 382 // determine next state.
gatedClock 75:c2894d531f42 383 dFSMstateLast = dFSMstate;
gatedClock 78:7df160e0db7b 384 if ((dButtonStart == 1) && (dDoorOpen == 0) && (giRemainingTime.dTotalTime > 0)) dFSMstate = FSM_CONTINUE;
gatedClock 75:c2894d531f42 385 else
gatedClock 78:7df160e0db7b 386 if (dButtonStop) dFSMstate = FSM_IDLE;
gatedClock 73:44739860198b 387 break;
gatedClock 73:44739860198b 388 }
gatedClock 78:7df160e0db7b 389
gatedClock 78:7df160e0db7b 390
gatedClock 79:4286319e48b4 391 case FSM_CONTINUE : // CONTINUE.
gatedClock 78:7df160e0db7b 392 {
gatedClock 78:7df160e0db7b 393
gatedClock 78:7df160e0db7b 394 if (dFSMstate != dFSMstateLast) // if just entered state.
gatedClock 78:7df160e0db7b 395 {
gatedClock 78:7df160e0db7b 396 }
gatedClock 80:e3e1a2161435 397
gatedClock 80:e3e1a2161435 398
gatedClock 80:e3e1a2161435 399 giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
gatedClock 80:e3e1a2161435 400 giLCD.dRemainingTime = giRemainingTime.dRemainingTime;
gatedClock 80:e3e1a2161435 401 giLCD.fCelsius = 0;
gatedClock 80:e3e1a2161435 402
gatedClock 80:e3e1a2161435 403
gatedClock 78:7df160e0db7b 404 giRemainingTime.cControl = RT_DECREMENT;
gatedClock 78:7df160e0db7b 405 // determine next state.
gatedClock 78:7df160e0db7b 406 dFSMstateLast = dFSMstate;
gatedClock 78:7df160e0db7b 407 if (dRemainingTime <= 0) dFSMstate = FSM_DONE;
gatedClock 78:7df160e0db7b 408 else
gatedClock 78:7df160e0db7b 409 if (dButtonStop) dFSMstate = FSM_IDLE;
gatedClock 79:4286319e48b4 410 else
gatedClock 79:4286319e48b4 411 if ((dDoorOpen == 1) && (dRemainingTime > 0)) dFSMstate = FSM_PAUSE;
gatedClock 78:7df160e0db7b 412 break;
gatedClock 78:7df160e0db7b 413 }
gatedClock 78:7df160e0db7b 414
gatedClock 78:7df160e0db7b 415
gatedClock 78:7df160e0db7b 416
gatedClock 73:44739860198b 417 case FSM_DONE : // DONE.
gatedClock 73:44739860198b 418 {
gatedClock 75:c2894d531f42 419
gatedClock 75:c2894d531f42 420 if (dFSMstate != dFSMstateLast) // if just entered state.
gatedClock 75:c2894d531f42 421 {
gatedClock 75:c2894d531f42 422 }
gatedClock 80:e3e1a2161435 423
gatedClock 80:e3e1a2161435 424
gatedClock 80:e3e1a2161435 425 giLCD.dTotalCookTime = giRemainingTime.dTotalTime;
gatedClock 80:e3e1a2161435 426 giLCD.dRemainingTime = giRemainingTime.dRemainingTime;
gatedClock 80:e3e1a2161435 427 giLCD.fCelsius = 0;
gatedClock 80:e3e1a2161435 428
gatedClock 80:e3e1a2161435 429
gatedClock 80:e3e1a2161435 430
gatedClock 75:c2894d531f42 431 giRemainingTime.cControl = RT_CLEAR;
gatedClock 75:c2894d531f42 432 // determine next state.
gatedClock 75:c2894d531f42 433 dFSMstateLast = dFSMstate;
gatedClock 74:4debb8f2e21d 434 dFSMstate = FSM_IDLE;
gatedClock 73:44739860198b 435 break;
gatedClock 73:44739860198b 436 }
gatedClock 73:44739860198b 437
gatedClock 73:44739860198b 438 default : {dFSMstate = FSM_IDLE; break;}
gatedClock 73:44739860198b 439
gatedClock 62:48e7c196e2a5 440 }
gatedClock 73:44739860198b 441
gatedClock 63:63f362bcc2ac 442
gatedClock 75:c2894d531f42 443
gatedClock 75:c2894d531f42 444 queueEvent = queueUpdateFSM.get(1); // threadButtonStateManager
gatedClock 60:e10bf95bbc96 445 if (queueEvent.status == osEventMessage)// update state variable.
gatedClock 60:e10bf95bbc96 446 {
gatedClock 61:8026a9fc0cf1 447 // interpret as integer, not pointer.
gatedClock 61:8026a9fc0cf1 448 dButtonState = (int) queueEvent.value.p;
gatedClock 63:63f362bcc2ac 449
gatedClock 75:c2894d531f42 450
gatedClock 69:55b836e8ced7 451
gatedClock 63:63f362bcc2ac 452 if (dButtonState == MSG_START)
gatedClock 63:63f362bcc2ac 453 {
gatedClock 63:63f362bcc2ac 454 dButtonStart = 1;
gatedClock 63:63f362bcc2ac 455 dButtonStop = 0;
gatedClock 79:4286319e48b4 456
gatedClock 79:4286319e48b4 457 // if the door is open, ignore
gatedClock 79:4286319e48b4 458 // and cancel 'start' state.
gatedClock 79:4286319e48b4 459 if (dDoorOpen) dButtonStart = 0;
gatedClock 63:63f362bcc2ac 460 }
gatedClock 63:63f362bcc2ac 461 if (dButtonState == MSG_STOP)
gatedClock 63:63f362bcc2ac 462 {
gatedClock 63:63f362bcc2ac 463 dButtonStart = 0;
gatedClock 63:63f362bcc2ac 464 dButtonStop = 1;
gatedClock 63:63f362bcc2ac 465 }
gatedClock 63:63f362bcc2ac 466
gatedClock 63:63f362bcc2ac 467 if (dButtonState == MSG_OPEN)
gatedClock 63:63f362bcc2ac 468 {
gatedClock 79:4286319e48b4 469 // if the door opens, clear current 'start' state.
gatedClock 79:4286319e48b4 470 dDoorOpen = 1;
gatedClock 79:4286319e48b4 471 dButtonStart = 0;
gatedClock 63:63f362bcc2ac 472 }
gatedClock 63:63f362bcc2ac 473
gatedClock 63:63f362bcc2ac 474 if (dButtonState == MSG_CLOSED)
gatedClock 63:63f362bcc2ac 475 {
gatedClock 63:63f362bcc2ac 476 dDoorOpen = 0;
gatedClock 63:63f362bcc2ac 477 }
gatedClock 63:63f362bcc2ac 478
gatedClock 61:8026a9fc0cf1 479 }
gatedClock 75:c2894d531f42 480
gatedClock 75:c2894d531f42 481 // fetch from global scope.
gatedClock 75:c2894d531f42 482 dRemainingTime = giRemainingTime.dRemainingTime;
gatedClock 69:55b836e8ced7 483
gatedClock 75:c2894d531f42 484 // pipeline variable.
gatedClock 57:0432c68ad232 485 Thread::wait(THREAD_5_WAITmS); // multitasking.
gatedClock 57:0432c68ad232 486 } // thread loop.
gatedClock 57:0432c68ad232 487 } // threadCookStateFSM.
gatedClock 57:0432c68ad232 488 /*----------------------------------------------//----------------------------*/
gatedClock 19:92b11e30aaaf 489 void slowClock(void) // 1Hz or thereabouts.
gatedClock 19:92b11e30aaaf 490 {
gatedClock 24:d39516e077ea 491 gcSlowClock = !gcSlowClock; // toggle clock.
gatedClock 19:92b11e30aaaf 492 }
gatedClock 19:92b11e30aaaf 493 /*----------------------------------------------//----------------------------*/
gatedClock 0:fcca4db7b32a 494 void initialization(void) // program initializations.
gatedClock 0:fcca4db7b32a 495 {
gatedClock 16:db7f0b3b2605 496 gcSignalWaitEnable = 1;
gatedClock 0:fcca4db7b32a 497 }
gatedClock 0:fcca4db7b32a 498 /*----------------------------------------------//----------------------------*/
gatedClock 26:bff592483cb1 499 void ISRleftButtonRising(void) // cooktime plus 60s.
gatedClock 1:9188d4668a88 500 {
gatedClock 66:4a0006fa5cc1 501 if (debounceTimer.read_ms() > DEBOUNCEmS)
gatedClock 26:bff592483cb1 502 gtButtons.cLeftButton = 1; // detect left button.
gatedClock 9:cfdb9aa5857c 503
gatedClock 66:4a0006fa5cc1 504 debounceTimer.reset(); // begin debounce period.
gatedClock 11:9cae003da12b 505 }
gatedClock 1:9188d4668a88 506 /*----------------------------------------------//----------------------------*/
gatedClock 15:5eaa2ab1d00d 507 void ISRleftButtonFalling(void) // button-release debounce.
gatedClock 1:9188d4668a88 508 {
gatedClock 66:4a0006fa5cc1 509 debounceTimer.reset(); // begin debounce period.
gatedClock 11:9cae003da12b 510 }
gatedClock 2:665ffa57031f 511 /*----------------------------------------------//----------------------------*/
gatedClock 26:bff592483cb1 512 void ISRrightButtonRising(void) // cooktime -60s.
gatedClock 12:e40272e1fd8f 513 {
gatedClock 66:4a0006fa5cc1 514 if (debounceTimer.read_ms() > DEBOUNCEmS)
gatedClock 26:bff592483cb1 515 gtButtons.cRightButton = 1; // detect right button.
gatedClock 12:e40272e1fd8f 516
gatedClock 66:4a0006fa5cc1 517 debounceTimer.reset(); // begin debounce period.
gatedClock 12:e40272e1fd8f 518 }
gatedClock 12:e40272e1fd8f 519 /*----------------------------------------------//----------------------------*/
gatedClock 15:5eaa2ab1d00d 520 void ISRrightButtonFalling(void) // button-release debounce.
gatedClock 12:e40272e1fd8f 521 {
gatedClock 66:4a0006fa5cc1 522 debounceTimer.reset(); // begin debounce period.
gatedClock 12:e40272e1fd8f 523 }
gatedClock 12:e40272e1fd8f 524 /*----------------------------------------------//----------------------------*/
gatedClock 26:bff592483cb1 525 void ISRtopButtonRising(void) // cook start.
gatedClock 12:e40272e1fd8f 526 {
gatedClock 66:4a0006fa5cc1 527 if (debounceTimer.read_ms() > DEBOUNCEmS)
gatedClock 26:bff592483cb1 528 gtButtons.cTopButton = 1; // detect top button.
gatedClock 12:e40272e1fd8f 529
gatedClock 66:4a0006fa5cc1 530 debounceTimer.reset(); // begin debounce period.
gatedClock 12:e40272e1fd8f 531 }
gatedClock 12:e40272e1fd8f 532 /*----------------------------------------------//----------------------------*/
gatedClock 15:5eaa2ab1d00d 533 void ISRtopButtonFalling(void) // button-release debounce.
gatedClock 12:e40272e1fd8f 534 {
gatedClock 66:4a0006fa5cc1 535 debounceTimer.reset(); // begin debounce period.
gatedClock 12:e40272e1fd8f 536 }
gatedClock 12:e40272e1fd8f 537 /*----------------------------------------------//----------------------------*/
gatedClock 53:8c2baf5623c8 538 // front-end control of magnetron off.
gatedClock 53:8c2baf5623c8 539 // due to physical danger, the magnetron is turned off immediately
gatedClock 53:8c2baf5623c8 540 // upon off-button press, in the interrupt that it generates.
gatedClock 53:8c2baf5623c8 541
gatedClock 26:bff592483cb1 542 void ISRbottomButtonRising(void) // cook stop.
gatedClock 12:e40272e1fd8f 543 {
gatedClock 66:4a0006fa5cc1 544 if (debounceTimer.read_ms() > DEBOUNCEmS)
gatedClock 66:4a0006fa5cc1 545 {
gatedClock 66:4a0006fa5cc1 546 led0 = 0; // magnetron off.
gatedClock 66:4a0006fa5cc1 547 gtButtons.cBottomButton = 1; // detect bottom button.
gatedClock 66:4a0006fa5cc1 548 }
gatedClock 66:4a0006fa5cc1 549 debounceTimer.reset(); // begin debounce period.
gatedClock 66:4a0006fa5cc1 550 }
gatedClock 12:e40272e1fd8f 551 /*----------------------------------------------//----------------------------*/
gatedClock 15:5eaa2ab1d00d 552 void ISRbottomButtonFalling(void) // button-release debounce.
gatedClock 12:e40272e1fd8f 553 {
gatedClock 66:4a0006fa5cc1 554 debounceTimer.reset(); // begin debounce period.
gatedClock 12:e40272e1fd8f 555 }
gatedClock 12:e40272e1fd8f 556 /*----------------------------------------------//----------------------------*/
gatedClock 53:8c2baf5623c8 557 // front-end control of magnetron off.
gatedClock 53:8c2baf5623c8 558 // due to physical danger, the magnetron is turned off immediately
gatedClock 53:8c2baf5623c8 559 // upon detection of an open door.
gatedClock 53:8c2baf5623c8 560
gatedClock 26:bff592483cb1 561 void ISRcenterButtonRising(void) // toggle door state.
gatedClock 12:e40272e1fd8f 562 {
gatedClock 66:4a0006fa5cc1 563 if (debounceTimer.read_ms() > DEBOUNCEmS)
gatedClock 66:4a0006fa5cc1 564 {
gatedClock 66:4a0006fa5cc1 565 if (gtButtons.cDoorOpen == MSG_OPEN) // calculate door state.
gatedClock 66:4a0006fa5cc1 566 gtButtons.cDoorOpen = MSG_CLOSED;
gatedClock 66:4a0006fa5cc1 567 else
gatedClock 66:4a0006fa5cc1 568 gtButtons.cDoorOpen = MSG_OPEN;
gatedClock 53:8c2baf5623c8 569
gatedClock 59:5e45b5e4a874 570 // magnetron off.
gatedClock 66:4a0006fa5cc1 571 if (gtButtons.cDoorOpen == MSG_OPEN) led0 = 0;
gatedClock 58:ec630b6dd9b1 572
gatedClock 66:4a0006fa5cc1 573 gtButtons.cCenterButton = 1;
gatedClock 66:4a0006fa5cc1 574 }
gatedClock 66:4a0006fa5cc1 575 debounceTimer.reset(); // begin debounce period.
gatedClock 12:e40272e1fd8f 576 }
gatedClock 12:e40272e1fd8f 577 /*----------------------------------------------//----------------------------*/
gatedClock 15:5eaa2ab1d00d 578 void ISRcenterButtonFalling(void) // button-release debounce.
gatedClock 12:e40272e1fd8f 579 {
gatedClock 66:4a0006fa5cc1 580 debounceTimer.reset(); // begin debounce period.
gatedClock 12:e40272e1fd8f 581 }
gatedClock 12:e40272e1fd8f 582 /*----------------------------------------------//----------------------------*/
gatedClock 40:7afff79f0d8b 583 void temperatureThread(void const *args) // temperature measurement.
gatedClock 39:4e7e4d935a87 584 {
gatedClock 45:e3207684e841 585 while(1) // thread loop.
gatedClock 45:e3207684e841 586 {
gatedClock 45:e3207684e841 587 gfCelsius = temperature.read(); // physical measurement.
gatedClock 40:7afff79f0d8b 588
gatedClock 45:e3207684e841 589 Thread::wait(THREAD_1_WAITmS); // multitasking.
gatedClock 45:e3207684e841 590 } // thread loop.
gatedClock 45:e3207684e841 591 } // temperatureThread.
gatedClock 42:266d5bbbfd19 592 /*----------------------------------------------//----------------------------*/
gatedClock 42:266d5bbbfd19 593 void LCDthread(void const *args) // LCD display thread.
gatedClock 42:266d5bbbfd19 594 {
gatedClock 67:1d9c85a4c3c1 595
gatedClock 67:1d9c85a4c3c1 596 static int dLCDtotalCookTimeSec = 0; // sample current values.
gatedClock 67:1d9c85a4c3c1 597 static int dCookTimeRemainingSec = 0;
gatedClock 67:1d9c85a4c3c1 598 static float fLCDcelsius = 0.0;
gatedClock 67:1d9c85a4c3c1 599
gatedClock 67:1d9c85a4c3c1 600 // remember previous values.
gatedClock 67:1d9c85a4c3c1 601 static int dLCDtotalCookTimeSecLast = 0;
gatedClock 67:1d9c85a4c3c1 602 static int dCookTimeRemainingSecLast = 0;
gatedClock 67:1d9c85a4c3c1 603 static float fLCDcelsiusLast = 0.0;
gatedClock 67:1d9c85a4c3c1 604
gatedClock 44:d16e813e61ef 605 while(1) // thread loop.
gatedClock 44:d16e813e61ef 606 {
gatedClock 67:1d9c85a4c3c1 607 // don't allow the values to
gatedClock 67:1d9c85a4c3c1 608 // change in the middle of the
gatedClock 67:1d9c85a4c3c1 609 // below else the anti-blink
gatedClock 67:1d9c85a4c3c1 610 // code won't work.
gatedClock 80:e3e1a2161435 611 dLCDtotalCookTimeSec = giLCD.dTotalCookTime;
gatedClock 80:e3e1a2161435 612 dCookTimeRemainingSec = giLCD.dRemainingTime;
gatedClock 80:e3e1a2161435 613 fLCDcelsius = giLCD.fCelsius;
gatedClock 80:e3e1a2161435 614
gatedClock 80:e3e1a2161435 615
gatedClock 67:1d9c85a4c3c1 616
gatedClock 67:1d9c85a4c3c1 617
gatedClock 67:1d9c85a4c3c1 618 // clear display only when
gatedClock 67:1d9c85a4c3c1 619 // necessary, in order to avoid
gatedClock 67:1d9c85a4c3c1 620 // 'blinkieness'.
gatedClock 67:1d9c85a4c3c1 621 if (dLCDtotalCookTimeSec != dLCDtotalCookTimeSecLast ||
gatedClock 67:1d9c85a4c3c1 622 dCookTimeRemainingSec != dCookTimeRemainingSecLast ||
gatedClock 67:1d9c85a4c3c1 623 fLCDcelsius != fLCDcelsiusLast)
gatedClock 67:1d9c85a4c3c1 624 lcd.cls();
gatedClock 42:266d5bbbfd19 625
gatedClock 44:d16e813e61ef 626 LCD1; // line 1.
gatedClock 67:1d9c85a4c3c1 627 lcd.printf(" total cook time: %d",dLCDtotalCookTimeSec);
gatedClock 42:266d5bbbfd19 628
gatedClock 44:d16e813e61ef 629 LCD2; // line 2.
gatedClock 67:1d9c85a4c3c1 630 lcd.printf(" remaing cook time: %d",dCookTimeRemainingSec);
gatedClock 42:266d5bbbfd19 631
gatedClock 44:d16e813e61ef 632 LCD3; // line 3.
gatedClock 67:1d9c85a4c3c1 633 lcd.printf(" temperature : %5.3f",fLCDcelsius);
gatedClock 67:1d9c85a4c3c1 634
gatedClock 67:1d9c85a4c3c1 635 // pipeline variables.
gatedClock 67:1d9c85a4c3c1 636 dLCDtotalCookTimeSecLast = dLCDtotalCookTimeSec;
gatedClock 67:1d9c85a4c3c1 637 dCookTimeRemainingSecLast = dCookTimeRemainingSec;
gatedClock 67:1d9c85a4c3c1 638 fLCDcelsiusLast = fLCDcelsius;
gatedClock 42:266d5bbbfd19 639
gatedClock 44:d16e813e61ef 640 Thread::wait(THREAD_2_WAITmS); // multitasking.
gatedClock 44:d16e813e61ef 641 } // thread loop.
gatedClock 44:d16e813e61ef 642 } // LCDthread.
gatedClock 42:266d5bbbfd19 643 /*----------------------------------------------//----------------------------*/
gatedClock 71:4a5f256ecf7c 644
gatedClock 71:4a5f256ecf7c 645 /*
gatedClock 71:4a5f256ecf7c 646 struct tRemainingTime // remaining time related.
gatedClock 64:255295f1d782 647 {
gatedClock 71:4a5f256ecf7c 648 char cControl; // countdown control.
gatedClock 71:4a5f256ecf7c 649 int dTotalTime; // initialize to this.
gatedClock 71:4a5f256ecf7c 650 int dRemainingTime; // the countdown value.
gatedClock 71:4a5f256ecf7c 651 }
gatedClock 71:4a5f256ecf7c 652
gatedClock 71:4a5f256ecf7c 653 giRemainingTime.
gatedClock 66:4a0006fa5cc1 654
gatedClock 71:4a5f256ecf7c 655 #define RT_PRELOAD 0x01 // remaining-time preload.
gatedClock 71:4a5f256ecf7c 656 #define RT_DECREMENT 0x02 // remaining-time decrement.
gatedClock 71:4a5f256ecf7c 657 #define RT_PAUSE 0x03 // remaining-time don't change.
gatedClock 71:4a5f256ecf7c 658 #define RT_CLEAR 0x04 // remaining-time set to zero.
gatedClock 71:4a5f256ecf7c 659
gatedClock 71:4a5f256ecf7c 660 */
gatedClock 71:4a5f256ecf7c 661
gatedClock 71:4a5f256ecf7c 662
gatedClock 71:4a5f256ecf7c 663
gatedClock 71:4a5f256ecf7c 664
gatedClock 71:4a5f256ecf7c 665
gatedClock 71:4a5f256ecf7c 666
gatedClock 71:4a5f256ecf7c 667 void tickCookRemainingTime(void) // cook-cycle countdown.
gatedClock 71:4a5f256ecf7c 668 {
gatedClock 71:4a5f256ecf7c 669 static int dRemainingTime = 0; // remaining time in seconds.
gatedClock 70:7c0743c28b11 670
gatedClock 76:74c454c9d75b 671
gatedClock 75:c2894d531f42 672
gatedClock 75:c2894d531f42 673 switch (giRemainingTime.cControl) // control processing.
gatedClock 71:4a5f256ecf7c 674 {
gatedClock 72:b4d0c0aa3c26 675 case RT_PRELOAD : // preload with total time.
gatedClock 71:4a5f256ecf7c 676 {
gatedClock 72:b4d0c0aa3c26 677 dRemainingTime = giRemainingTime.dTotalTime;
gatedClock 72:b4d0c0aa3c26 678 if (dRemainingTime > 180) dRemainingTime = 180;
gatedClock 72:b4d0c0aa3c26 679 if (dRemainingTime < 0) dRemainingTime = 0;
gatedClock 71:4a5f256ecf7c 680 break;
gatedClock 71:4a5f256ecf7c 681 }
gatedClock 72:b4d0c0aa3c26 682 case RT_DECREMENT : // count-down.
gatedClock 71:4a5f256ecf7c 683 {
gatedClock 72:b4d0c0aa3c26 684 dRemainingTime--;
gatedClock 72:b4d0c0aa3c26 685 if (dRemainingTime > 180) dRemainingTime = 180;
gatedClock 72:b4d0c0aa3c26 686 if (dRemainingTime < 0) dRemainingTime = 0;
gatedClock 71:4a5f256ecf7c 687 break;
gatedClock 71:4a5f256ecf7c 688 }
gatedClock 71:4a5f256ecf7c 689
gatedClock 72:b4d0c0aa3c26 690 case RT_PAUSE : // suspend countdown.
gatedClock 69:55b836e8ced7 691 {
gatedClock 72:b4d0c0aa3c26 692 dRemainingTime = dRemainingTime;
gatedClock 72:b4d0c0aa3c26 693 if (dRemainingTime > 180) dRemainingTime = 180;
gatedClock 72:b4d0c0aa3c26 694 if (dRemainingTime < 0) dRemainingTime = 0;
gatedClock 71:4a5f256ecf7c 695 break;
gatedClock 71:4a5f256ecf7c 696 }
gatedClock 71:4a5f256ecf7c 697
gatedClock 72:b4d0c0aa3c26 698 case RT_CLEAR : // clear countdown.
gatedClock 71:4a5f256ecf7c 699 {
gatedClock 76:74c454c9d75b 700 dRemainingTime = 0;
gatedClock 76:74c454c9d75b 701 led3 = 1;
gatedClock 71:4a5f256ecf7c 702 break;
gatedClock 71:4a5f256ecf7c 703 }
gatedClock 69:55b836e8ced7 704
gatedClock 72:b4d0c0aa3c26 705 default : // saturate, just in case.
gatedClock 72:b4d0c0aa3c26 706 {
gatedClock 72:b4d0c0aa3c26 707 if (dRemainingTime > 180) dRemainingTime = 180;
gatedClock 72:b4d0c0aa3c26 708 if (dRemainingTime < 0) dRemainingTime = 0;
gatedClock 72:b4d0c0aa3c26 709 }
gatedClock 75:c2894d531f42 710 } // control processing.
gatedClock 71:4a5f256ecf7c 711
gatedClock 75:c2894d531f42 712 // promote to global scope.
gatedClock 75:c2894d531f42 713 giRemainingTime.dRemainingTime = dRemainingTime;
gatedClock 70:7c0743c28b11 714
gatedClock 70:7c0743c28b11 715 } // cookRemainingTime.
gatedClock 69:55b836e8ced7 716 /*----------------------------------------------//----------------------------*/
gatedClock 69:55b836e8ced7 717
gatedClock 69:55b836e8ced7 718
gatedClock 69:55b836e8ced7 719
gatedClock 69:55b836e8ced7 720
gatedClock 69:55b836e8ced7 721
gatedClock 69:55b836e8ced7 722
gatedClock 69:55b836e8ced7 723
gatedClock 69:55b836e8ced7 724
gatedClock 69:55b836e8ced7 725
gatedClock 69:55b836e8ced7 726
gatedClock 69:55b836e8ced7 727