blink.c

Back to Blink sample application.

00001 
00017 #include <appTimer.h>
00018 #include <zdo.h>
00019 #include <blink.h>
00020 
00021 static HAL_AppTimer_t blinkTimer;                           // Blink timer.
00022 
00023 #ifndef _BUTTONS_
00024 static HAL_AppTimer_t changeBlinkTimer;                     // Buttons emulation timer.
00025 #endif //#ifndef _BUTTONS_
00026 
00027 static void buttonsReleased(uint8_t buttonNumber);          // Button release event handler.
00028 static void blinkTimerFired(void);                          // blinkTimer handler.
00029 
00030 #ifndef _BUTTONS_
00031 static void changeTimerFired(void);                         //Buttons emulation timer handler. 
00032 #endif //#ifndef _BUTTONS_
00033 
00034 /*******************************************************************************
00035   Description: application task handler.
00036 
00037   Parameters: none.
00038   
00039   Returns: nothing.
00040 *******************************************************************************/
00041 void APL_TaskHandler(void)
00042 {
00043   BSP_OpenLeds(); // Enable LEDs 
00044 
00045 #ifdef _BUTTONS_
00046   BSP_OpenButtons(NULL, buttonsReleased);         // Register button event handlers
00047 #else
00048   // Configure blink timer
00049   changeBlinkTimer.interval = 10000;              // Timer interval
00050   changeBlinkTimer.mode     = TIMER_REPEAT_MODE;  // Repeating mode (TIMER_REPEAT_MODE or TIMER_ONE_SHOT_MODE)
00051   changeBlinkTimer.callback = changeTimerFired;   // Callback function for timer fire event
00052   HAL_StartAppTimer(&changeBlinkTimer);           // Start blink timer
00053 #endif //#ifdef _BUTTONS_
00054   
00055   // Configure blink timer
00056   blinkTimer.interval = BLINK_INTERVAL;           // Timer interval
00057   blinkTimer.mode     = TIMER_REPEAT_MODE;        // Repeating mode (TIMER_REPEAT_MODE or TIMER_ONE_SHOT_MODE)
00058   blinkTimer.callback = blinkTimerFired;          // Callback function for timer fire event
00059   HAL_StartAppTimer(&blinkTimer);                 // Start blink timer
00060 }
00061 
00062 #ifndef _BUTTONS_
00063 void changeTimerFired(void)
00064 {
00065   static uint8_t button = HALF_PERIOD_BUTTON;
00066   //Buttons emulation 
00067   buttonsReleased(button);
00068   if (HALF_PERIOD_BUTTON == button)
00069     button = DOUBLE_PERIOD_BUTTON;
00070   else
00071     button = HALF_PERIOD_BUTTON;
00072 }
00073 #endif //#ifndef _BUTTONS_
00074 
00075 /*******************************************************************************
00076   Description: blinking timer fire event handler.
00077 
00078   Parameters: none.
00079   
00080   Returns: nothing.
00081 *******************************************************************************/
00082 static void blinkTimerFired()
00083 {
00084   BSP_ToggleLed(LED_RED);
00085   BSP_ToggleLed(LED_YELLOW);
00086   BSP_ToggleLed(LED_GREEN);
00087 }
00088 
00089 /*******************************************************************************
00090   Description: button release event handler.
00091 
00092   Parameters: buttonNumber - released button number.
00093   
00094   Returns: nothing.
00095 *******************************************************************************/
00096 static void buttonsReleased(uint8_t buttonNumber)
00097 {
00098   HAL_StopAppTimer(&blinkTimer); // Stop blink timer
00099   
00100   // Dependent on button being released, update blink interval
00101   if (HALF_PERIOD_BUTTON == buttonNumber)
00102   {
00103     blinkTimer.interval /= 2;
00104     if (blinkTimer.interval < MIN_BLINK_INTERVAL)
00105       blinkTimer.interval = MIN_BLINK_INTERVAL;
00106   }
00107   else if (DOUBLE_PERIOD_BUTTON == buttonNumber)
00108   {
00109     blinkTimer.interval *= 2;
00110     if (blinkTimer.interval > MAX_BLINK_INTERVAL)
00111       blinkTimer.interval = MAX_BLINK_INTERVAL;
00112   }
00113 
00114   blinkTimerFired();              // Update LED status immediately.
00115   HAL_StartAppTimer(&blinkTimer); // Start updated blink timer.
00116 }
00117 
00118 /*******************************************************************************
00119   Description: just a stub.
00120 
00121   Parameters: are not used.
00122   
00123   Returns: nothing.
00124 *******************************************************************************/
00125 void ZDO_MgmtNwkUpdateNotf(ZDO_MgmtNwkUpdateNotf_t *nwkParams) 
00126 {
00127   nwkParams = nwkParams;  // Unused parameter warning prevention
00128 }
00129 
00130 /*******************************************************************************
00131   Description: just a stub.
00132 
00133   Parameters: none.
00134   
00135   Returns: nothing.
00136 *******************************************************************************/
00137 void ZDO_WakeUpInd(void) 
00138 {
00139 }
00140 
00141 /*******************************************************************************
00142   Description: just a stub.
00143 
00144   Parameters: none.
00145   
00146   Returns: nothing.
00147 *******************************************************************************/
00148 void ZDO_SleepInd(void) 
00149 {
00150 }
00151 
00152 //eof blink.c

Generated on Tue Feb 17 16:44:56 2009 for BitCloud Stack Documentation by  doxygen 1.5.1-p1