homework 7

Dependencies:   mbed-rtos mbed C12832_lcd LM75B

Committer:
gatedClock
Date:
Wed Sep 11 23:12:35 2013 +0000
Revision:
73:44739860198b
Parent:
72:b4d0c0aa3c26
Child:
74:4debb8f2e21d
working on state machine.

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