ui_sync_led.c File Reference

Providing control of the flash synchronize LED on the UI board since 2010. More...

Go to the source code of this file.

Defines

#define FLASH_PERIOD_HALF   500
#define FLASH_PERIOD_HALFQUARTER   125
#define FLASH_PERIOD_QUARTER   250
#define FLASH_PERIOD_SEC   1000
#define LED_ON_PERIOD   50

Functions

void ui_sync_led_flash (void)
 Updates the flashing of the sync led based on the timestamp.
static void ui_sync_led_flash_pattern (void)
 Calculates the flash pattern for the current timestamp and blinks the sync led appropriately.
void ui_sync_led_init (INT_VOID_F timestamp_in)
 Initializes the ui_sync_led module.
void ui_sync_led_off (void)
 Turns off the sync led.
void ui_sync_led_on (void)
 Turns on the sync led.

Variables

static INT_VOID_F led_get_timestamp = intvoid
 A function which returns the current timestamp on the board.
int led_on_flag = 0
int ts = 0

Detailed Description

Providing control of the flash synchronize LED on the UI board since 2010.

Author:
Nan(Sarah) Xiao
Date:
April 2010

Definition in file ui_sync_led.c.


Function Documentation

void ui_sync_led_flash ( void   ) 

Updates the flashing of the sync led based on the timestamp.

Call this every row of the schedule.

Definition at line 58 of file ui_sync_led.c.

References led_get_timestamp, and ui_sync_led_flash_pattern().

00059 {  
00060   static unsigned short flag = 0;
00061   unsigned long remainder;
00062 
00063   remainder = led_get_timestamp() % FLASH_PERIOD_HALFQUARTER;
00064   
00065   //This logic is intended to detect the first iteration at which the remainder
00066   //has passed zero, and to run the ui_sync_led_flash_pattern at that time only.
00067   //Note that the remainder is non-negative.
00068   if (remainder < (FLASH_PERIOD_HALFQUARTER >> 1))
00069   {
00070     if (flag)
00071     {
00072       ui_sync_led_flash_pattern();
00073     }
00074     flag = 0;       
00075   }
00076   else
00077   {
00078     flag = 1;
00079   } 
00080 }

static void ui_sync_led_flash_pattern ( void   )  [static]

Calculates the flash pattern for the current timestamp and blinks the sync led appropriately.

ui_sync_led_on();

Definition at line 86 of file ui_sync_led.c.

References led_get_timestamp, ui_sync_led_off(), and ui_sync_led_on().

Referenced by ui_sync_led_flash().

00087 {
00088   static int sync_flag = 0;
00089   static unsigned short flag = 0;
00090   unsigned long remainder = led_get_timestamp() % FLASH_PERIOD_SEC;
00091   int sync_count = (led_get_timestamp() / FLASH_PERIOD_HALFQUARTER) % 8;
00092 
00093   if(led_get_timestamp() - ts > LED_ON_PERIOD) led_on_flag = 0;
00094 
00095   //This logic is intended to detect the first iteration at which the remainder
00096   //has passed zero, and to run the ui_sync_led_flash_pattern at that time only.
00097   //Note that the remainder is non-negative.
00098   if (remainder < (FLASH_PERIOD_SEC >> 1))
00099   {
00100     if (flag)
00101     {
00102       sync_flag++;
00103       if (sync_flag >= 10)
00104       {
00105         sync_flag = 0;
00106       }     
00107       flag = 0;
00108     }       
00109   }
00110   else
00111   {
00112     flag = 1;
00113   }
00114   switch (sync_flag) {  
00115     case 0:
00116       if ((sync_count == 0) || (sync_count == 6)){
00117         led_on_flag = 1;
00118         ts = led_get_timestamp();
00119       } 
00120 //      else if (sync_count == 2){
00121 //        ui_sync_led_off();
00122 //      }
00123       break;   
00124     case 1:
00125       if (sync_count == 2){
00126         led_on_flag = 1;
00127         ts = led_get_timestamp();
00128       } 
00129 //      else if (sync_count == 4){
00130 //        ui_sync_led_off();
00131 //      } 
00132       break;     
00133     case 2:
00134       if ((sync_count == 0) || (sync_count == 4)){
00135         led_on_flag = 1;
00136         ts = led_get_timestamp();
00137       } 
00138 //      else if ((sync_count == 2) || (sync_count == 6)){
00139 //        ui_sync_led_off();
00140 //      }  
00141       break;     
00142     case 3:
00143       if ((sync_count == 0) || (sync_count == 7)){
00144         //ui_sync_led_on();
00145         led_on_flag = 1;
00146         ts = led_get_timestamp();
00147       } 
00148 //      else if (sync_count == 2){
00149 //        ui_sync_led_off();
00150 //      } 
00151       break;
00152     case 4:
00153       if ((sync_count == 2) || (sync_count == 6)){
00154         //ui_sync_led_on();
00155         led_on_flag = 1;
00156         ts = led_get_timestamp();
00157       } 
00158 //      if ((sync_count == 0) || (sync_count == 4)){
00159 //        ui_sync_led_off();
00160 //      } 
00161       break;
00162     case 5:
00163       if (sync_count == 2){
00165         led_on_flag = 1;
00166         ts = led_get_timestamp();
00167       } 
00168 //      else if ((sync_count == 0) || (sync_count == 4)){
00169 //        ui_sync_led_off();
00170 //      } 
00171       break;
00172     case 6:
00173       if ((sync_count == 0) || (sync_count == 4)){
00174         ui_sync_led_on();
00175       } 
00176 //      else if ((sync_count == 2) || (sync_count == 6)){
00177 //        ui_sync_led_off();
00178 //      }  
00179       break;
00180     case 7:
00181       if ((sync_count == 0) || (sync_count == 4)){
00182         //ui_sync_led_on();
00183         led_on_flag = 1;
00184         ts = led_get_timestamp();
00185       } 
00186 //      else if ((sync_count == 2) || (sync_count == 6)){
00187 //        ui_sync_led_off();
00188 //      } 
00189       break;
00190     case 8:
00191       if ((sync_count == 0) || (sync_count == 4) || (sync_count == 6)){
00192         //ui_sync_led_on();
00193         led_on_flag = 1;
00194         ts = led_get_timestamp();
00195       } 
00196 //      else if ((sync_count == 2) || (sync_count == 5) || (sync_count == 7)){
00197 //        ui_sync_led_off();
00198 //      }
00199       break;
00200       
00201     case 9:
00202       if ((sync_count == 0) || (sync_count == 2) || (sync_count == 4) || (sync_count == 6)){
00203         //ui_sync_led_on();
00204         led_on_flag = 1;
00205         ts = led_get_timestamp();
00206       } 
00207 //      else if ((sync_count == 1) || (sync_count == 3) || (sync_count == 5) || (sync_count == 7)){
00208 //        ui_sync_led_off();
00209 //      }
00210       break;           
00211   }
00212 
00213   //flash LED
00214   if(led_on_flag == 1) ui_sync_led_on();
00215   else ui_sync_led_off();
00216 }

void ui_sync_led_init ( INT_VOID_F  timestamp_in  ) 

Initializes the ui_sync_led module.

Must call this function first.

Parameters:
timestamp_in A function which takes no parameters and returns the timestamp as an int.

Definition at line 30 of file ui_sync_led.c.

References led_get_timestamp, and ui_sync_led_off().

00031 {
00032   led_get_timestamp = timestamp_in;
00033   ui_sync_led_off();
00034 }

Generated on Tue Jun 29 16:36:15 2010 by  doxygen 1.6.3