⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbtest.c

📁 Curtiss-Wright Controls Embedded Computing公司的cw183板bsp源代码
💻 C
字号:
/* mouseTest.c - a wrapper file for the Dy 4 USB demo code  *//* Copyright (c) 2002 Dy 4 Systems, Inc. *//*Modification History--------------------01a, 16moct02, tis  create *//*DESCRIPTIONThis libray contains the following routines:testMouse - It Opens "/usbMo/0" device and reads it, then prints the mouse coordinates and the butons status.testKeyboard -It Opens "/usbKb/0" device and reads it, and prints the stroked keys.*//* includes */#include "vxWorks.h"#include "string.h"#include "stdio.h"#include "ioLib.h"#include "sioLib.h"#include "taskLib.h"#include "config.h"#define CTRL_Z              26  /* ASCI code for ^Z */LOCAL BOOL enterPressed;/*************************************************************************** enterThread - waits for user to press [enter]** RETURNS:  N/A*/LOCAL void enterThread ( void )    {    char bfr [256];    printf ("\nPress [enter] to terminate the Mouse test.\n");    gets (bfr);    enterPressed = TRUE;    }    /*************************************************************************** testMouse - prints the mouses presses to the terminal** RETURNS: OK or ERROR*/UINT16 testMouse ( void )    {    int     taskId;    int     fd = 0;    char    buf[4];    int     count = 0;     bzero(buf,4);    if ((fd = open ("/usbMo/0", 2,0)) == ERROR)    return (ERROR);    ioctl(fd,F_SETFL,!_FNONBLOCK);    /* Create thread to watch for Enter keypress */    enterPressed = FALSE;     if((taskId = taskSpawn ("tEnter",                       50,        /* priority */ /*tissa lowered the priority*/                 0,     /* task options */                  0x4000,    /* 16k stack space */                    (FUNCPTR) enterThread,                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )) ==ERROR)    {    printf(" TaskSpawn Error...!\n");    return ERROR;       }    while (!enterPressed)    {              if (read (fd, buf,3)== OK);      {      printf("\rx:%x  y:%x  button:%x  count:%d  ",             buf[2], buf[1],             buf[0],count);    count++;      }    taskDelay (5);     }    taskDelete (taskId);    close(fd);    return OK;    }     /*************************************************************************** testKeyboard - prints key presses to the terminal** RETURNS: OK or ERROR*/UINT16 testKeyboard ( void )    {    int     taskId;    char    inChar;    int     fd = 0;    int count = 0;    /* Poll for input or until user presses CTRL-Z on USB keyboard or     * [enter] on main keyboard. */    if ((fd = open ("/usbKb/0", 2,0)) == ERROR)    return (ERROR);    /* Create thread to watch for keypress */    enterPressed = FALSE;     if((taskId = taskSpawn ("tEnter",                       50,        /* priority */ /*tissa lowered the priority*/                 0,     /* task options */                  0x4000,    /* 16k stack space */                    (FUNCPTR) enterThread,                  0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )) ==ERROR)    {    printf(" TaskSpawn Error...!\n");    return ERROR;       }    printf ("Press CTRL-Z to terminate polling.\n");    while (!enterPressed)    {        if (read (fd, &inChar, 1) == OK)        {        printf ("ASCII %3d count:%d", inChar,count);        count++;        if (inChar >= 32)            printf (" '%c'", inChar);        printf ("\n");        if (inChar == CTRL_Z)            {            printf ("Stopped by CTRL-Z\n");            break;            }        }    taskDelay (5);     }    taskDelete (taskId);    close(fd);         return OK;    }    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -