4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 2001 Bernie Innocenti <bernie@codewiz.org>
33 * \brief Display Blanker (implementation).
37 * \author Bernie Innocenti <bernie@codewiz.org>
41 #include "hw/hw_blanker.h"
44 #include <drv/timer.h>
46 /* Time without input events before starting blanker */
47 #define BLK_BLANKTIMEOUT (15 * 1000) /* ms */
50 #warning FIXME:Revise me!
52 /** Keyboard event handler to listen for key presses in blanker. */
53 static KbdHandler blk_KbdHandler;
55 /** Time since last key event. */
56 static ticks_t blk_lastevent;
58 /** Display blanking function is enabled. */
59 static bool blk_enabled;
61 /** Display blanker is engaged right now. */
62 static bool blk_active;
65 static bool blk_on(void)
76 static void blk_off(void)
86 void blk_retrigger(void)
88 blk_lastevent = timer_clock();
94 * Matrix-like screen saver effect
96 static void blk_hack(void)
98 static signed char blk_colstart[CONFIG_LCD_COLS];
104 /* Modify one column */
105 col = rand() % CONFIG_LCD_COLS;
106 blk_colstart[col] += rand() % 12 - 5;
109 for (col = 0; col < CONFIG_LCD_COLS; ++col)
111 if (blk_colstart[col] > 0)
116 for(row = CONFIG_LCD_ROWS-1; row; --row)
118 lcd_SetAddr(blk_layer, LCD_POS(col,row));
119 lcd_PutChar(blk_layer->Buf[LCD_POS(col,row-1)], blk_layer);
123 lcd_SetAddr(blk_layer, LCD_POS(col,0));
124 lcd_PutChar((char)(rand() % 127 + 128), blk_layer);
126 else if (blk_colstart[col] < 0)
131 for(row = 0; row < CONFIG_LCD_ROWS; ++row)
133 if (blk_layer->Buf[LCD_POS(col,row)] != ' ')
135 lcd_SetAddr(blk_layer, LCD_POS(col,row));
136 lcd_PutChar(' ', blk_layer);
146 static keymask_t blk_handlerFunc(keymask_t key)
148 /* key used to turn off blanker */
149 static keymask_t offkey;
151 ticks_t now = timer_clock();
161 /* remember and eat key event */
165 else if (key == offkey)
167 /* keep eating the key until released */
171 /* pass key through */
178 /* Blank timeout reached? */
179 if (now - blk_lastevent > ms_to_ticks(BLK_BLANKTIMEOUT))
181 /* Enable blanker unless already done */
182 if (!blk_active && !blk_on())
186 /* Do some nice visual effect */
195 void blk_enable(void)
200 blk_lastevent = timer_clock();
202 /* Add display blanker handler */
203 blk_KbdHandler.hook = blk_handlerFunc;
204 blk_KbdHandler.pri = 100; /* high priority */
205 blk_KbdHandler.flags = KHF_RAWKEYS;
206 kbd_addHandler(&blk_KbdHandler);
213 void blk_disable(void)
217 kbd_remHandler(&blk_KbdHandler);