Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed C12832_lcd LM75B
main.cpp@58:ec630b6dd9b1, 2013-09-10 (annotated)
- Committer:
- gatedClock
- Date:
- Tue Sep 10 22:45:53 2013 +0000
- Revision:
- 58:ec630b6dd9b1
- Parent:
- 57:0432c68ad232
- Child:
- 59:5e45b5e4a874
working on threadButtonStateManager, for start/stop/open/closed.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 0:fcca4db7b32a | 7 | -----includes-----------------------------------//----------------------------*/ |
| gatedClock | 0:fcca4db7b32a | 8 | #include "mbed.h" // mbed class. |
| gatedClock | 10:2b0a9fc39109 | 9 | #include "rtos.h" // rtos class. |
| gatedClock | 39:4e7e4d935a87 | 10 | #include "LM75B.h" // thermometer class. |
| gatedClock | 10:2b0a9fc39109 | 11 | #include "C12832_lcd.h" // LCD class. |
| gatedClock | 0:fcca4db7b32a | 12 | //---defines------------------------------------//------------------------------ |
| gatedClock | 9:cfdb9aa5857c | 13 | #define LCD1 lcd.locate(0, 0); // LCD line 1. |
| gatedClock | 9:cfdb9aa5857c | 14 | #define LCD2 lcd.locate(0,11); // LCD line 2. |
| gatedClock | 9:cfdb9aa5857c | 15 | #define LCD3 lcd.locate(0,22); // LCD line 3. |
| gatedClock | 9:cfdb9aa5857c | 16 | |
| gatedClock | 10:2b0a9fc39109 | 17 | |
| gatedClock | 19:92b11e30aaaf | 18 | #define DEBOUNCE 0.16 // debounce pause duration in S. |
| gatedClock | 19:92b11e30aaaf | 19 | #define uS_TIMEOUT 100 // Timer uS timeout. |
| gatedClock | 19:92b11e30aaaf | 20 | #define LBSIG 1 // left button signal code. |
| gatedClock | 33:34c1bef3c4ff | 21 | #define PIPEuS 1000 // pipeline clock period. |
| gatedClock | 19:92b11e30aaaf | 22 | #define SLOWCLOCKuS 500000 // slow-clock period. |
| gatedClock | 39:4e7e4d935a87 | 23 | #define TEMPCLOCKS 1 // temperature-measuring period in S. |
| gatedClock | 26:bff592483cb1 | 24 | #define PIPEDATASIZE 8 // dimension of tPipeData. |
| gatedClock | 44:d16e813e61ef | 25 | #define THREAD_1_WAITmS 400 // thread 1 wait in mS. |
| gatedClock | 44:d16e813e61ef | 26 | #define THREAD_2_WAITmS 400 // thread 2 wait in mS. |
| gatedClock | 52:8ba6a0c91a89 | 27 | #define THREAD_3_WAITmS 400 // thread 3 wait in mS. |
| gatedClock | 54:b0e7352d2516 | 28 | #define THREAD_4_WAITmS 400 // thread 4 wait in mS. |
| gatedClock | 57:0432c68ad232 | 29 | #define THREAD_5_WAITmS 400 // thread 5 wait in mS. |
| gatedClock | 44:d16e813e61ef | 30 | #define HB_MODULO 1024 // heartbeat modulo divisor. |
| gatedClock | 50:2928c3cbdcc3 | 31 | |
| gatedClock | 54:b0e7352d2516 | 32 | #define MSG_INC_TIME 0x01 |
| gatedClock | 54:b0e7352d2516 | 33 | #define MSG_DEC_TIME 0x02 |
| gatedClock | 58:ec630b6dd9b1 | 34 | #define MSG_START 0x04 |
| gatedClock | 58:ec630b6dd9b1 | 35 | #define MSG_STOP 0x08 |
| gatedClock | 58:ec630b6dd9b1 | 36 | #define MSG_OPEN 0x10 |
| gatedClock | 58:ec630b6dd9b1 | 37 | #define MSG_CLOSED 0x20 |
| gatedClock | 57:0432c68ad232 | 38 | |
| gatedClock | 57:0432c68ad232 | 39 | #define FSM_IDLE 0x00 // cook-state state-machine. |
| gatedClock | 57:0432c68ad232 | 40 | #define FSM_COOK 0x01 // cook-state state-machine. |
| gatedClock | 57:0432c68ad232 | 41 | #define FSM_PAUSE 0x02 // cook-state state-machine. |
| gatedClock | 57:0432c68ad232 | 42 | #define FSM_DONE 0x04 // cook-state state-machine. |
| gatedClock | 0:fcca4db7b32a | 43 | //--global_definitions--------------------------//------------------------------ |
| gatedClock | 26:bff592483cb1 | 44 | struct tButtons // button ISR updates. |
| gatedClock | 26:bff592483cb1 | 45 | { |
| gatedClock | 26:bff592483cb1 | 46 | char cLeftButton; // cooktime +60S. |
| gatedClock | 26:bff592483cb1 | 47 | char cRightButton; // cooktime -60S. |
| gatedClock | 26:bff592483cb1 | 48 | char cTopButton; // start cook. |
| gatedClock | 26:bff592483cb1 | 49 | char cBottomButton; // stop cook. |
| gatedClock | 58:ec630b6dd9b1 | 50 | char cCenterButton; // center button pressed. |
| gatedClock | 53:8c2baf5623c8 | 51 | char cDoorOpen; // door open. |
| gatedClock | 26:bff592483cb1 | 52 | }; |
| gatedClock | 34:b449d2a7c786 | 53 | |
| gatedClock | 55:17f3354da63a | 54 | Queue<int ,1> queueModTotalTime; // message to modify total time. |
| gatedClock | 58:ec630b6dd9b1 | 55 | Queue<int ,1> queueUpdateFSM; // message to inform FSM. |
| gatedClock | 55:17f3354da63a | 56 | |
| gatedClock | 0:fcca4db7b32a | 57 | //--global_variables----------------------------//------------------------------ |
| gatedClock | 26:bff592483cb1 | 58 | char gcSignalWaitEnable; // 1 to wait on a signal. |
| gatedClock | 26:bff592483cb1 | 59 | char gcSlowClock; // slow-clock signal. |
| gatedClock | 33:34c1bef3c4ff | 60 | char gcInitializePipeline; // 1 to initialize pipeline state. |
| gatedClock | 39:4e7e4d935a87 | 61 | float gfCelsius; // from thermometer. |
| gatedClock | 42:266d5bbbfd19 | 62 | float gfLCDcelsius; // feed into LCD. |
| gatedClock | 42:266d5bbbfd19 | 63 | int gdLCDtotalCookTimeSec; // feed into LCD. |
| gatedClock | 42:266d5bbbfd19 | 64 | int gdCookTimeRemainingSec; // feed into LCD. |
| gatedClock | 26:bff592483cb1 | 65 | tButtons gtButtons; // ISR button updates. |
| gatedClock | 0:fcca4db7b32a | 66 | //--global_instances----------------------------//------------------------------ |
| gatedClock | 55:17f3354da63a | 67 | Serial pc(USBTX, USBRX); // PuTTY terminal communication. |
| gatedClock | 39:4e7e4d935a87 | 68 | LM75B temperature(p28,p27); // on-board thermometer. |
| gatedClock | 9:cfdb9aa5857c | 69 | C12832_LCD lcd; // LCD object. |
| gatedClock | 53:8c2baf5623c8 | 70 | DigitalOut led0(LED4); // magnetron. |
| gatedClock | 39:4e7e4d935a87 | 71 | DigitalOut led1(LED3); |
| gatedClock | 39:4e7e4d935a87 | 72 | DigitalOut led2(LED2); |
| gatedClock | 39:4e7e4d935a87 | 73 | DigitalOut led3(LED1); |
| gatedClock | 0:fcca4db7b32a | 74 | |
| gatedClock | 0:fcca4db7b32a | 75 | InterruptIn iJoyStickUp (p15); // joystick up rising edge. |
| gatedClock | 0:fcca4db7b32a | 76 | InterruptIn iJoyStickDown (p12); // joystick down rising edge. |
| gatedClock | 0:fcca4db7b32a | 77 | InterruptIn iJoyStickLeft (p13); // joystick left rising edge. |
| gatedClock | 0:fcca4db7b32a | 78 | InterruptIn iJoyStickRight (p16); // joystick right rising edge. |
| gatedClock | 0:fcca4db7b32a | 79 | InterruptIn iJoyStickCenter(p14); // 1 if joystick middle pressed. |
| gatedClock | 0:fcca4db7b32a | 80 | |
| gatedClock | 50:2928c3cbdcc3 | 81 | Ticker tickerButtonStateManager; // manage the button states. |
| gatedClock | 19:92b11e30aaaf | 82 | Ticker tickerSlowClock; // generate a ~1Hz clock. |
| gatedClock | 40:7afff79f0d8b | 83 | |
| gatedClock | 0:fcca4db7b32a | 84 | //-------prototypes-----------------------------//------------------------------ |
| gatedClock | 49:56f790977983 | 85 | |
| gatedClock | 19:92b11e30aaaf | 86 | void slowClock(); // 1Hz or thereabouts. |
| gatedClock | 49:56f790977983 | 87 | |
| gatedClock | 9:cfdb9aa5857c | 88 | void initialization(); // initialize settings. |
| gatedClock | 13:21f27ba467c2 | 89 | |
| gatedClock | 13:21f27ba467c2 | 90 | void ISRleftButtonRising(); // cook-time increase. |
| gatedClock | 13:21f27ba467c2 | 91 | void ISRleftButtonFalling(); // button-release debounce. |
| gatedClock | 13:21f27ba467c2 | 92 | void ISRrightButtonRising(); // cook-time decrease. |
| gatedClock | 13:21f27ba467c2 | 93 | void ISRrightButtonFalling(); // button-release debounce. |
| gatedClock | 13:21f27ba467c2 | 94 | void ISRtopButtonRising(); // cook start. |
| gatedClock | 13:21f27ba467c2 | 95 | void ISRtopButtonFalling(); // button-release debounce. |
| gatedClock | 13:21f27ba467c2 | 96 | void ISRbottomButtonRising(); // cook stop. |
| gatedClock | 13:21f27ba467c2 | 97 | void ISRbottomButtonFalling(); // button-release debounce. |
| gatedClock | 13:21f27ba467c2 | 98 | void ISRcenterButtonRising(); // door state toggle. |
| gatedClock | 13:21f27ba467c2 | 99 | void ISRcenterButtonFalling(); // button-release debounce. |
| gatedClock | 16:db7f0b3b2605 | 100 | void disableSignalWaiting(); // break from signal waiting. |
| gatedClock | 39:4e7e4d935a87 | 101 | |
| gatedClock | 54:b0e7352d2516 | 102 | void threadButtonStateManager(void const *args); |
| gatedClock | 50:2928c3cbdcc3 | 103 | void threadTotalTimeControl(void const *args); |
| gatedClock | 57:0432c68ad232 | 104 | void threadCookStateFSM(void const *args); |
| gatedClock | 50:2928c3cbdcc3 | 105 | |
| gatedClock | 40:7afff79f0d8b | 106 | void temperatureThread(void const *args); // temperature measurement. |
| gatedClock | 42:266d5bbbfd19 | 107 | void LCDthread (void const *args); // LCD display thread. |
| gatedClock | 0:fcca4db7b32a | 108 | //==============================================//============================== |
| gatedClock | 0:fcca4db7b32a | 109 | int main(void) |
| gatedClock | 0:fcca4db7b32a | 110 | { |
| gatedClock | 16:db7f0b3b2605 | 111 | char cLeftButtonState; // 1 means button was pressed. |
| gatedClock | 16:db7f0b3b2605 | 112 | |
| gatedClock | 16:db7f0b3b2605 | 113 | |
| gatedClock | 16:db7f0b3b2605 | 114 | |
| gatedClock | 14:d3bb343cd5b2 | 115 | iJoyStickLeft.rise (&ISRleftButtonRising); |
| gatedClock | 14:d3bb343cd5b2 | 116 | iJoyStickLeft.fall (&ISRleftButtonFalling); |
| gatedClock | 9:cfdb9aa5857c | 117 | |
| gatedClock | 14:d3bb343cd5b2 | 118 | iJoyStickRight.rise(&ISRrightButtonRising); |
| gatedClock | 14:d3bb343cd5b2 | 119 | iJoyStickRight.fall(&ISRrightButtonFalling); |
| gatedClock | 14:d3bb343cd5b2 | 120 | |
| gatedClock | 14:d3bb343cd5b2 | 121 | iJoyStickUp.rise (&ISRtopButtonRising); |
| gatedClock | 14:d3bb343cd5b2 | 122 | iJoyStickUp.fall (&ISRtopButtonFalling); |
| gatedClock | 9:cfdb9aa5857c | 123 | |
| gatedClock | 14:d3bb343cd5b2 | 124 | iJoyStickDown.rise (&ISRbottomButtonRising); |
| gatedClock | 14:d3bb343cd5b2 | 125 | iJoyStickDown.fall (&ISRbottomButtonFalling); |
| gatedClock | 7:9fbd1d540863 | 126 | |
| gatedClock | 14:d3bb343cd5b2 | 127 | iJoyStickCenter.rise(&ISRcenterButtonRising); |
| gatedClock | 14:d3bb343cd5b2 | 128 | iJoyStickCenter.fall(&ISRcenterButtonFalling); |
| gatedClock | 9:cfdb9aa5857c | 129 | |
| gatedClock | 33:34c1bef3c4ff | 130 | gcInitializePipeline = 1; // tell pipeline to initialize. |
| gatedClock | 16:db7f0b3b2605 | 131 | |
| gatedClock | 9:cfdb9aa5857c | 132 | initialization(); // initialize variables. |
| gatedClock | 21:b794d189c36b | 133 | gcSlowClock = 0; |
| gatedClock | 44:d16e813e61ef | 134 | led1 = 0; |
| gatedClock | 53:8c2baf5623c8 | 135 | gtButtons.cDoorOpen = 0; // initialize with door closed. |
| gatedClock | 49:56f790977983 | 136 | |
| gatedClock | 39:4e7e4d935a87 | 137 | tickerSlowClock.attach_us(&slowClock ,SLOWCLOCKuS); |
| gatedClock | 54:b0e7352d2516 | 138 | |
| gatedClock | 40:7afff79f0d8b | 139 | |
| gatedClock | 58:ec630b6dd9b1 | 140 | Thread thread_1(temperatureThread ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); |
| gatedClock | 58:ec630b6dd9b1 | 141 | Thread thread_2(LCDthread ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); |
| gatedClock | 58:ec630b6dd9b1 | 142 | Thread thread_3(threadTotalTimeControl ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); |
| gatedClock | 54:b0e7352d2516 | 143 | Thread thread_4(threadButtonStateManager,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); |
| gatedClock | 58:ec630b6dd9b1 | 144 | Thread thread_5(threadCookStateFSM ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); |
| gatedClock | 52:8ba6a0c91a89 | 145 | |
| gatedClock | 40:7afff79f0d8b | 146 | |
| gatedClock | 14:d3bb343cd5b2 | 147 | |
| gatedClock | 9:cfdb9aa5857c | 148 | |
| gatedClock | 14:d3bb343cd5b2 | 149 | while(1) |
| gatedClock | 0:fcca4db7b32a | 150 | { |
| gatedClock | 44:d16e813e61ef | 151 | Thread::wait(10000); |
| gatedClock | 16:db7f0b3b2605 | 152 | |
| gatedClock | 16:db7f0b3b2605 | 153 | |
| gatedClock | 16:db7f0b3b2605 | 154 | |
| gatedClock | 14:d3bb343cd5b2 | 155 | |
| gatedClock | 0:fcca4db7b32a | 156 | } |
| gatedClock | 19:92b11e30aaaf | 157 | } |
| gatedClock | 19:92b11e30aaaf | 158 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 54:b0e7352d2516 | 159 | // process buttons, generate messages. |
| gatedClock | 54:b0e7352d2516 | 160 | void threadButtonStateManager(void const *args) |
| gatedClock | 50:2928c3cbdcc3 | 161 | { |
| gatedClock | 56:18cff6eb91db | 162 | int dMessage; // message. |
| gatedClock | 50:2928c3cbdcc3 | 163 | |
| gatedClock | 54:b0e7352d2516 | 164 | while(1) // thread loop. |
| gatedClock | 54:b0e7352d2516 | 165 | { |
| gatedClock | 54:b0e7352d2516 | 166 | |
| gatedClock | 54:b0e7352d2516 | 167 | //--- // TOTAL TIME CONTROL. |
| gatedClock | 56:18cff6eb91db | 168 | |
| gatedClock | 56:18cff6eb91db | 169 | // encoded integers will be sent, |
| gatedClock | 56:18cff6eb91db | 170 | // not pointers. |
| gatedClock | 50:2928c3cbdcc3 | 171 | |
| gatedClock | 50:2928c3cbdcc3 | 172 | if (gtButtons.cLeftButton) // total time increment button. |
| gatedClock | 50:2928c3cbdcc3 | 173 | { |
| gatedClock | 54:b0e7352d2516 | 174 | dMessage = MSG_INC_TIME; // set message. |
| gatedClock | 56:18cff6eb91db | 175 | queueModTotalTime.put((int *) dMessage);// pretend it's a pointer. |
| gatedClock | 50:2928c3cbdcc3 | 176 | gtButtons.cLeftButton = 0; // clear the button state. |
| gatedClock | 50:2928c3cbdcc3 | 177 | } |
| gatedClock | 50:2928c3cbdcc3 | 178 | |
| gatedClock | 50:2928c3cbdcc3 | 179 | if (gtButtons.cRightButton) // total time increment button. |
| gatedClock | 50:2928c3cbdcc3 | 180 | { |
| gatedClock | 54:b0e7352d2516 | 181 | dMessage = MSG_DEC_TIME; // set message. |
| gatedClock | 56:18cff6eb91db | 182 | queueModTotalTime.put((int *) dMessage);// pretend it's a pointer. |
| gatedClock | 50:2928c3cbdcc3 | 183 | gtButtons.cRightButton = 0; // clear the button state. |
| gatedClock | 50:2928c3cbdcc3 | 184 | } |
| gatedClock | 54:b0e7352d2516 | 185 | |
| gatedClock | 58:ec630b6dd9b1 | 186 | |
| gatedClock | 58:ec630b6dd9b1 | 187 | if (gtButtons.cTopButton) |
| gatedClock | 58:ec630b6dd9b1 | 188 | { |
| gatedClock | 58:ec630b6dd9b1 | 189 | } |
| gatedClock | 58:ec630b6dd9b1 | 190 | |
| gatedClock | 58:ec630b6dd9b1 | 191 | if (gtButtons.cBottomButton) |
| gatedClock | 58:ec630b6dd9b1 | 192 | { |
| gatedClock | 58:ec630b6dd9b1 | 193 | } |
| gatedClock | 58:ec630b6dd9b1 | 194 | |
| gatedClock | 58:ec630b6dd9b1 | 195 | if (gtButtons.cCenterButton) |
| gatedClock | 58:ec630b6dd9b1 | 196 | { |
| gatedClock | 58:ec630b6dd9b1 | 197 | |
| gatedClock | 58:ec630b6dd9b1 | 198 | |
| gatedClock | 58:ec630b6dd9b1 | 199 | } |
| gatedClock | 58:ec630b6dd9b1 | 200 | |
| gatedClock | 58:ec630b6dd9b1 | 201 | |
| gatedClock | 58:ec630b6dd9b1 | 202 | |
| gatedClock | 58:ec630b6dd9b1 | 203 | |
| gatedClock | 58:ec630b6dd9b1 | 204 | |
| gatedClock | 58:ec630b6dd9b1 | 205 | |
| gatedClock | 58:ec630b6dd9b1 | 206 | |
| gatedClock | 58:ec630b6dd9b1 | 207 | |
| gatedClock | 58:ec630b6dd9b1 | 208 | |
| gatedClock | 58:ec630b6dd9b1 | 209 | //queueUpdateFSM |
| gatedClock | 58:ec630b6dd9b1 | 210 | /* |
| gatedClock | 58:ec630b6dd9b1 | 211 | #define MSG_INC_TIME 0x01 |
| gatedClock | 58:ec630b6dd9b1 | 212 | #define MSG_DEC_TIME 0x02 |
| gatedClock | 58:ec630b6dd9b1 | 213 | #define MSG_START 0x04 |
| gatedClock | 58:ec630b6dd9b1 | 214 | #define MSG_STOP 0x08 |
| gatedClock | 58:ec630b6dd9b1 | 215 | #define MSG_OPEN 0x10 |
| gatedClock | 58:ec630b6dd9b1 | 216 | #define MSG_CLOSED 0x20 |
| gatedClock | 58:ec630b6dd9b1 | 217 | |
| gatedClock | 58:ec630b6dd9b1 | 218 | char cLeftButton; // cooktime +60S. |
| gatedClock | 58:ec630b6dd9b1 | 219 | char cRightButton; // cooktime -60S. |
| gatedClock | 58:ec630b6dd9b1 | 220 | char cTopButton; // start cook. |
| gatedClock | 58:ec630b6dd9b1 | 221 | char cBottomButton; // stop cook. |
| gatedClock | 58:ec630b6dd9b1 | 222 | char cDoorOpen; // door open. |
| gatedClock | 58:ec630b6dd9b1 | 223 | */ |
| gatedClock | 58:ec630b6dd9b1 | 224 | |
| gatedClock | 54:b0e7352d2516 | 225 | Thread::wait(THREAD_4_WAITmS); // multitasking. |
| gatedClock | 54:b0e7352d2516 | 226 | } // thread loop. |
| gatedClock | 50:2928c3cbdcc3 | 227 | |
| gatedClock | 54:b0e7352d2516 | 228 | } // threadButtonStateManager. |
| gatedClock | 50:2928c3cbdcc3 | 229 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 51:e5ec74c49b01 | 230 | // the incoming messages are mutually-exclusive. |
| gatedClock | 51:e5ec74c49b01 | 231 | // total time controller. |
| gatedClock | 51:e5ec74c49b01 | 232 | void threadTotalTimeControl(void const *args) |
| gatedClock | 50:2928c3cbdcc3 | 233 | { |
| gatedClock | 51:e5ec74c49b01 | 234 | static int dTotalTime = 0; // total time variable. |
| gatedClock | 51:e5ec74c49b01 | 235 | |
| gatedClock | 56:18cff6eb91db | 236 | int dMessage; // message data pointer. |
| gatedClock | 51:e5ec74c49b01 | 237 | |
| gatedClock | 51:e5ec74c49b01 | 238 | osEvent queueEvent; // queue event. |
| gatedClock | 50:2928c3cbdcc3 | 239 | |
| gatedClock | 50:2928c3cbdcc3 | 240 | while(1) // thread loop. |
| gatedClock | 50:2928c3cbdcc3 | 241 | { |
| gatedClock | 50:2928c3cbdcc3 | 242 | |
| gatedClock | 55:17f3354da63a | 243 | queueEvent = queueModTotalTime.get(1); // get message. |
| gatedClock | 51:e5ec74c49b01 | 244 | if (queueEvent.status == osEventMessage) |
| gatedClock | 51:e5ec74c49b01 | 245 | { |
| gatedClock | 56:18cff6eb91db | 246 | dMessage = (int) queueEvent.value.p; // interpret as integer, not pointer. |
| gatedClock | 54:b0e7352d2516 | 247 | |
| gatedClock | 54:b0e7352d2516 | 248 | // increment total time. |
| gatedClock | 56:18cff6eb91db | 249 | if (dMessage == MSG_INC_TIME) dTotalTime += 60; |
| gatedClock | 54:b0e7352d2516 | 250 | |
| gatedClock | 54:b0e7352d2516 | 251 | // decrement total time. |
| gatedClock | 56:18cff6eb91db | 252 | if (dMessage == MSG_DEC_TIME) dTotalTime -= 60; |
| gatedClock | 51:e5ec74c49b01 | 253 | } |
| gatedClock | 54:b0e7352d2516 | 254 | |
| gatedClock | 51:e5ec74c49b01 | 255 | if (dTotalTime > 180) dTotalTime = 180; // saturate. |
| gatedClock | 51:e5ec74c49b01 | 256 | if (dTotalTime < 0) dTotalTime = 0; // saturate. |
| gatedClock | 51:e5ec74c49b01 | 257 | |
| gatedClock | 51:e5ec74c49b01 | 258 | gdLCDtotalCookTimeSec = dTotalTime; // transmit to LCD. |
| gatedClock | 50:2928c3cbdcc3 | 259 | |
| gatedClock | 50:2928c3cbdcc3 | 260 | Thread::wait(THREAD_3_WAITmS); // multitasking. |
| gatedClock | 50:2928c3cbdcc3 | 261 | } // thread loop. |
| gatedClock | 50:2928c3cbdcc3 | 262 | } // threadTotalTimeControl. |
| gatedClock | 33:34c1bef3c4ff | 263 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 57:0432c68ad232 | 264 | void threadCookStateFSM(void const *args) // cook-cycle FSM. |
| gatedClock | 57:0432c68ad232 | 265 | { |
| gatedClock | 57:0432c68ad232 | 266 | while(1) // thread loop. |
| gatedClock | 57:0432c68ad232 | 267 | { |
| gatedClock | 57:0432c68ad232 | 268 | |
| gatedClock | 57:0432c68ad232 | 269 | |
| gatedClock | 57:0432c68ad232 | 270 | |
| gatedClock | 57:0432c68ad232 | 271 | |
| gatedClock | 57:0432c68ad232 | 272 | |
| gatedClock | 57:0432c68ad232 | 273 | Thread::wait(THREAD_5_WAITmS); // multitasking. |
| gatedClock | 57:0432c68ad232 | 274 | } // thread loop. |
| gatedClock | 57:0432c68ad232 | 275 | } // threadCookStateFSM. |
| gatedClock | 57:0432c68ad232 | 276 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 19:92b11e30aaaf | 277 | void slowClock(void) // 1Hz or thereabouts. |
| gatedClock | 19:92b11e30aaaf | 278 | { |
| gatedClock | 24:d39516e077ea | 279 | gcSlowClock = !gcSlowClock; // toggle clock. |
| gatedClock | 19:92b11e30aaaf | 280 | } |
| gatedClock | 19:92b11e30aaaf | 281 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 0:fcca4db7b32a | 282 | void initialization(void) // program initializations. |
| gatedClock | 0:fcca4db7b32a | 283 | { |
| gatedClock | 16:db7f0b3b2605 | 284 | gcSignalWaitEnable = 1; |
| gatedClock | 0:fcca4db7b32a | 285 | } |
| gatedClock | 0:fcca4db7b32a | 286 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 26:bff592483cb1 | 287 | void ISRleftButtonRising(void) // cooktime plus 60s. |
| gatedClock | 1:9188d4668a88 | 288 | { |
| gatedClock | 11:9cae003da12b | 289 | __disable_irq(); // debounce start. |
| gatedClock | 53:8c2baf5623c8 | 290 | |
| gatedClock | 26:bff592483cb1 | 291 | gtButtons.cLeftButton = 1; // detect left button. |
| gatedClock | 9:cfdb9aa5857c | 292 | |
| gatedClock | 9:cfdb9aa5857c | 293 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 9:cfdb9aa5857c | 294 | |
| gatedClock | 11:9cae003da12b | 295 | __enable_irq(); // debounce done. |
| gatedClock | 11:9cae003da12b | 296 | } |
| gatedClock | 1:9188d4668a88 | 297 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 15:5eaa2ab1d00d | 298 | void ISRleftButtonFalling(void) // button-release debounce. |
| gatedClock | 1:9188d4668a88 | 299 | { |
| gatedClock | 11:9cae003da12b | 300 | __disable_irq(); // debounce start. |
| gatedClock | 9:cfdb9aa5857c | 301 | |
| gatedClock | 9:cfdb9aa5857c | 302 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 9:cfdb9aa5857c | 303 | |
| gatedClock | 11:9cae003da12b | 304 | __enable_irq(); // debounce done. |
| gatedClock | 11:9cae003da12b | 305 | } |
| gatedClock | 2:665ffa57031f | 306 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 26:bff592483cb1 | 307 | void ISRrightButtonRising(void) // cooktime -60s. |
| gatedClock | 12:e40272e1fd8f | 308 | { |
| gatedClock | 12:e40272e1fd8f | 309 | __disable_irq(); // debounce start. |
| gatedClock | 12:e40272e1fd8f | 310 | |
| gatedClock | 26:bff592483cb1 | 311 | gtButtons.cRightButton = 1; // detect right button. |
| gatedClock | 12:e40272e1fd8f | 312 | |
| gatedClock | 12:e40272e1fd8f | 313 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 12:e40272e1fd8f | 314 | |
| gatedClock | 12:e40272e1fd8f | 315 | __enable_irq(); // debounce done. |
| gatedClock | 12:e40272e1fd8f | 316 | } |
| gatedClock | 12:e40272e1fd8f | 317 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 15:5eaa2ab1d00d | 318 | void ISRrightButtonFalling(void) // button-release debounce. |
| gatedClock | 12:e40272e1fd8f | 319 | { |
| gatedClock | 12:e40272e1fd8f | 320 | __disable_irq(); // debounce start. |
| gatedClock | 12:e40272e1fd8f | 321 | |
| gatedClock | 12:e40272e1fd8f | 322 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 12:e40272e1fd8f | 323 | |
| gatedClock | 12:e40272e1fd8f | 324 | __enable_irq(); // debounce done. |
| gatedClock | 12:e40272e1fd8f | 325 | } |
| gatedClock | 12:e40272e1fd8f | 326 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 26:bff592483cb1 | 327 | void ISRtopButtonRising(void) // cook start. |
| gatedClock | 12:e40272e1fd8f | 328 | { |
| gatedClock | 12:e40272e1fd8f | 329 | __disable_irq(); // debounce start. |
| gatedClock | 12:e40272e1fd8f | 330 | |
| gatedClock | 26:bff592483cb1 | 331 | gtButtons.cTopButton = 1; // detect top button. |
| gatedClock | 12:e40272e1fd8f | 332 | |
| gatedClock | 12:e40272e1fd8f | 333 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 12:e40272e1fd8f | 334 | |
| gatedClock | 12:e40272e1fd8f | 335 | __enable_irq(); // debounce done. |
| gatedClock | 12:e40272e1fd8f | 336 | } |
| gatedClock | 12:e40272e1fd8f | 337 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 15:5eaa2ab1d00d | 338 | void ISRtopButtonFalling(void) // button-release debounce. |
| gatedClock | 12:e40272e1fd8f | 339 | { |
| gatedClock | 12:e40272e1fd8f | 340 | __disable_irq(); // debounce start. |
| gatedClock | 12:e40272e1fd8f | 341 | |
| gatedClock | 12:e40272e1fd8f | 342 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 12:e40272e1fd8f | 343 | |
| gatedClock | 12:e40272e1fd8f | 344 | __enable_irq(); // debounce done. |
| gatedClock | 12:e40272e1fd8f | 345 | } |
| gatedClock | 12:e40272e1fd8f | 346 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 53:8c2baf5623c8 | 347 | |
| gatedClock | 53:8c2baf5623c8 | 348 | // front-end control of magnetron off. |
| gatedClock | 53:8c2baf5623c8 | 349 | // due to physical danger, the magnetron is turned off immediately |
| gatedClock | 53:8c2baf5623c8 | 350 | // upon off-button press, in the interrupt that it generates. |
| gatedClock | 53:8c2baf5623c8 | 351 | |
| gatedClock | 26:bff592483cb1 | 352 | void ISRbottomButtonRising(void) // cook stop. |
| gatedClock | 12:e40272e1fd8f | 353 | { |
| gatedClock | 12:e40272e1fd8f | 354 | __disable_irq(); // debounce start. |
| gatedClock | 53:8c2baf5623c8 | 355 | |
| gatedClock | 53:8c2baf5623c8 | 356 | led0 = 0; // magnetron off. |
| gatedClock | 12:e40272e1fd8f | 357 | |
| gatedClock | 26:bff592483cb1 | 358 | gtButtons.cBottomButton = 1; // detect bottom button. |
| gatedClock | 12:e40272e1fd8f | 359 | |
| gatedClock | 12:e40272e1fd8f | 360 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 12:e40272e1fd8f | 361 | |
| gatedClock | 12:e40272e1fd8f | 362 | __enable_irq(); // debounce done. |
| gatedClock | 12:e40272e1fd8f | 363 | } |
| gatedClock | 12:e40272e1fd8f | 364 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 15:5eaa2ab1d00d | 365 | void ISRbottomButtonFalling(void) // button-release debounce. |
| gatedClock | 12:e40272e1fd8f | 366 | { |
| gatedClock | 12:e40272e1fd8f | 367 | __disable_irq(); // debounce start. |
| gatedClock | 12:e40272e1fd8f | 368 | |
| gatedClock | 12:e40272e1fd8f | 369 | |
| gatedClock | 12:e40272e1fd8f | 370 | |
| gatedClock | 12:e40272e1fd8f | 371 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 12:e40272e1fd8f | 372 | |
| gatedClock | 12:e40272e1fd8f | 373 | __enable_irq(); // debounce done. |
| gatedClock | 12:e40272e1fd8f | 374 | } |
| gatedClock | 12:e40272e1fd8f | 375 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 53:8c2baf5623c8 | 376 | // front-end control of magnetron off. |
| gatedClock | 53:8c2baf5623c8 | 377 | // due to physical danger, the magnetron is turned off immediately |
| gatedClock | 53:8c2baf5623c8 | 378 | // upon detection of an open door. |
| gatedClock | 53:8c2baf5623c8 | 379 | |
| gatedClock | 26:bff592483cb1 | 380 | void ISRcenterButtonRising(void) // toggle door state. |
| gatedClock | 12:e40272e1fd8f | 381 | { |
| gatedClock | 12:e40272e1fd8f | 382 | __disable_irq(); // debounce start. |
| gatedClock | 53:8c2baf5623c8 | 383 | |
| gatedClock | 53:8c2baf5623c8 | 384 | if (gtButtons.cDoorOpen) // calculate door state. |
| gatedClock | 53:8c2baf5623c8 | 385 | gtButtons.cDoorOpen = 0; |
| gatedClock | 53:8c2baf5623c8 | 386 | else |
| gatedClock | 53:8c2baf5623c8 | 387 | gtButtons.cDoorOpen = 1; |
| gatedClock | 53:8c2baf5623c8 | 388 | |
| gatedClock | 53:8c2baf5623c8 | 389 | if (gtButtons.cDoorOpen) led0 = 0; // magnetron off. |
| gatedClock | 58:ec630b6dd9b1 | 390 | |
| gatedClock | 58:ec630b6dd9b1 | 391 | gtButtons.cCenterButton = 1; |
| gatedClock | 12:e40272e1fd8f | 392 | |
| gatedClock | 12:e40272e1fd8f | 393 | |
| gatedClock | 12:e40272e1fd8f | 394 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 12:e40272e1fd8f | 395 | |
| gatedClock | 12:e40272e1fd8f | 396 | __enable_irq(); // debounce done. |
| gatedClock | 12:e40272e1fd8f | 397 | } |
| gatedClock | 12:e40272e1fd8f | 398 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 15:5eaa2ab1d00d | 399 | void ISRcenterButtonFalling(void) // button-release debounce. |
| gatedClock | 12:e40272e1fd8f | 400 | { |
| gatedClock | 12:e40272e1fd8f | 401 | __disable_irq(); // debounce start. |
| gatedClock | 12:e40272e1fd8f | 402 | |
| gatedClock | 12:e40272e1fd8f | 403 | |
| gatedClock | 12:e40272e1fd8f | 404 | |
| gatedClock | 12:e40272e1fd8f | 405 | wait(DEBOUNCE); // debounce time. |
| gatedClock | 12:e40272e1fd8f | 406 | |
| gatedClock | 12:e40272e1fd8f | 407 | __enable_irq(); // debounce done. |
| gatedClock | 12:e40272e1fd8f | 408 | } |
| gatedClock | 12:e40272e1fd8f | 409 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 40:7afff79f0d8b | 410 | void temperatureThread(void const *args) // temperature measurement. |
| gatedClock | 39:4e7e4d935a87 | 411 | { |
| gatedClock | 45:e3207684e841 | 412 | while(1) // thread loop. |
| gatedClock | 45:e3207684e841 | 413 | { |
| gatedClock | 45:e3207684e841 | 414 | gfCelsius = temperature.read(); // physical measurement. |
| gatedClock | 40:7afff79f0d8b | 415 | |
| gatedClock | 45:e3207684e841 | 416 | Thread::wait(THREAD_1_WAITmS); // multitasking. |
| gatedClock | 45:e3207684e841 | 417 | } // thread loop. |
| gatedClock | 45:e3207684e841 | 418 | } // temperatureThread. |
| gatedClock | 42:266d5bbbfd19 | 419 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 42:266d5bbbfd19 | 420 | void LCDthread(void const *args) // LCD display thread. |
| gatedClock | 42:266d5bbbfd19 | 421 | { |
| gatedClock | 44:d16e813e61ef | 422 | while(1) // thread loop. |
| gatedClock | 44:d16e813e61ef | 423 | { |
| gatedClock | 44:d16e813e61ef | 424 | lcd.cls(); // clear the display. |
| gatedClock | 42:266d5bbbfd19 | 425 | |
| gatedClock | 44:d16e813e61ef | 426 | LCD1; // line 1. |
| gatedClock | 44:d16e813e61ef | 427 | lcd.printf(" total cook time: %d",gdLCDtotalCookTimeSec); |
| gatedClock | 42:266d5bbbfd19 | 428 | |
| gatedClock | 44:d16e813e61ef | 429 | LCD2; // line 2. |
| gatedClock | 44:d16e813e61ef | 430 | lcd.printf(" remaing cook time: %d",gdCookTimeRemainingSec); |
| gatedClock | 42:266d5bbbfd19 | 431 | |
| gatedClock | 44:d16e813e61ef | 432 | LCD3; // line 3. |
| gatedClock | 44:d16e813e61ef | 433 | lcd.printf(" temperature : %5.3f",gfLCDcelsius); |
| gatedClock | 42:266d5bbbfd19 | 434 | |
| gatedClock | 44:d16e813e61ef | 435 | Thread::wait(THREAD_2_WAITmS); // multitasking. |
| gatedClock | 44:d16e813e61ef | 436 | } // thread loop. |
| gatedClock | 44:d16e813e61ef | 437 | } // LCDthread. |
| gatedClock | 42:266d5bbbfd19 | 438 | /*----------------------------------------------//----------------------------*/ |
| gatedClock | 42:266d5bbbfd19 | 439 | |
| gatedClock | 42:266d5bbbfd19 | 440 |