examples/hidkbd: Reuse lib_meminstream_s and remove hidbkd_instream_s
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
2c56945fee
commit
00dd4affea
@ -57,49 +57,10 @@
|
|||||||
# undef CONFIG_EXAMPLES_HIDKBD_ENCODED
|
# undef CONFIG_EXAMPLES_HIDKBD_ENCODED
|
||||||
#endif
|
#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
|
* 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
|
* Name: hidkbd_decode
|
||||||
*
|
*
|
||||||
@ -111,7 +72,7 @@ static int hidkbd_getstream(FAR struct lib_instream_s *this)
|
|||||||
#ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED
|
#ifdef CONFIG_EXAMPLES_HIDKBD_ENCODED
|
||||||
static void hidkbd_decode(FAR char *buffer, ssize_t nbytes)
|
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;
|
struct kbd_getstate_s state;
|
||||||
uint8_t ch;
|
uint8_t ch;
|
||||||
int ret;
|
int ret;
|
||||||
@ -119,10 +80,7 @@ static void hidkbd_decode(FAR char *buffer, ssize_t nbytes)
|
|||||||
/* Initialize */
|
/* Initialize */
|
||||||
|
|
||||||
memset(&state, 0, sizeof(struct kbd_getstate_s));
|
memset(&state, 0, sizeof(struct kbd_getstate_s));
|
||||||
kbdstream.stream.getc = hidkbd_getstream;
|
lib_meminstream(&kbdstream, buffer, nbytes);
|
||||||
kbdstream.stream.nget = 0;
|
|
||||||
kbdstream.buffer = buffer;
|
|
||||||
kbdstream.nbytes = nbytes;
|
|
||||||
|
|
||||||
/* Loop until all of the bytes have been consumed. We implicitly assume
|
/* Loop until all of the bytes have been consumed. We implicitly assume
|
||||||
* that the escaped sequences do not cross buffer boundaries. That
|
* that the escaped sequences do not cross buffer boundaries. That
|
||||||
|
Loading…
x
Reference in New Issue
Block a user