homework 7

Dependencies:   mbed-rtos mbed C12832_lcd LM75B

Files at this revision

API Documentation at this revision

Comitter:
gatedClock
Date:
Thu Sep 12 20:50:22 2013 +0000
Parent:
100:fd7006aa3d05
Child:
102:5735d9cbad00
Commit message:
switching to ticker beeper.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Sep 12 20:22:43 2013 +0000
+++ b/main.cpp	Thu Sep 12 20:50:22 2013 +0000
@@ -36,7 +36,7 @@
     #define THREAD_2_WAITmS  40                 // LCD thread wait.
     #define THREAD_3_WAITmS  80                 // thread 3 wait in mS.
     #define THREAD_4_WAITmS   1                 // thread 4 wait in mS.
-    #define THREAD_5_WAITmS   1                 // FSM thread wait.
+    #define THREAD_5_WAITmS   100                 // FSM thread wait.
     #define HB_MODULO      1024                 // heartbeat modulo divisor.
     
     #define MSG_INC_TIME   0x01
@@ -115,6 +115,7 @@
     tLCD           giLCD;                       // structure instance.
     
     int      gdDiagTotalTime;
+    char gcBeepEnable;
 //--global_instances----------------------------//------------------------------ 
     Serial      pc(USBTX, USBRX);               // PuTTY terminal communication.
     LM75B        temperature(p28,p27);          // on-board thermometer.   
@@ -137,7 +138,8 @@
 
     Ticker       tickerButtonStateManager;      // manage the button states.
     Ticker       tickerSlowClock;               // generate a ~1Hz clock.
-    Ticker       tickerCookCountdown;           // remaining cook time.       
+    Ticker       tickerCookCountdown;           // remaining cook time.      
+    Ticker       tickerBeep;                    // beeper ticker. 
     
  //   Timer        timerFSMdone;                  // duration of FSM 'done' state.
 
@@ -167,6 +169,7 @@
     void temperatureThread(void const *args);   // temperature measurement.
     void LCDthread        (void const *args);   // LCD display thread.
     void speakerThread(void const *args);       // speaker thread.
+    void tickerBeeper();                        // beep oscillator.
 //==============================================//==============================
     int main(void) 
     {
@@ -197,6 +200,7 @@
       gcSlowClock = 0;
       led1 = 0;
       gtButtons.cDoorOpen = 0;                  // initialize with door closed.
+      gcBeepEnable =0;
       
  //     timerFSMdone.start();                 // start 'done' timer.
  
@@ -204,6 +208,8 @@
       
 
        tickerCookCountdown.attach_us(&tickCookRemainingTime,1000000/GRANULARITY);
+       
+       tickerBeep.attach_us(&tickerBeeper,2000);
  
       
       Thread thread_1(temperatureThread       ,NULL,osPriorityIdle,DEFAULT_STACK_SIZE,NULL);
@@ -382,6 +388,7 @@
       
       while(1)                                  // thread loop.
       {
+      pc.printf("\n\r state: %d",dFSMstate);
   
         switch (dFSMstate)                      // cook-mode state machine.
         {
@@ -842,7 +849,7 @@
       int     dSeconds;
       float   fHalfSecond;                      // cycles per half-second.
       
-      
+  /*    
       pSeconds = (int *) pSecondsBeep;
       dSeconds = *pSeconds;
  //     dSeconds = 2;
@@ -856,11 +863,20 @@
         speaker = 0;
         wait(fHalfSecond);
       }
-    
+  */  
     
     }
 /*----------------------------------------------//----------------------------*/
-
+    void tickerBeeper(void)
+    {
+      static char cState = 0;
+      if (gcBeepEnable)
+      {
+        if (cState) {speaker = 1; cState = 0;}
+        else        {speaker = 0; cState = 1;}
+      
+      
+      }
+    }
+/*----------------------------------------------//----------------------------*/
 
-
-