<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
Originally posted May 2003. Support to test for incoming characters
waiting is kind of there. This may help you out<br>
<br>
Oliver - Could the test part of this be usefully added to nutos as
kbhit? - Looks ugly but is pretty straightforward to use.<br>
<br>
Regards<br>
Brett<br>
<br>
Hi
<br>
<br>
The following snippet of code can be used to check for the existance of
incoming characters without having to actually receive them. Useful
for "Press the Return key or wait 10 seconds to reload last known
configuration" type messages. Improved versions of version portable
code welcomed.
<br>
<br>
It uses the uart library. Is there a more generic stream or file
function call I could use? I chose this approach rather than write a
custom function to hopefully support future and past nutos releases.
<br>
<br>
Hopefully this will save someone some effort.
<br>
<br>
Cheers
<br>
Brett
<br>
<br>
// Globals
<br>
FILE *uart;
<br>
u_long UartStatus;
<br>
u_long *UartStatus_ptr;
<br>
<br>
// Sample Code to check for key press, Assumes uart file already open.
Does not block if no characters were received.
<br>
<br>
// Were any keys pressed?
<br>
result=UartAvrIOCtl(((NUTFILE *) (_fileno(uart)))->nf_dev,
UART_GETSTATUS, UartStatus_ptr);
<br>
if((UartStatus & UART_RXBUFFEREMPTY)==0) // One or more keys were
pressed
<br>
// Now go get it<br>
if((rlen = _read(_fileno(uart), rxbuff_ptr, RXBUFF_LEN)) > 0)
// Get the characters
<br>
if(strchr(rxbuff_ptr, '\r') || strchr(rxbuff_ptr, '\n'))
// Did the user hit <CR> or <LF> ?
<br>
UserEnterNewConfig(); // Yes? go to Configure mode
<br>
<br>
<pre class="moz-signature" cols="72">-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: <a
class="moz-txt-link-abbreviated"
href="mailto:Brett.Abbott@digital-telemetry.com">Brett.Abbott@digital-telemetry.com</a>
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860 Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------
</pre>
</body>
</html>