homework 7

Dependencies:   mbed-rtos mbed C12832_lcd LM75B

Committer:
gatedClock
Date:
Thu Sep 12 02:18:59 2013 +0000
Revision:
76:74c454c9d75b
Parent:
75:c2894d531f42
Child:
77:73e4fd83642f
moved the ticker into the thread, its still hanging.

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