9
0
Fork 0

Complete HID keyboard test

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3259 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2011-01-18 23:28:02 +00:00
parent 49993776c1
commit 95f41810e3
2 changed files with 62 additions and 15 deletions

View File

@ -1698,7 +1698,7 @@ static ssize_t usbhost_read(FAR struct file *filep, FAR char *buffer, size_t len
{
FAR struct inode *inode;
FAR struct usbhost_state_s *priv;
size_t remaining;
size_t nbytes;
unsigned int tail;
int ret;
@ -1729,22 +1729,22 @@ static ssize_t usbhost_read(FAR struct file *filep, FAR char *buffer, size_t len
{
/* Read data from our internal buffer of received characters */
for (tail = priv->tailndx;
tail != priv->headndx && remaining > 0;
tail++, remaining--)
for (tail = priv->tailndx, nbytes = 0;
tail != priv->headndx && nbytes < len;
nbytes++)
{
/* Handle wrap-around of the tail index */
if (tail >= CONFIG_USBHID_BUFSIZE)
{
tail = 0;
}
/* Copy the next keyboard character into the user buffer */
*buffer += priv->buffer[tail];
remaining--;
/* Handle wrap-around of the tail index */
if (++tail >= CONFIG_USBHID_BUFSIZE)
{
tail = 0;
}
}
ret = nbytes;
/* Update the tail index (pehaps marking the buffer empty) */
@ -1752,7 +1752,7 @@ static ssize_t usbhost_read(FAR struct file *filep, FAR char *buffer, size_t len
}
usbhost_givesem(&priv->exclsem);
return 0; /* Return EOF for now */
return (ssize_t)ret;
}
/****************************************************************************

View File

@ -39,8 +39,12 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sched.h>
#include <nuttx/usb/usbhost.h>
@ -69,10 +73,15 @@
#ifndef CONFIG_EXAMPLES_HIDKBD_DEFPRIO
# define CONFIG_EXAMPLES_HIDKBD_DEFPRIO 50
#endif
#ifndef CONFIG_EXAMPLES_HIDKBD_STACKSIZE
# define CONFIG_EXAMPLES_HIDKBD_STACKSIZE 1024
#endif
#ifndef CONFIG_EXAMPLES_HIDKBD_DEVNAME
# define CONFIG_EXAMPLES_HIDKBD_DEVNAME "/dev/kbda"
#endif
/****************************************************************************
* Private Types
****************************************************************************/
@ -144,7 +153,10 @@ void user_initialize(void)
int user_start(int argc, char *argv[])
{
char buffer[256];
pid_t pid;
ssize_t nbytes;
int fd;
int ret;
/* First, register all of the USB host HID keyboard class driver */
@ -181,9 +193,44 @@ int user_start(int argc, char *argv[])
for (;;)
{
/* Open the keyboard device. Loop until the device is successfully
* opened.
*/
do
{
printf("Opening device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
fflush(stdout);
fd = open(CONFIG_EXAMPLES_HIDKBD_DEVNAME, O_RDONLY);
if (fd < 0)
{
sleep(3);
}
}
while (fd < 0);
printf("Device %s opened\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
fflush(stdout);
sleep(5);
printf("user_start: Still running...\n");
/* Loop until there is a read failure */
do
{
/* Read a buffer of data */
nbytes = read(fd, buffer, 256);
if (nbytes > 0)
{
/* On success, echo the buffer to stdout */
(void)write(1, buffer, nbytes);
}
}
while (nbytes >= 0);
printf("Closing device %s\n", CONFIG_EXAMPLES_HIDKBD_DEVNAME);
fflush(stdout);
close(fd);
}
}
return 0;