From 00dd4affea1ec9a583b5cb86e74aee689558915b Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 4 Dec 2022 19:52:34 +0800 Subject: [PATCH] examples/hidkbd: Reuse lib_meminstream_s and remove hidbkd_instream_s Signed-off-by: Xiang Xiao --- examples/hidkbd/hidkbd_main.c | 46 ++--------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/examples/hidkbd/hidkbd_main.c b/examples/hidkbd/hidkbd_main.c index e0f2a52ee..d2b53ee9d 100644 --- a/examples/hidkbd/hidkbd_main.c +++ b/examples/hidkbd/hidkbd_main.c @@ -57,49 +57,10 @@ # undef CONFIG_EXAMPLES_HIDKBD_ENCODED #endif -/**************************************************************************** - * Private Types - ****************************************************************************/ - -#ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED -struct hidbkd_instream_s -{ - struct lib_instream_s stream; - FAR char *buffer; - ssize_t nbytes; -}; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: hidkbd_getstream - * - * Description: - * Get one character from the keyboard. - * - ****************************************************************************/ - -#ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED -static int hidkbd_getstream(FAR struct lib_instream_s *this) -{ - FAR struct hidbkd_instream_s *kbdstream = \ - (FAR struct hidbkd_instream_s *)this; - - DEBUGASSERT(kbdstream && kbdstream->buffer); - if (kbdstream->nbytes > 0) - { - kbdstream->nbytes--; - kbdstream->stream.nget++; - return (int)*kbdstream->buffer++; - } - - return EOF; -} -#endif - /**************************************************************************** * Name: hidkbd_decode * @@ -111,7 +72,7 @@ static int hidkbd_getstream(FAR struct lib_instream_s *this) #ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED static void hidkbd_decode(FAR char *buffer, ssize_t nbytes) { - struct hidbkd_instream_s kbdstream; + struct lib_meminstream_s kbdstream; struct kbd_getstate_s state; uint8_t ch; int ret; @@ -119,10 +80,7 @@ static void hidkbd_decode(FAR char *buffer, ssize_t nbytes) /* Initialize */ memset(&state, 0, sizeof(struct kbd_getstate_s)); - kbdstream.stream.getc = hidkbd_getstream; - kbdstream.stream.nget = 0; - kbdstream.buffer = buffer; - kbdstream.nbytes = nbytes; + lib_meminstream(&kbdstream, buffer, nbytes); /* Loop until all of the bytes have been consumed. We implicitly assume * that the escaped sequences do not cross buffer boundaries. That