homework 7
Dependencies: mbed-rtos mbed C12832_lcd LM75B
main.cpp@52:8ba6a0c91a89, 2013-09-10 (annotated)
- Committer:
- gatedClock
- Date:
- Tue Sep 10 21:41:26 2013 +0000
- Revision:
- 52:8ba6a0c91a89
- Parent:
- 51:e5ec74c49b01
- Child:
- 53:8c2baf5623c8
slugish and causing trouble.
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 | 44:d16e813e61ef | 28 | #define HB_MODULO 1024 // heartbeat modulo divisor. |
gatedClock | 50:2928c3cbdcc3 | 29 | |
gatedClock | 50:2928c3cbdcc3 | 30 | #define SIG_INC_TIME 0x01 |
gatedClock | 50:2928c3cbdcc3 | 31 | #define SIG_DEC_TIME 0x02 |
gatedClock | 0:fcca4db7b32a | 32 | //--global_definitions--------------------------//------------------------------ |
gatedClock | 26:bff592483cb1 | 33 | struct tButtons // button ISR updates. |
gatedClock | 26:bff592483cb1 | 34 | { |
gatedClock | 26:bff592483cb1 | 35 | char cLeftButton; // cooktime +60S. |
gatedClock | 26:bff592483cb1 | 36 | char cRightButton; // cooktime -60S. |
gatedClock | 26:bff592483cb1 | 37 | char cTopButton; // start cook. |
gatedClock | 26:bff592483cb1 | 38 | char cBottomButton; // stop cook. |
gatedClock | 26:bff592483cb1 | 39 | char cCenterButton; // door toggle. |
gatedClock | 26:bff592483cb1 | 40 | }; |
gatedClock | 34:b449d2a7c786 | 41 | |
gatedClock | 50:2928c3cbdcc3 | 42 | Queue<int ,1> queueIncTotalTime; // message to increase total time. |
gatedClock | 50:2928c3cbdcc3 | 43 | Queue<int ,1> queueDecTotalTime; // message to increase total time. |
gatedClock | 0:fcca4db7b32a | 44 | //--global_variables----------------------------//------------------------------ |
gatedClock | 26:bff592483cb1 | 45 | char gcSignalWaitEnable; // 1 to wait on a signal. |
gatedClock | 26:bff592483cb1 | 46 | char gcSlowClock; // slow-clock signal. |
gatedClock | 33:34c1bef3c4ff | 47 | char gcInitializePipeline; // 1 to initialize pipeline state. |
gatedClock | 39:4e7e4d935a87 | 48 | float gfCelsius; // from thermometer. |
gatedClock | 42:266d5bbbfd19 | 49 | float gfLCDcelsius; // feed into LCD. |
gatedClock | 42:266d5bbbfd19 | 50 | int gdLCDtotalCookTimeSec; // feed into LCD. |
gatedClock | 42:266d5bbbfd19 | 51 | int gdCookTimeRemainingSec; // feed into LCD. |
gatedClock | 26:bff592483cb1 | 52 | tButtons gtButtons; // ISR button updates. |
gatedClock | 0:fcca4db7b32a | 53 | //--global_instances----------------------------//------------------------------ |
gatedClock | 39:4e7e4d935a87 | 54 | LM75B temperature(p28,p27); // on-board thermometer. |
gatedClock | 9:cfdb9aa5857c | 55 | C12832_LCD lcd; // LCD object. |
gatedClock | 39:4e7e4d935a87 | 56 | DigitalOut led0(LED4); |
gatedClock | 39:4e7e4d935a87 | 57 | DigitalOut led1(LED3); |
gatedClock | 39:4e7e4d935a87 | 58 | DigitalOut led2(LED2); |
gatedClock | 39:4e7e4d935a87 | 59 | DigitalOut led3(LED1); |
gatedClock | 0:fcca4db7b32a | 60 | |
gatedClock | 0:fcca4db7b32a | 61 | InterruptIn iJoyStickUp (p15); // joystick up rising edge. |
gatedClock | 0:fcca4db7b32a | 62 | InterruptIn iJoyStickDown (p12); // joystick down rising edge. |
gatedClock | 0:fcca4db7b32a | 63 | InterruptIn iJoyStickLeft (p13); // joystick left rising edge. |
gatedClock | 0:fcca4db7b32a | 64 | InterruptIn iJoyStickRight (p16); // joystick right rising edge. |
gatedClock | 0:fcca4db7b32a | 65 | InterruptIn iJoyStickCenter(p14); // 1 if joystick middle pressed. |
gatedClock | 0:fcca4db7b32a | 66 | |
gatedClock | 50:2928c3cbdcc3 | 67 | Ticker tickerButtonStateManager; // manage the button states. |
gatedClock | 19:92b11e30aaaf | 68 | Ticker tickerSlowClock; // generate a ~1Hz clock. |
gatedClock | 40:7afff79f0d8b | 69 | |
gatedClock | 0:fcca4db7b32a | 70 | //-------prototypes-----------------------------//------------------------------ |
gatedClock | 49:56f790977983 | 71 | |
gatedClock | 19:92b11e30aaaf | 72 | void slowClock(); // 1Hz or thereabouts. |
gatedClock | 49:56f790977983 | 73 | |
gatedClock | 9:cfdb9aa5857c | 74 | void initialization(); // initialize settings. |
gatedClock | 13:21f27ba467c2 | 75 | |
gatedClock | 13:21f27ba467c2 | 76 | void ISRleftButtonRising(); // cook-time increase. |
gatedClock | 13:21f27ba467c2 | 77 | void ISRleftButtonFalling(); // button-release debounce. |
gatedClock | 13:21f27ba467c2 | 78 | void ISRrightButtonRising(); // cook-time decrease. |
gatedClock | 13:21f27ba467c2 | 79 | void ISRrightButtonFalling(); // button-release debounce. |
gatedClock | 13:21f27ba467c2 | 80 | void ISRtopButtonRising(); // cook start. |
gatedClock | 13:21f27ba467c2 | 81 | void ISRtopButtonFalling(); // button-release debounce. |
gatedClock | 13:21f27ba467c2 | 82 | void ISRbottomButtonRising(); // cook stop. |
gatedClock | 13:21f27ba467c2 | 83 | void ISRbottomButtonFalling(); // button-release debounce. |
gatedClock | 13:21f27ba467c2 | 84 | void ISRcenterButtonRising(); // door state toggle. |
gatedClock | 13:21f27ba467c2 | 85 | void ISRcenterButtonFalling(); // button-release debounce. |
gatedClock | 16:db7f0b3b2605 | 86 | void disableSignalWaiting(); // break from signal waiting. |
gatedClock | 39:4e7e4d935a87 | 87 | |
gatedClock | 50:2928c3cbdcc3 | 88 | void buttonStateManager(); |
gatedClock | 50:2928c3cbdcc3 | 89 | void threadTotalTimeControl(void const *args); |
gatedClock | 50:2928c3cbdcc3 | 90 | |
gatedClock | 40:7afff79f0d8b | 91 | void temperatureThread(void const *args); // temperature measurement. |
gatedClock | 42:266d5bbbfd19 | 92 | void LCDthread (void const *args); // LCD display thread. |
gatedClock | 0:fcca4db7b32a | 93 | //==============================================//============================== |
gatedClock | 0:fcca4db7b32a | 94 | int main(void) |
gatedClock | 0:fcca4db7b32a | 95 | { |
gatedClock | 16:db7f0b3b2605 | 96 | char cLeftButtonState; // 1 means button was pressed. |
gatedClock | 16:db7f0b3b2605 | 97 | |
gatedClock | 16:db7f0b3b2605 | 98 | |
gatedClock | 16:db7f0b3b2605 | 99 | |
gatedClock | 14:d3bb343cd5b2 | 100 | iJoyStickLeft.rise (&ISRleftButtonRising); |
gatedClock | 14:d3bb343cd5b2 | 101 | iJoyStickLeft.fall (&ISRleftButtonFalling); |
gatedClock | 9:cfdb9aa5857c | 102 | |
gatedClock | 14:d3bb343cd5b2 | 103 | iJoyStickRight.rise(&ISRrightButtonRising); |
gatedClock | 14:d3bb343cd5b2 | 104 | iJoyStickRight.fall(&ISRrightButtonFalling); |
gatedClock | 14:d3bb343cd5b2 | 105 | |
gatedClock | 14:d3bb343cd5b2 | 106 | iJoyStickUp.rise (&ISRtopButtonRising); |
gatedClock | 14:d3bb343cd5b2 | 107 | iJoyStickUp.fall (&ISRtopButtonFalling); |
gatedClock | 9:cfdb9aa5857c | 108 | |
gatedClock | 14:d3bb343cd5b2 | 109 | iJoyStickDown.rise (&ISRbottomButtonRising); |
gatedClock | 14:d3bb343cd5b2 | 110 | iJoyStickDown.fall (&ISRbottomButtonFalling); |
gatedClock | 7:9fbd1d540863 | 111 | |
gatedClock | 14:d3bb343cd5b2 | 112 | iJoyStickCenter.rise(&ISRcenterButtonRising); |
gatedClock | 14:d3bb343cd5b2 | 113 | iJoyStickCenter.fall(&ISRcenterButtonFalling); |
gatedClock | 9:cfdb9aa5857c | 114 | |
gatedClock | 33:34c1bef3c4ff | 115 | gcInitializePipeline = 1; // tell pipeline to initialize. |
gatedClock | 16:db7f0b3b2605 | 116 | |
gatedClock | 9:cfdb9aa5857c | 117 | initialization(); // initialize variables. |
gatedClock | 21:b794d189c36b | 118 | gcSlowClock = 0; |
gatedClock | 44:d16e813e61ef | 119 | led1 = 0; |
gatedClock | 0:fcca4db7b32a | 120 | |
gatedClock | 49:56f790977983 | 121 | |
gatedClock | 39:4e7e4d935a87 | 122 | tickerSlowClock.attach_us(&slowClock ,SLOWCLOCKuS); |
gatedClock | 51:e5ec74c49b01 | 123 | tickerButtonStateManager.attach_us(&buttonStateManager,1000); |
gatedClock | 40:7afff79f0d8b | 124 | |
gatedClock | 46:3b3023c302ec | 125 | Thread thread_1(temperatureThread,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); |
gatedClock | 46:3b3023c302ec | 126 | Thread thread_2(LCDthread ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); |
gatedClock | 50:2928c3cbdcc3 | 127 | Thread thread_3(threadTotalTimeControl,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL); |
gatedClock | 52:8ba6a0c91a89 | 128 | |
gatedClock | 40:7afff79f0d8b | 129 | |
gatedClock | 19:92b11e30aaaf | 130 | |
gatedClock | 14:d3bb343cd5b2 | 131 | |
gatedClock | 9:cfdb9aa5857c | 132 | |
gatedClock | 14:d3bb343cd5b2 | 133 | while(1) |
gatedClock | 0:fcca4db7b32a | 134 | { |
gatedClock | 44:d16e813e61ef | 135 | Thread::wait(10000); |
gatedClock | 16:db7f0b3b2605 | 136 | |
gatedClock | 16:db7f0b3b2605 | 137 | |
gatedClock | 16:db7f0b3b2605 | 138 | |
gatedClock | 14:d3bb343cd5b2 | 139 | |
gatedClock | 0:fcca4db7b32a | 140 | } |
gatedClock | 19:92b11e30aaaf | 141 | } |
gatedClock | 19:92b11e30aaaf | 142 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 50:2928c3cbdcc3 | 143 | void buttonStateManager(void) // ticker-controlled. |
gatedClock | 50:2928c3cbdcc3 | 144 | { |
gatedClock | 50:2928c3cbdcc3 | 145 | static int dOne; // arbitrary payload data. |
gatedClock | 50:2928c3cbdcc3 | 146 | |
gatedClock | 50:2928c3cbdcc3 | 147 | dOne = 1; // initialize. |
gatedClock | 50:2928c3cbdcc3 | 148 | |
gatedClock | 50:2928c3cbdcc3 | 149 | if (gtButtons.cLeftButton) // total time increment button. |
gatedClock | 50:2928c3cbdcc3 | 150 | { |
gatedClock | 50:2928c3cbdcc3 | 151 | queueIncTotalTime.put(&dOne); // tell total time to increment. |
gatedClock | 50:2928c3cbdcc3 | 152 | gtButtons.cLeftButton = 0; // clear the button state. |
gatedClock | 50:2928c3cbdcc3 | 153 | } |
gatedClock | 50:2928c3cbdcc3 | 154 | |
gatedClock | 50:2928c3cbdcc3 | 155 | if (gtButtons.cRightButton) // total time increment button. |
gatedClock | 50:2928c3cbdcc3 | 156 | { |
gatedClock | 50:2928c3cbdcc3 | 157 | queueDecTotalTime.put(&dOne); // tell total time to decrement. |
gatedClock | 50:2928c3cbdcc3 | 158 | gtButtons.cRightButton = 0; // clear the button state. |
gatedClock | 50:2928c3cbdcc3 | 159 | } |
gatedClock | 50:2928c3cbdcc3 | 160 | |
gatedClock | 50:2928c3cbdcc3 | 161 | |
gatedClock | 50:2928c3cbdcc3 | 162 | } |
gatedClock | 50:2928c3cbdcc3 | 163 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 51:e5ec74c49b01 | 164 | // the incoming messages are mutually-exclusive. |
gatedClock | 51:e5ec74c49b01 | 165 | // total time controller. |
gatedClock | 51:e5ec74c49b01 | 166 | void threadTotalTimeControl(void const *args) |
gatedClock | 50:2928c3cbdcc3 | 167 | { |
gatedClock | 51:e5ec74c49b01 | 168 | static int dTotalTime = 0; // total time variable. |
gatedClock | 51:e5ec74c49b01 | 169 | |
gatedClock | 51:e5ec74c49b01 | 170 | int * pdGet; // arbitrary data pointer. |
gatedClock | 51:e5ec74c49b01 | 171 | |
gatedClock | 51:e5ec74c49b01 | 172 | osEvent queueEvent; // queue event. |
gatedClock | 50:2928c3cbdcc3 | 173 | |
gatedClock | 50:2928c3cbdcc3 | 174 | while(1) // thread loop. |
gatedClock | 50:2928c3cbdcc3 | 175 | { |
gatedClock | 50:2928c3cbdcc3 | 176 | |
gatedClock | 51:e5ec74c49b01 | 177 | queueEvent = queueIncTotalTime.get(1); // get increment message. |
gatedClock | 51:e5ec74c49b01 | 178 | if (queueEvent.status == osEventMessage) |
gatedClock | 51:e5ec74c49b01 | 179 | { |
gatedClock | 51:e5ec74c49b01 | 180 | pdGet = (int *) queueEvent.value.p; // drain the queue. |
gatedClock | 51:e5ec74c49b01 | 181 | dTotalTime += 60; // increment total time. |
gatedClock | 51:e5ec74c49b01 | 182 | } |
gatedClock | 50:2928c3cbdcc3 | 183 | |
gatedClock | 51:e5ec74c49b01 | 184 | queueEvent = queueDecTotalTime.get(1); // get increment message. |
gatedClock | 51:e5ec74c49b01 | 185 | if (queueEvent.status == osEventMessage) |
gatedClock | 51:e5ec74c49b01 | 186 | { |
gatedClock | 51:e5ec74c49b01 | 187 | pdGet = (int *) queueEvent.value.p; // drain the queue. |
gatedClock | 51:e5ec74c49b01 | 188 | dTotalTime -= 60; // increment total time. |
gatedClock | 51:e5ec74c49b01 | 189 | } |
gatedClock | 51:e5ec74c49b01 | 190 | |
gatedClock | 51:e5ec74c49b01 | 191 | |
gatedClock | 51:e5ec74c49b01 | 192 | if (dTotalTime > 180) dTotalTime = 180; // saturate. |
gatedClock | 51:e5ec74c49b01 | 193 | if (dTotalTime < 0) dTotalTime = 0; // saturate. |
gatedClock | 51:e5ec74c49b01 | 194 | |
gatedClock | 51:e5ec74c49b01 | 195 | gdLCDtotalCookTimeSec = dTotalTime; // transmit to LCD. |
gatedClock | 50:2928c3cbdcc3 | 196 | |
gatedClock | 50:2928c3cbdcc3 | 197 | |
gatedClock | 50:2928c3cbdcc3 | 198 | Thread::wait(THREAD_3_WAITmS); // multitasking. |
gatedClock | 50:2928c3cbdcc3 | 199 | } // thread loop. |
gatedClock | 50:2928c3cbdcc3 | 200 | |
gatedClock | 50:2928c3cbdcc3 | 201 | |
gatedClock | 50:2928c3cbdcc3 | 202 | } // threadTotalTimeControl. |
gatedClock | 33:34c1bef3c4ff | 203 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 19:92b11e30aaaf | 204 | void slowClock(void) // 1Hz or thereabouts. |
gatedClock | 19:92b11e30aaaf | 205 | { |
gatedClock | 24:d39516e077ea | 206 | gcSlowClock = !gcSlowClock; // toggle clock. |
gatedClock | 19:92b11e30aaaf | 207 | } |
gatedClock | 19:92b11e30aaaf | 208 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 0:fcca4db7b32a | 209 | void initialization(void) // program initializations. |
gatedClock | 0:fcca4db7b32a | 210 | { |
gatedClock | 16:db7f0b3b2605 | 211 | gcSignalWaitEnable = 1; |
gatedClock | 0:fcca4db7b32a | 212 | } |
gatedClock | 0:fcca4db7b32a | 213 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 26:bff592483cb1 | 214 | void ISRleftButtonRising(void) // cooktime plus 60s. |
gatedClock | 1:9188d4668a88 | 215 | { |
gatedClock | 11:9cae003da12b | 216 | __disable_irq(); // debounce start. |
gatedClock | 9:cfdb9aa5857c | 217 | |
gatedClock | 26:bff592483cb1 | 218 | gtButtons.cLeftButton = 1; // detect left button. |
gatedClock | 9:cfdb9aa5857c | 219 | |
gatedClock | 9:cfdb9aa5857c | 220 | wait(DEBOUNCE); // debounce time. |
gatedClock | 9:cfdb9aa5857c | 221 | |
gatedClock | 11:9cae003da12b | 222 | __enable_irq(); // debounce done. |
gatedClock | 11:9cae003da12b | 223 | } |
gatedClock | 1:9188d4668a88 | 224 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 15:5eaa2ab1d00d | 225 | void ISRleftButtonFalling(void) // button-release debounce. |
gatedClock | 1:9188d4668a88 | 226 | { |
gatedClock | 11:9cae003da12b | 227 | __disable_irq(); // debounce start. |
gatedClock | 9:cfdb9aa5857c | 228 | |
gatedClock | 11:9cae003da12b | 229 | |
gatedClock | 9:cfdb9aa5857c | 230 | |
gatedClock | 9:cfdb9aa5857c | 231 | wait(DEBOUNCE); // debounce time. |
gatedClock | 9:cfdb9aa5857c | 232 | |
gatedClock | 11:9cae003da12b | 233 | __enable_irq(); // debounce done. |
gatedClock | 11:9cae003da12b | 234 | } |
gatedClock | 2:665ffa57031f | 235 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 26:bff592483cb1 | 236 | void ISRrightButtonRising(void) // cooktime -60s. |
gatedClock | 12:e40272e1fd8f | 237 | { |
gatedClock | 12:e40272e1fd8f | 238 | __disable_irq(); // debounce start. |
gatedClock | 12:e40272e1fd8f | 239 | |
gatedClock | 26:bff592483cb1 | 240 | gtButtons.cRightButton = 1; // detect right button. |
gatedClock | 12:e40272e1fd8f | 241 | |
gatedClock | 12:e40272e1fd8f | 242 | wait(DEBOUNCE); // debounce time. |
gatedClock | 12:e40272e1fd8f | 243 | |
gatedClock | 12:e40272e1fd8f | 244 | __enable_irq(); // debounce done. |
gatedClock | 12:e40272e1fd8f | 245 | } |
gatedClock | 12:e40272e1fd8f | 246 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 15:5eaa2ab1d00d | 247 | void ISRrightButtonFalling(void) // button-release debounce. |
gatedClock | 12:e40272e1fd8f | 248 | { |
gatedClock | 12:e40272e1fd8f | 249 | __disable_irq(); // debounce start. |
gatedClock | 12:e40272e1fd8f | 250 | |
gatedClock | 12:e40272e1fd8f | 251 | |
gatedClock | 12:e40272e1fd8f | 252 | |
gatedClock | 12:e40272e1fd8f | 253 | wait(DEBOUNCE); // debounce time. |
gatedClock | 12:e40272e1fd8f | 254 | |
gatedClock | 12:e40272e1fd8f | 255 | __enable_irq(); // debounce done. |
gatedClock | 12:e40272e1fd8f | 256 | } |
gatedClock | 12:e40272e1fd8f | 257 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 26:bff592483cb1 | 258 | void ISRtopButtonRising(void) // cook start. |
gatedClock | 12:e40272e1fd8f | 259 | { |
gatedClock | 12:e40272e1fd8f | 260 | __disable_irq(); // debounce start. |
gatedClock | 12:e40272e1fd8f | 261 | |
gatedClock | 26:bff592483cb1 | 262 | gtButtons.cTopButton = 1; // detect top button. |
gatedClock | 12:e40272e1fd8f | 263 | |
gatedClock | 12:e40272e1fd8f | 264 | wait(DEBOUNCE); // debounce time. |
gatedClock | 12:e40272e1fd8f | 265 | |
gatedClock | 12:e40272e1fd8f | 266 | __enable_irq(); // debounce done. |
gatedClock | 12:e40272e1fd8f | 267 | } |
gatedClock | 12:e40272e1fd8f | 268 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 15:5eaa2ab1d00d | 269 | void ISRtopButtonFalling(void) // button-release debounce. |
gatedClock | 12:e40272e1fd8f | 270 | { |
gatedClock | 12:e40272e1fd8f | 271 | __disable_irq(); // debounce start. |
gatedClock | 12:e40272e1fd8f | 272 | |
gatedClock | 12:e40272e1fd8f | 273 | |
gatedClock | 12:e40272e1fd8f | 274 | |
gatedClock | 12:e40272e1fd8f | 275 | wait(DEBOUNCE); // debounce time. |
gatedClock | 12:e40272e1fd8f | 276 | |
gatedClock | 12:e40272e1fd8f | 277 | __enable_irq(); // debounce done. |
gatedClock | 12:e40272e1fd8f | 278 | } |
gatedClock | 12:e40272e1fd8f | 279 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 26:bff592483cb1 | 280 | void ISRbottomButtonRising(void) // cook stop. |
gatedClock | 12:e40272e1fd8f | 281 | { |
gatedClock | 12:e40272e1fd8f | 282 | __disable_irq(); // debounce start. |
gatedClock | 12:e40272e1fd8f | 283 | |
gatedClock | 26:bff592483cb1 | 284 | gtButtons.cBottomButton = 1; // detect bottom button. |
gatedClock | 12:e40272e1fd8f | 285 | |
gatedClock | 12:e40272e1fd8f | 286 | wait(DEBOUNCE); // debounce time. |
gatedClock | 12:e40272e1fd8f | 287 | |
gatedClock | 12:e40272e1fd8f | 288 | __enable_irq(); // debounce done. |
gatedClock | 12:e40272e1fd8f | 289 | } |
gatedClock | 12:e40272e1fd8f | 290 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 15:5eaa2ab1d00d | 291 | void ISRbottomButtonFalling(void) // button-release debounce. |
gatedClock | 12:e40272e1fd8f | 292 | { |
gatedClock | 12:e40272e1fd8f | 293 | __disable_irq(); // debounce start. |
gatedClock | 12:e40272e1fd8f | 294 | |
gatedClock | 12:e40272e1fd8f | 295 | |
gatedClock | 12:e40272e1fd8f | 296 | |
gatedClock | 12:e40272e1fd8f | 297 | wait(DEBOUNCE); // debounce time. |
gatedClock | 12:e40272e1fd8f | 298 | |
gatedClock | 12:e40272e1fd8f | 299 | __enable_irq(); // debounce done. |
gatedClock | 12:e40272e1fd8f | 300 | } |
gatedClock | 12:e40272e1fd8f | 301 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 26:bff592483cb1 | 302 | void ISRcenterButtonRising(void) // toggle door state. |
gatedClock | 12:e40272e1fd8f | 303 | { |
gatedClock | 12:e40272e1fd8f | 304 | __disable_irq(); // debounce start. |
gatedClock | 12:e40272e1fd8f | 305 | |
gatedClock | 26:bff592483cb1 | 306 | gtButtons.cCenterButton = 1; // detect center button. |
gatedClock | 12:e40272e1fd8f | 307 | |
gatedClock | 12:e40272e1fd8f | 308 | wait(DEBOUNCE); // debounce time. |
gatedClock | 12:e40272e1fd8f | 309 | |
gatedClock | 12:e40272e1fd8f | 310 | __enable_irq(); // debounce done. |
gatedClock | 12:e40272e1fd8f | 311 | } |
gatedClock | 12:e40272e1fd8f | 312 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 15:5eaa2ab1d00d | 313 | void ISRcenterButtonFalling(void) // button-release debounce. |
gatedClock | 12:e40272e1fd8f | 314 | { |
gatedClock | 12:e40272e1fd8f | 315 | __disable_irq(); // debounce start. |
gatedClock | 12:e40272e1fd8f | 316 | |
gatedClock | 12:e40272e1fd8f | 317 | |
gatedClock | 12:e40272e1fd8f | 318 | |
gatedClock | 12:e40272e1fd8f | 319 | wait(DEBOUNCE); // debounce time. |
gatedClock | 12:e40272e1fd8f | 320 | |
gatedClock | 12:e40272e1fd8f | 321 | __enable_irq(); // debounce done. |
gatedClock | 12:e40272e1fd8f | 322 | } |
gatedClock | 12:e40272e1fd8f | 323 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 40:7afff79f0d8b | 324 | void temperatureThread(void const *args) // temperature measurement. |
gatedClock | 39:4e7e4d935a87 | 325 | { |
gatedClock | 45:e3207684e841 | 326 | while(1) // thread loop. |
gatedClock | 45:e3207684e841 | 327 | { |
gatedClock | 45:e3207684e841 | 328 | gfCelsius = temperature.read(); // physical measurement. |
gatedClock | 40:7afff79f0d8b | 329 | |
gatedClock | 45:e3207684e841 | 330 | Thread::wait(THREAD_1_WAITmS); // multitasking. |
gatedClock | 45:e3207684e841 | 331 | } // thread loop. |
gatedClock | 45:e3207684e841 | 332 | } // temperatureThread. |
gatedClock | 42:266d5bbbfd19 | 333 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 42:266d5bbbfd19 | 334 | void LCDthread(void const *args) // LCD display thread. |
gatedClock | 42:266d5bbbfd19 | 335 | { |
gatedClock | 44:d16e813e61ef | 336 | while(1) // thread loop. |
gatedClock | 44:d16e813e61ef | 337 | { |
gatedClock | 44:d16e813e61ef | 338 | lcd.cls(); // clear the display. |
gatedClock | 42:266d5bbbfd19 | 339 | |
gatedClock | 44:d16e813e61ef | 340 | LCD1; // line 1. |
gatedClock | 44:d16e813e61ef | 341 | lcd.printf(" total cook time: %d",gdLCDtotalCookTimeSec); |
gatedClock | 42:266d5bbbfd19 | 342 | |
gatedClock | 44:d16e813e61ef | 343 | LCD2; // line 2. |
gatedClock | 44:d16e813e61ef | 344 | lcd.printf(" remaing cook time: %d",gdCookTimeRemainingSec); |
gatedClock | 42:266d5bbbfd19 | 345 | |
gatedClock | 44:d16e813e61ef | 346 | LCD3; // line 3. |
gatedClock | 44:d16e813e61ef | 347 | lcd.printf(" temperature : %5.3f",gfLCDcelsius); |
gatedClock | 42:266d5bbbfd19 | 348 | |
gatedClock | 44:d16e813e61ef | 349 | Thread::wait(THREAD_2_WAITmS); // multitasking. |
gatedClock | 44:d16e813e61ef | 350 | } // thread loop. |
gatedClock | 44:d16e813e61ef | 351 | } // LCDthread. |
gatedClock | 42:266d5bbbfd19 | 352 | /*----------------------------------------------//----------------------------*/ |
gatedClock | 42:266d5bbbfd19 | 353 | |
gatedClock | 42:266d5bbbfd19 | 354 |