blanker.c

Go to the documentation of this file.
00001 
00040 #include "blanker.h"
00041 #include "hw/hw_blanker.h"
00042 
00043 #include <drv/kbd.h>
00044 #include <drv/timer.h>
00045 
00046 /* Time without input events before starting blanker */
00047 #define BLK_BLANKTIMEOUT    (15 * 1000) /* ms */
00048 
00049 
00050 #warning FIXME:Revise me!
00051 
00053 static KbdHandler blk_KbdHandler;
00054 
00056 static ticks_t blk_lastevent;
00057 
00059 static bool blk_enabled;
00060 
00062 static bool blk_active;
00063 
00064 
00065 static bool blk_on(void)
00066 {
00067     if (!blk_active)
00068     {
00069         blk_active = true;
00070         BLK_LCDOFF;
00071     }
00072     return true;
00073 }
00074 
00075 
00076 static void blk_off(void)
00077 {
00078     if (blk_active)
00079     {
00080         blk_active = false;
00081         BLK_LCDON;
00082     }
00083 }
00084 
00085 
00086 void blk_retrigger(void)
00087 {
00088     blk_lastevent = timer_clock();
00089     blk_off();
00090 }
00091 
00092 #if 0
00093 
00096 static void blk_hack(void)
00097 {
00098     static signed char blk_colstart[CONFIG_LCD_COLS];
00099     UBYTE row, col;
00100 
00101 
00102     if (rand()%3 == 0)
00103     {
00104         /* Modify one column */
00105         col = rand() % CONFIG_LCD_COLS;
00106         blk_colstart[col] += rand() % 12 - 5;
00107     }
00108 
00109     for (col = 0; col < CONFIG_LCD_COLS; ++col)
00110     {
00111         if (blk_colstart[col] > 0)
00112         {
00113             --blk_colstart[col];
00114 
00115             /* Scroll down */
00116             for(row = CONFIG_LCD_ROWS-1; row; --row)
00117             {
00118                 lcd_SetAddr(blk_layer, LCD_POS(col,row));
00119                 lcd_PutChar(blk_layer->Buf[LCD_POS(col,row-1)], blk_layer);
00120             }
00121 
00122             /* Add new kanji */
00123             lcd_SetAddr(blk_layer, LCD_POS(col,0));
00124             lcd_PutChar((char)(rand() % 127 + 128), blk_layer);
00125         }
00126         else if (blk_colstart[col] < 0)
00127         {
00128             ++blk_colstart[col];
00129 
00130             /* Clear tail */
00131             for(row = 0; row < CONFIG_LCD_ROWS; ++row)
00132             {
00133                 if (blk_layer->Buf[LCD_POS(col,row)] != ' ')
00134                 {
00135                     lcd_SetAddr(blk_layer, LCD_POS(col,row));
00136                     lcd_PutChar(' ', blk_layer);
00137                     break;
00138                 }
00139             }
00140         }
00141     }
00142 }
00143 #endif
00144 
00145 
00146 static keymask_t blk_handlerFunc(keymask_t key)
00147 {
00148     /* key used to turn off blanker */
00149     static keymask_t offkey;
00150 
00151     ticks_t now = timer_clock();
00152 
00153     /* If key pressed */
00154     if (key != 0)
00155     {
00156         blk_lastevent = now;
00157         if (blk_active)
00158         {
00159             blk_off();
00160 
00161             /* remember and eat key event */
00162             offkey = key;
00163             key = 0;
00164         }
00165         else if (key == offkey)
00166         {
00167             /* keep eating the key until released */
00168             key = 0;
00169         }
00170 
00171         /* pass key through */
00172         return key;
00173     }
00174 
00175     /* reset off key */
00176     offkey = 0;
00177 
00178     /* Blank timeout reached? */
00179     if (now - blk_lastevent > ms_to_ticks(BLK_BLANKTIMEOUT))
00180     {
00181         /* Enable blanker unless already done */
00182         if (!blk_active && !blk_on())
00183             return 0;
00184 
00185 #if 0
00186         /* Do some nice visual effect */
00187         blk_hack();
00188 #endif /* _DEBUG */
00189     }
00190 
00191     return 0;
00192 }
00193 
00194 
00195 void blk_enable(void)
00196 {
00197     if (!blk_enabled)
00198     {
00199         blk_active = false;
00200         blk_lastevent = timer_clock();
00201 
00202         /* Add display blanker handler */
00203         blk_KbdHandler.hook = blk_handlerFunc;
00204         blk_KbdHandler.pri = 100; /* high priority */
00205         blk_KbdHandler.flags = KHF_RAWKEYS;
00206         kbd_addHandler(&blk_KbdHandler);
00207 
00208         blk_enabled = true;
00209     }
00210 }
00211 
00212 
00213 void blk_disable(void)
00214 {
00215     if (blk_enabled)
00216     {
00217         kbd_remHandler(&blk_KbdHandler);
00218         blk_off();
00219         blk_enabled = false;
00220     }
00221 }
00222