4 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
5 * Copyright 2001 Bernardo Innocenti <bernie@codewiz.org>
8 * \brief Display Blanker (implementation).
12 * \author Bernardo Innocenti <bernie@develer.com>
17 #include <drv/timer.h>
19 /* Time without input events before starting blanker */
20 #define BLK_BLANKTIMEOUT (15 * 1000) /* ms */
22 // TODO: move to blanker_hw.h
23 #include <drv/power.h>
24 #define BLK_LCDON power_LcdOn()
25 #define BLK_LCDOFF power_LcdOff()
28 /** Keyboard event handler to listen for key presses in blanker. */
29 static KbdHandler blk_KbdHandler;
31 /** Time since last key event. */
32 static ticks_t blk_lastevent;
34 /** Display blanking function is enabled. */
35 static bool blk_enabled;
37 /** Display blanker is engaged right now. */
38 static bool blk_active;
41 static bool blk_on(void)
52 static void blk_off(void)
62 void blk_retrigger(void)
64 blk_lastevent = timer_clock();
70 * Matrix-like screen saver effect
72 static void blk_hack(void)
74 static signed char blk_colstart[LCD_COLS];
80 /* Modify one column */
81 col = rand() % LCD_COLS;
82 blk_colstart[col] += rand() % 12 - 5;
85 for (col = 0; col < LCD_COLS; ++col)
87 if (blk_colstart[col] > 0)
92 for(row = LCD_ROWS-1; row; --row)
94 lcd_SetAddr(blk_layer, LCD_POS(col,row));
95 lcd_PutChar(blk_layer->Buf[LCD_POS(col,row-1)], blk_layer);
99 lcd_SetAddr(blk_layer, LCD_POS(col,0));
100 lcd_PutChar((char)(rand() % 127 + 128), blk_layer);
102 else if (blk_colstart[col] < 0)
107 for(row = 0; row < LCD_ROWS; ++row)
109 if (blk_layer->Buf[LCD_POS(col,row)] != ' ')
111 lcd_SetAddr(blk_layer, LCD_POS(col,row));
112 lcd_PutChar(' ', blk_layer);
122 static keymask_t blk_handlerFunc(keymask_t key)
124 /* key used to turn off blanker */
125 static keymask_t offkey;
127 ticks_t now = timer_clock();
137 /* remember and eat key event */
141 else if (key == offkey)
143 /* keep eating the key until released */
147 /* pass key through */
154 /* Blank timeout reached? */
155 if (now - blk_lastevent > ms_to_ticks(BLK_BLANKTIMEOUT))
157 /* Enable blanker unless already done */
158 if (!blk_active && !blk_on())
162 /* Do some nice visual effect */
171 void blk_enable(void)
176 blk_lastevent = timer_clock();
178 /* Add display blanker handler */
179 blk_KbdHandler.hook = blk_handlerFunc;
180 blk_KbdHandler.pri = 100; /* high priority */
181 blk_KbdHandler.flags = KHF_RAWKEYS;
182 kbd_addHandler(&blk_KbdHandler);
189 void blk_disable(void)
193 kbd_remHandler(&blk_KbdHandler);