summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-23 23:11:13 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-01-23 23:11:13 +0000
commit32464a54e18c12622724ed1a5d93f31d31eff409 (patch)
tree9300f5860d154f7e0f8b86336a317a4fca7e5af4 /apps
parent7080c71f2b2007926d5d7728f2ff443968ebe1fc (diff)
downloadpx4-nuttx-32464a54e18c12622724ed1a5d93f31d31eff409.tar.gz
px4-nuttx-32464a54e18c12622724ed1a5d93f31d31eff409.tar.bz2
px4-nuttx-32464a54e18c12622724ed1a5d93f31d31eff409.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/examples/keypadtest/Kconfig8
-rw-r--r--apps/examples/keypadtest/keypadtest_main.c115
2 files changed, 122 insertions, 1 deletions
diff --git a/apps/examples/keypadtest/Kconfig b/apps/examples/keypadtest/Kconfig
index 9dee80633..98c6d348e 100644
--- a/apps/examples/keypadtest/Kconfig
+++ b/apps/examples/keypadtest/Kconfig
@@ -18,4 +18,12 @@ if EXAMPLES_KEYPADTEST
The name of the keypad device that will be opened in order to perform
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
diff --git a/apps/examples/keypadtest/keypadtest_main.c b/apps/examples/keypadtest/keypadtest_main.c
index afdc3e08a..dd7369c3e 100644
--- a/apps/examples/keypadtest/keypadtest_main.c
+++ b/apps/examples/keypadtest/keypadtest_main.c
@@ -50,6 +50,11 @@
#include <nuttx/input/keypad.h>
+#ifdef CONFIG_EXAMPLES_KEYPADTEST_ENCODED
+# include <nuttx/streams.h>
+# include <nuttx/input/kbd_codec.h>
+#endif
+
/****************************************************************************
* Definitions
****************************************************************************/
@@ -67,6 +72,15 @@
* 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
****************************************************************************/
@@ -76,6 +90,102 @@
****************************************************************************/
/****************************************************************************
+ * 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
****************************************************************************/
@@ -125,8 +235,11 @@ int keypadtest_main(int argc, char *argv[])
if (nbytes > 0)
{
/* On success, echo the buffer to stdout */
-
+#ifdef CONFIG_EXAMPLES_KEYPADTEST_ENCODED
+ keypad_decode(buffer, nbytes);
+#else
(void)write(1, buffer, nbytes);
+#endif
}
}
while (nbytes >= 0);