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