Add option to used keyboard CODEC in apps/examples/keypadtest
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5554 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
d39a78a910
commit
b2007c8e5b
@ -18,4 +18,12 @@ if EXAMPLES_KEYPADTEST
|
|||||||
The name of the keypad device that will be opened in order to perform
|
The name of the keypad device that will be opened in order to perform
|
||||||
the keypad test. Default: "/dev/keypad"
|
the keypad test. Default: "/dev/keypad"
|
||||||
|
|
||||||
|
config EXAMPLES_KEYPADTEST_ENCODED
|
||||||
|
bool "Use Keyboard CODEC"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Use the keyboard encoded/decoder to pass control information from
|
||||||
|
the keypad driver to the keypad test. This is the keyboard CODEC
|
||||||
|
defined in nuttx/input/kbd_codec.h.
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
@ -50,6 +50,11 @@
|
|||||||
|
|
||||||
#include <nuttx/input/keypad.h>
|
#include <nuttx/input/keypad.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_KEYPADTEST_ENCODED
|
||||||
|
# include <nuttx/streams.h>
|
||||||
|
# include <nuttx/input/kbd_codec.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -67,6 +72,15 @@
|
|||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_KEYPADTEST_ENCODED
|
||||||
|
struct keypad_instream_s
|
||||||
|
{
|
||||||
|
struct lib_instream_s stream;
|
||||||
|
FAR char *buffer;
|
||||||
|
ssize_t nbytes;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -75,6 +89,102 @@
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: keypad_getstream
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get one character from the keyboard.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_KEYPADTEST_ENCODED
|
||||||
|
static int keypad_getstream(FAR struct lib_instream_s *this)
|
||||||
|
{
|
||||||
|
FAR struct keypad_instream_s *kbdstream = (FAR struct keypad_instream_s *)this;
|
||||||
|
|
||||||
|
DEBUGASSERT(kbdstream && kbdstream->buffer);
|
||||||
|
if (kbdstream->nbytes > 0)
|
||||||
|
{
|
||||||
|
kbdstream->nbytes--;
|
||||||
|
kbdstream->stream.nget++;
|
||||||
|
return (int)*kbdstream->buffer++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EOF;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: keypad_decode
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Decode encoded keyboard input
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_KEYPADTEST_ENCODED
|
||||||
|
static void keypad_decode(FAR char *buffer, ssize_t nbytes)
|
||||||
|
{
|
||||||
|
struct keypad_instream_s kbdstream;
|
||||||
|
struct kbd_getstate_s state;
|
||||||
|
uint8_t ch;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Initialize */
|
||||||
|
|
||||||
|
memset(&state, 0, sizeof(struct kbd_getstate_s));
|
||||||
|
kbdstream.stream.get = keypad_getstream;
|
||||||
|
kbdstream.stream.nget = 0;
|
||||||
|
kbdstream.buffer = buffer;
|
||||||
|
kbdstream.nbytes = nbytes;
|
||||||
|
|
||||||
|
/* Loop until all of the bytes have been consumed. We implicitly assume
|
||||||
|
* that the the escaped sequences do not cross buffer boundaries. That
|
||||||
|
* might be true if the read buffer were small or the data rates high.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
/* Decode the next thing from the buffer */
|
||||||
|
|
||||||
|
ret = kbd_decode((FAR struct lib_instream_s *)&kbdstream, &state, &ch);
|
||||||
|
if (ret == KBD_ERROR)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Normal data? Or special key? */
|
||||||
|
|
||||||
|
switch (ret)
|
||||||
|
{
|
||||||
|
case KBD_PRESS: /* Key press event */
|
||||||
|
printf("Normal Press: %c [%02x]\n", isprint(ch) ? ch : '.', ch);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KBD_RELEASE: /* Key release event */
|
||||||
|
printf("Normal Release: %c [%02x]\n", isprint(ch) ? ch : '.', ch);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KBD_SPECPRESS: /* Special key press event */
|
||||||
|
printf("Special Press: %d\n", ch);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KBD_SPECREL: /* Special key release event */
|
||||||
|
printf("Special Release: %d\n", ch);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KBD_ERROR: /* Error or end-of-file */
|
||||||
|
printf("EOF: %d\n", ret);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("Unexpected: %d\n", ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -125,8 +235,11 @@ int keypadtest_main(int argc, char *argv[])
|
|||||||
if (nbytes > 0)
|
if (nbytes > 0)
|
||||||
{
|
{
|
||||||
/* On success, echo the buffer to stdout */
|
/* On success, echo the buffer to stdout */
|
||||||
|
#ifdef CONFIG_EXAMPLES_KEYPADTEST_ENCODED
|
||||||
|
keypad_decode(buffer, nbytes);
|
||||||
|
#else
|
||||||
(void)write(1, buffer, nbytes);
|
(void)write(1, buffer, nbytes);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (nbytes >= 0);
|
while (nbytes >= 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user