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).
36 * \author Bernie Innocenti <bernie@codewiz.org>
40 #include "hw/hw_blanker.h"
43 #include <drv/timer.h>
45 /* Time without input events before starting blanker */
46 #define BLK_BLANKTIMEOUT (15 * 1000) /* ms */
49 #warning FIXME:Revise me!
51 /** Keyboard event handler to listen for key presses in blanker. */
52 static KbdHandler blk_KbdHandler;
54 /** Time since last key event. */
55 static ticks_t blk_lastevent;
57 /** Display blanking function is enabled. */
58 static bool blk_enabled;
60 /** Display blanker is engaged right now. */
61 static bool blk_active;
64 static bool blk_on(void)
75 static void blk_off(void)
85 void blk_retrigger(void)
87 blk_lastevent = timer_clock();
93 * Matrix-like screen saver effect
95 static void blk_hack(void)
97 static signed char blk_colstart[CONFIG_LCD_COLS];
103 /* Modify one column */
104 col = rand() % CONFIG_LCD_COLS;
105 blk_colstart[col] += rand() % 12 - 5;
108 for (col = 0; col < CONFIG_LCD_COLS; ++col)
110 if (blk_colstart[col] > 0)
115 for(row = CONFIG_LCD_ROWS-1; row; --row)
117 lcd_SetAddr(blk_layer, LCD_POS(col,row));
118 lcd_PutChar(blk_layer->Buf[LCD_POS(col,row-1)], blk_layer);
122 lcd_SetAddr(blk_layer, LCD_POS(col,0));
123 lcd_PutChar((char)(rand() % 127 + 128), blk_layer);
125 else if (blk_colstart[col] < 0)
130 for(row = 0; row < CONFIG_LCD_ROWS; ++row)
132 if (blk_layer->Buf[LCD_POS(col,row)] != ' ')
134 lcd_SetAddr(blk_layer, LCD_POS(col,row));
135 lcd_PutChar(' ', blk_layer);
145 static keymask_t blk_handlerFunc(keymask_t key)
147 /* key used to turn off blanker */
148 static keymask_t offkey;
150 ticks_t now = timer_clock();
160 /* remember and eat key event */
164 else if (key == offkey)
166 /* keep eating the key until released */
170 /* pass key through */
177 /* Blank timeout reached? */
178 if (now - blk_lastevent > ms_to_ticks(BLK_BLANKTIMEOUT))
180 /* Enable blanker unless already done */
181 if (!blk_active && !blk_on())
185 /* Do some nice visual effect */
194 void blk_enable(void)
199 blk_lastevent = timer_clock();
201 /* Add display blanker handler */
202 blk_KbdHandler.hook = blk_handlerFunc;
203 blk_KbdHandler.pri = 100; /* high priority */
204 blk_KbdHandler.flags = KHF_RAWKEYS;
205 kbd_addHandler(&blk_KbdHandler);
212 void blk_disable(void)
216 kbd_remHandler(&blk_KbdHandler);