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 Bernardo Innocenti <bernie@codewiz.org>
33 * \brief Display Blanker (implementation).
37 * \author Bernardo Innocenti <bernie@develer.com>
42 #include <drv/timer.h>
44 /* Time without input events before starting blanker */
45 #define BLK_BLANKTIMEOUT (15 * 1000) /* ms */
47 // TODO: move to blanker_hw.h
48 #include <drv/power.h>
49 #define BLK_LCDON power_LcdOn()
50 #define BLK_LCDOFF power_LcdOff()
53 /** Keyboard event handler to listen for key presses in blanker. */
54 static KbdHandler blk_KbdHandler;
56 /** Time since last key event. */
57 static ticks_t blk_lastevent;
59 /** Display blanking function is enabled. */
60 static bool blk_enabled;
62 /** Display blanker is engaged right now. */
63 static bool blk_active;
66 static bool blk_on(void)
77 static void blk_off(void)
87 void blk_retrigger(void)
89 blk_lastevent = timer_clock();
95 * Matrix-like screen saver effect
97 static void blk_hack(void)
99 static signed char blk_colstart[LCD_COLS];
105 /* Modify one column */
106 col = rand() % LCD_COLS;
107 blk_colstart[col] += rand() % 12 - 5;
110 for (col = 0; col < LCD_COLS; ++col)
112 if (blk_colstart[col] > 0)
117 for(row = LCD_ROWS-1; row; --row)
119 lcd_SetAddr(blk_layer, LCD_POS(col,row));
120 lcd_PutChar(blk_layer->Buf[LCD_POS(col,row-1)], blk_layer);
124 lcd_SetAddr(blk_layer, LCD_POS(col,0));
125 lcd_PutChar((char)(rand() % 127 + 128), blk_layer);
127 else if (blk_colstart[col] < 0)
132 for(row = 0; row < LCD_ROWS; ++row)
134 if (blk_layer->Buf[LCD_POS(col,row)] != ' ')
136 lcd_SetAddr(blk_layer, LCD_POS(col,row));
137 lcd_PutChar(' ', blk_layer);
147 static keymask_t blk_handlerFunc(keymask_t key)
149 /* key used to turn off blanker */
150 static keymask_t offkey;
152 ticks_t now = timer_clock();
162 /* remember and eat key event */
166 else if (key == offkey)
168 /* keep eating the key until released */
172 /* pass key through */
179 /* Blank timeout reached? */
180 if (now - blk_lastevent > ms_to_ticks(BLK_BLANKTIMEOUT))
182 /* Enable blanker unless already done */
183 if (!blk_active && !blk_on())
187 /* Do some nice visual effect */
196 void blk_enable(void)
201 blk_lastevent = timer_clock();
203 /* Add display blanker handler */
204 blk_KbdHandler.hook = blk_handlerFunc;
205 blk_KbdHandler.pri = 100; /* high priority */
206 blk_KbdHandler.flags = KHF_RAWKEYS;
207 kbd_addHandler(&blk_KbdHandler);
214 void blk_disable(void)
218 kbd_remHandler(&blk_KbdHandler);