homework 7
Dependencies: mbed-rtos mbed C12832_lcd LM75B
Diff: main.cpp
- Revision:
- 94:551b1df4b10c
- Parent:
- 93:0e93e4a23f2b
- Child:
- 95:7e391a5951d1
--- a/main.cpp Thu Sep 12 18:13:12 2013 +0000 +++ b/main.cpp Thu Sep 12 18:46:43 2013 +0000 @@ -57,10 +57,13 @@ #define RT_PAUSE 0x03 // remaining-time don't change. #define RT_CLEAR 0x04 // remaining-time set to zero. + #define TEMP_READ 0x01 // temperature synthesizer control. + #define TEMP_CALC 0x02 // temperature synthesizer control. + #define GRANULARITY 0x400 // 1-second countdown ticker granularity. #define MAXSECONDS 180 // maximum microwave-on time. #define BEEPTIME 3 // beep duration in S. - #define BEEPFREQ 400 // beep frequency in Hz. + #define BEEPFREQ 300 // beep frequency in Hz. #define DEBUG1 // debug preprocessor control. //--global_definitions--------------------------//------------------------------ @@ -96,6 +99,7 @@ Queue<int, 1> queueSetRemainingTime; // tell countdown it's start time. Queue<int, 1> queueFSMnewState; // latest FSM state. Queue<int, 1> queueSpeakerControl; // speaker control queue. + Queue<int, 1> queueTemperatureControl; // control the temperature synthesizer. //--global_variables----------------------------//------------------------------ char gcSignalWaitEnable; // 1 to wait on a signal. char gcSlowClock; // slow-clock signal. @@ -126,6 +130,7 @@ Timer debounceTimer; // button debounce timer. Timer beepTimer; // beep-duration timer. + Timer temperatureTimer; // how often to raise temperature. Ticker tickerButtonStateManager; // manage the button states. Ticker tickerSlowClock; // generate a ~1Hz clock. @@ -340,6 +345,11 @@ dBeepSeconds = BEEPTIME; + // queueModTotalTime.put((int *) dMessage,1);// pre + + + queueTemperatureControl.put((int *) TEMP_READ,1); + while(1) // thread loop. { @@ -350,12 +360,13 @@ { led0 = 0; if (dFSMstate != dFSMstateLast) // if just entered state. - { + { + queueTemperatureControl.put((int *) TEMP_READ,1); } giLCD.dTotalCookTime = giRemainingTime.dTotalTime; giLCD.dRemainingTime = 0; // suppress remaining time display. - giLCD.fCelsius = 0; +// giLCD.fCelsius = 0; giRemainingTime.cControl = RT_PRELOAD; dFSMstateLast = dFSMstate; // determine next state. @@ -368,11 +379,12 @@ if (dFSMstate != dFSMstateLast) // if just entered state. { giRemainingTime.cControl = RT_DECREMENT; + queueTemperatureControl.put((int *) TEMP_CALC,1); } giLCD.dTotalCookTime = giRemainingTime.dTotalTime; giLCD.dRemainingTime = giRemainingTime.dRemainingTime; - giLCD.fCelsius = 0; + // giLCD.fCelsius = 0; @@ -395,7 +407,7 @@ giLCD.dTotalCookTime = giRemainingTime.dTotalTime; giLCD.dRemainingTime = giRemainingTime.dRemainingTime; - giLCD.fCelsius = 0; + // giLCD.fCelsius = 0; giRemainingTime.cControl = RT_PAUSE; @@ -418,7 +430,7 @@ giLCD.dTotalCookTime = giRemainingTime.dTotalTime; giLCD.dRemainingTime = giRemainingTime.dRemainingTime; - giLCD.fCelsius = 0; + // giLCD.fCelsius = 0; giRemainingTime.cControl = RT_DECREMENT; @@ -450,7 +462,7 @@ giLCD.dTotalCookTime = giRemainingTime.dTotalTime; giLCD.dRemainingTime = giRemainingTime.dRemainingTime; - giLCD.fCelsius = 0; +// giLCD.fCelsius = 0; @@ -614,12 +626,39 @@ { debounceTimer.reset(); // begin debounce period. } -/*----------------------------------------------//----------------------------*/ +/*----------------------------------------------//----------------------------*/ //==================================================== void temperatureThread(void const *args) // temperature measurement. { + int dTempControl = 0; // temperature control. + osEvent queueEvent; // from button state manager. + + temperatureTimer.start(); + while(1) // thread loop. { + // obtain temperature command. + queueEvent = queueTemperatureControl.get(1); + if (queueEvent.status == osEventMessage) + { + dTempControl = (int) queueEvent.value.p; + } + + if (dTempControl == TEMP_READ) gfCelsius = temperature.read(); // physical measurement. + + if (dTempControl == TEMP_CALC) + { + if (temperatureTimer.read() > 1) + { + temperatureTimer.reset(); + gfCelsius += (1.0 / 6.0); + } + } + + + + giLCD.fCelsius = gfCelsius; + Thread::wait(THREAD_1_WAITmS); // multitasking. } // thread loop.