blanker.c
Go to the documentation of this file.00001
00040 #include "blanker.h"
00041 #include <drv/kbd.h>
00042 #include <drv/timer.h>
00043
00044
00045 #define BLK_BLANKTIMEOUT (15 * 1000)
00046
00047
00048 #include <drv/power.h>
00049 #define BLK_LCDON power_LcdOn()
00050 #define BLK_LCDOFF power_LcdOff()
00051
00052
00054 static KbdHandler blk_KbdHandler;
00055
00057 static ticks_t blk_lastevent;
00058
00060 static bool blk_enabled;
00061
00063 static bool blk_active;
00064
00065
00066 static bool blk_on(void)
00067 {
00068 if (!blk_active)
00069 {
00070 blk_active = true;
00071 BLK_LCDOFF;
00072 }
00073 return true;
00074 }
00075
00076
00077 static void blk_off(void)
00078 {
00079 if (blk_active)
00080 {
00081 blk_active = false;
00082 BLK_LCDON;
00083 }
00084 }
00085
00086
00087 void blk_retrigger(void)
00088 {
00089 blk_lastevent = timer_clock();
00090 blk_off();
00091 }
00092
00093 #if 0
00094
00097 static void blk_hack(void)
00098 {
00099 static signed char blk_colstart[LCD_COLS];
00100 UBYTE row, col;
00101
00102
00103 if (rand()%3 == 0)
00104 {
00105
00106 col = rand() % LCD_COLS;
00107 blk_colstart[col] += rand() % 12 - 5;
00108 }
00109
00110 for (col = 0; col < LCD_COLS; ++col)
00111 {
00112 if (blk_colstart[col] > 0)
00113 {
00114 --blk_colstart[col];
00115
00116
00117 for(row = LCD_ROWS-1; row; --row)
00118 {
00119 lcd_SetAddr(blk_layer, LCD_POS(col,row));
00120 lcd_PutChar(blk_layer->Buf[LCD_POS(col,row-1)], blk_layer);
00121 }
00122
00123
00124 lcd_SetAddr(blk_layer, LCD_POS(col,0));
00125 lcd_PutChar((char)(rand() % 127 + 128), blk_layer);
00126 }
00127 else if (blk_colstart[col] < 0)
00128 {
00129 ++blk_colstart[col];
00130
00131
00132 for(row = 0; row < LCD_ROWS; ++row)
00133 {
00134 if (blk_layer->Buf[LCD_POS(col,row)] != ' ')
00135 {
00136 lcd_SetAddr(blk_layer, LCD_POS(col,row));
00137 lcd_PutChar(' ', blk_layer);
00138 break;
00139 }
00140 }
00141 }
00142 }
00143 }
00144 #endif
00145
00146
00147 static keymask_t blk_handlerFunc(keymask_t key)
00148 {
00149
00150 static keymask_t offkey;
00151
00152 ticks_t now = timer_clock();
00153
00154
00155 if (key != 0)
00156 {
00157 blk_lastevent = now;
00158 if (blk_active)
00159 {
00160 blk_off();
00161
00162
00163 offkey = key;
00164 key = 0;
00165 }
00166 else if (key == offkey)
00167 {
00168
00169 key = 0;
00170 }
00171
00172
00173 return key;
00174 }
00175
00176
00177 offkey = 0;
00178
00179
00180 if (now - blk_lastevent > ms_to_ticks(BLK_BLANKTIMEOUT))
00181 {
00182
00183 if (!blk_active && !blk_on())
00184 return 0;
00185
00186 #if 0
00187
00188 blk_hack();
00189 #endif
00190 }
00191
00192 return 0;
00193 }
00194
00195
00196 void blk_enable(void)
00197 {
00198 if (!blk_enabled)
00199 {
00200 blk_active = false;
00201 blk_lastevent = timer_clock();
00202
00203
00204 blk_KbdHandler.hook = blk_handlerFunc;
00205 blk_KbdHandler.pri = 100;
00206 blk_KbdHandler.flags = KHF_RAWKEYS;
00207 kbd_addHandler(&blk_KbdHandler);
00208
00209 blk_enabled = true;
00210 }
00211 }
00212
00213
00214 void blk_disable(void)
00215 {
00216 if (blk_enabled)
00217 {
00218 kbd_remHandler(&blk_KbdHandler);
00219 blk_off();
00220 blk_enabled = false;
00221 }
00222 }