From 9d633bdc7113f0050a0b35df5245dee2b819a273 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 7 Mar 2011 19:33:50 +0000 Subject: [console] Add a timeout parameter to getkey() Signed-off-by: Michael Brown --- src/core/getkey.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/core/getkey.c') diff --git a/src/core/getkey.c b/src/core/getkey.c index 5710f1900..b8e6af786 100644 --- a/src/core/getkey.c +++ b/src/core/getkey.c @@ -35,13 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER ); /** * Read character from console if available within timeout period * - * @v timeout Timeout period, in ticks + * @v timeout Timeout period, in ticks (0=indefinite) * @ret character Character read from console */ -int getchar_timeout ( unsigned long timeout ) { +static int getchar_timeout ( unsigned long timeout ) { unsigned long start = currticks(); - while ( ( currticks() - start ) < timeout ) { + while ( ( timeout == 0 ) || ( ( currticks() - start ) < timeout ) ) { step(); if ( iskey() ) return getchar(); @@ -53,6 +53,7 @@ int getchar_timeout ( unsigned long timeout ) { /** * Get single keypress * + * @v timeout Timeout period, in ticks (0=indefinite) * @ret key Key pressed * * The returned key will be an ASCII value or a KEY_XXX special @@ -60,11 +61,11 @@ int getchar_timeout ( unsigned long timeout ) { * will return "special" keys (e.g. cursor keys) as a series of * characters forming an ANSI escape sequence. */ -int getkey ( void ) { +int getkey ( unsigned long timeout ) { int character; unsigned int n = 0; - character = getchar(); + character = getchar_timeout ( timeout ); if ( character != ESC ) return character; -- cgit v1.2.3-55-g7522