From 46ce1bc93240f6663d01031d3e1a6b6f0208e411 Mon Sep 17 00:00:00 2001 From: bernie Date: Sat, 3 Jun 2006 13:57:15 +0000 Subject: [PATCH] Add simple screen blanker. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@658 38d2e660-2303-0410-9eaa-f027e97ec537 --- mware/blanker.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++++ mware/blanker.h | 21 ++++++ 2 files changed, 218 insertions(+) create mode 100755 mware/blanker.c create mode 100755 mware/blanker.h diff --git a/mware/blanker.c b/mware/blanker.c new file mode 100755 index 00000000..6e7f1103 --- /dev/null +++ b/mware/blanker.c @@ -0,0 +1,197 @@ +/** + * \file + * + * + * \brief Display Blanker (implementation). + * + * \version $Id$ + * + * \author Bernardo Innocenti + */ + +#include "blanker.h" +#include +#include + +/* Time without input events before starting blanker */ +#define BLK_BLANKTIMEOUT (15 * 1000) /* ms */ + +// TODO: move to blanker_hw.h +#include +#define BLK_LCDON power_LcdOn() +#define BLK_LCDOFF power_LcdOff() + + +/** Keyboard event handler to listen for key presses in blanker. */ +static KbdHandler blk_KbdHandler; + +/** Time since last key event. */ +static ticks_t blk_lastevent; + +/** Display blanking function is enabled. */ +static bool blk_enabled; + +/** Display blanker is engaged right now. */ +static bool blk_active; + + +static bool blk_on(void) +{ + if (!blk_active) + { + blk_active = true; + BLK_LCDOFF; + } + return true; +} + + +static void blk_off(void) +{ + if (blk_active) + { + blk_active = false; + BLK_LCDON; + } +} + + +void blk_retrigger(void) +{ + blk_lastevent = timer_clock(); + blk_off(); +} + +#if 0 +/** + * Matrix-like screen saver effect + */ +static void blk_hack(void) +{ + static signed char blk_colstart[LCD_COLS]; + UBYTE row, col; + + + if (rand()%3 == 0) + { + /* Modify one column */ + col = rand() % LCD_COLS; + blk_colstart[col] += rand() % 12 - 5; + } + + for (col = 0; col < LCD_COLS; ++col) + { + if (blk_colstart[col] > 0) + { + --blk_colstart[col]; + + /* Scroll down */ + for(row = LCD_ROWS-1; row; --row) + { + lcd_SetAddr(blk_layer, LCD_POS(col,row)); + lcd_PutChar(blk_layer->Buf[LCD_POS(col,row-1)], blk_layer); + } + + /* Add new kanji */ + lcd_SetAddr(blk_layer, LCD_POS(col,0)); + lcd_PutChar((char)(rand() % 127 + 128), blk_layer); + } + else if (blk_colstart[col] < 0) + { + ++blk_colstart[col]; + + /* Clear tail */ + for(row = 0; row < LCD_ROWS; ++row) + { + if (blk_layer->Buf[LCD_POS(col,row)] != ' ') + { + lcd_SetAddr(blk_layer, LCD_POS(col,row)); + lcd_PutChar(' ', blk_layer); + break; + } + } + } + } +} +#endif + + +static keymask_t blk_handlerFunc(keymask_t key) +{ + /* key used to turn off blanker */ + static keymask_t offkey; + + ticks_t now = timer_clock(); + + /* If key pressed */ + if (key != 0) + { + blk_lastevent = now; + if (blk_active) + { + blk_off(); + + /* remember and eat key event */ + offkey = key; + key = 0; + } + else if (key == offkey) + { + /* keep eating the key until released */ + key = 0; + } + + /* pass key through */ + return key; + } + + /* reset off key */ + offkey = 0; + + /* Blank timeout reached? */ + if (now - blk_lastevent > ms_to_ticks(BLK_BLANKTIMEOUT)) + { + /* Enable blanker unless already done */ + if (!blk_active && !blk_on()) + return 0; + +#if 0 + /* Do some nice visual effect */ + blk_hack(); +#endif /* _DEBUG */ + } + + return 0; +} + + +void blk_enable(void) +{ + if (!blk_enabled) + { + blk_active = false; + blk_lastevent = timer_clock(); + + /* Add display blanker handler */ + blk_KbdHandler.hook = blk_handlerFunc; + blk_KbdHandler.pri = 100; /* high priority */ + blk_KbdHandler.flags = KHF_RAWKEYS; + kbd_addHandler(&blk_KbdHandler); + + blk_enabled = true; + } +} + + +void blk_disable(void) +{ + if (blk_enabled) + { + kbd_remHandler(&blk_KbdHandler); + blk_off(); + blk_enabled = false; + } +} diff --git a/mware/blanker.h b/mware/blanker.h new file mode 100755 index 00000000..ee49b440 --- /dev/null +++ b/mware/blanker.h @@ -0,0 +1,21 @@ +/** + * \file + * + * + * \brief Display Blanker (implementation). + * + * \version $Id$ + * + * \author Bernardo Innocenti + */ +#ifndef MWARE_BLANKER_H +#define MWARE_BLANKER_H + +extern void blk_enable(void); +extern void blk_disable(void); +extern void blk_retrigger(void); + +#endif /* MWARE_BLANKER_H */ -- 2.25.1