📄 usrusbtool.c
字号:
!= OK)
{
fprintf (fout, "usbdTransferAbort() returned %d\n", s);
break;
}
/* wait for the callback to be invoked */
while (!irpCallbackInvoked)
OSS_THREAD_SLEEP (1);
}
}
OSS_THREAD_DESTROY (thread);
pipe_done:
if ((s = usbdPipeDestroy (usbdClientHandle, handle)) != OK)
{
fprintf (fout, "usbdPipeDestroy() returned %d\n", s);
return RET_CONTINUE;
}
return RET_CONTINUE;
}
#ifdef INCLUDE_USB_KEYBOARD
/*************************************************************************
*
* cmdKbdInit - initializes USB keyboard SIO driver
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdKbdInit
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
if (usbKeyboardDevInit () == OK)
fprintf (fout, "usbKeyboardDevInit() returned OK\n");
else
fprintf (fout, "usbKeyboardDevInit() returned ERROR\n");
return RET_CONTINUE;
}
/*************************************************************************
*
* cmdKbdDown - shuts down USB keyboard SIO driver
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdKbdDown
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
if (usbKeyboardDevShutdown () == OK)
fprintf (fout, "usbKeyboardDevShutdown() returned OK\n");
else
fprintf (fout, "usbKeyboardDevShutdown() returned ERROR\n");
return RET_CONTINUE;
}
/*************************************************************************
*
* kbdAttachCallback - receives callbacks from USB keyboard SIO driver
*
* RETURNS: N/A
*/
LOCAL SIO_CHAN *pKbdSioChan;
LOCAL VOID kbdAttachCallback
(
pVOID arg, /* caller-defined argument */
SIO_CHAN *pChan, /* pointer to affected SIO_CHAN */
UINT16 attachCode /* defined as USB_KBD_xxxx */
)
{
FILE *fout = (FILE *) arg;
fprintf (fout, "pChan = %p, attach code = %s\n", pChan,
(attachCode == USB_KBD_ATTACH) ? "USB_KBD_ATTACH" : "USB_KBD_REMOVE");
if (attachCode == USB_KBD_ATTACH)
{
if (pKbdSioChan == NULL)
{
if (usbKeyboardSioChanLock (pChan) != OK)
fprintf (fout, "usbKeyboardSioChanLock() returned ERROR\n");
else
pKbdSioChan = pChan;
}
else
{
fprintf (fout, "Another channel already in use, ignored.\n");
}
}
else
{
if (pChan == pKbdSioChan)
{
if (usbKeyboardSioChanUnlock (pChan) != OK)
fprintf (fout, "usbKeyboardSioChanUnlock() returned ERROR\n");
pKbdSioChan = NULL;
}
}
}
/*************************************************************************
*
* cmdKbdPoll - Polls keyboard SIO driver for input
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdKbdPoll
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
THREAD_HANDLE thread;
char inChar;
/* register for callbacks */
pKbdSioChan = NULL;
if (usbKeyboardDynamicAttachRegister (kbdAttachCallback, (pVOID) fout) != OK)
{
fprintf (fout, "usbKeyboardDynamicAttachRegister() returned ERROR\n");
return RET_CONTINUE;
}
/* Poll for input or until user presses CTRL-Z on USB keyboard or
* [enter] on main keyboard. */
/* Create thread to watch for keypress */
enterPressed = FALSE;
if (OSS_THREAD_CREATE (enterThread, (pVOID) fout, OSS_PRIORITY_INHERIT, "tEnter",
&thread) != OK)
goto pipe_done;
fprintf (fout, "Press CTRL-Z to terminate polling.\n");
while (!enterPressed)
{
if (pKbdSioChan != NULL)
{
if ((*pKbdSioChan->pDrvFuncs->pollInput) (pKbdSioChan, &inChar) == OK)
{
fprintf (fout, "ASCII %3d", inChar);
if (inChar >= 32)
fprintf (fout, " '%c'", inChar);
fprintf (fout, "\n");
if (inChar == CTRL_Z)
{
fprintf (fout, "Stopped by CTRL-Z\n");
break;
}
}
}
OSS_THREAD_SLEEP (1);
}
OSS_THREAD_DESTROY (thread);
pipe_done:
/* unregister */
if (usbKeyboardDynamicAttachUnRegister (kbdAttachCallback, (pVOID) fout) != OK)
fprintf (fout, "usbKeyboardDynamicAttachUnRegister() returned ERROR\n");
return RET_CONTINUE;
}
/*************************************************************************
*
* cmdKbdTest - Tests USB keyboard SIO driver
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdKbdTest
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
if ( cmdKbdInit(Param,ppCmd,fin,fout) != RET_CONTINUE )
{
return RET_CONTINUE;
} /* end of if () */
if ( cmdKbdPoll(Param,ppCmd,fin,fout) != RET_CONTINUE )
{
return RET_CONTINUE;
} /* end of if () */
if ( cmdKbdDown(Param,ppCmd,fin,fout) != RET_CONTINUE )
{
return RET_CONTINUE;
} /* end of if () */
return RET_CONTINUE;
}
#endif /*INCLUDE_USB_KEYBOARD*/
#ifdef INCLUDE_USB_MOUSE
/*************************************************************************
*
* showMouseState
*
* RETURNS: N/A
*/
LOCAL long mouseX;
LOCAL long mouseY;
LOCAL BOOL mouseButtons_1_2;
LOCAL VOID showMouseState
(
FILE *fout,
UINT8 buttons
)
{
fprintf (fout, "\rx:%5ld y:%5ld B1:%3.3s B2:%3.3s B3:%3.3s",
mouseX, mouseY,
(buttons & MOUSE_BUTTON_1) == 0 ? "UP " : "DWN",
(buttons & MOUSE_BUTTON_2) == 0 ? "UP " : "DWN",
(buttons & MOUSE_BUTTON_3) == 0 ? "UP " : "DWN");
}
/*************************************************************************
*
* signExtend - extends sign from char to long
*
* RETURNS: sign-extended long value
*/
LOCAL long signExtend
(
char value
)
{
if ((value & 0x80) != 0)
return value | 0xffffff00;
return value;
}
/*************************************************************************
*
* mseRptCallback - invoked when reports received from mouse
*
* RETURNS: OK
*/
LOCAL STATUS mseRptCallback
(
void *arg,
pHID_MSE_BOOT_REPORT pReport
)
{
FILE *fout = (FILE *) arg;
long xChange = signExtend (pReport->xDisplacement);
long yChange = signExtend (pReport->yDisplacement);
mouseX += xChange;
mouseY += yChange;
showMouseState (fout, pReport->buttonState);
if ( (pReport->buttonState & MOUSE_BUTTON_1) &&
(pReport->buttonState & MOUSE_BUTTON_2) )
{
mouseButtons_1_2 = TRUE;
} /* end of if () */
return OK;
}
/*************************************************************************
*
* mseAttachCallback - receives callbacks from USB mouse SIO driver
*
* RETURNS: N/A
*/
LOCAL SIO_CHAN *pMseSioChan;
LOCAL VOID mseAttachCallback
(
pVOID arg, /* caller-defined argument */
SIO_CHAN *pChan, /* pointer to affected SIO_CHAN */
UINT16 attachCode /* defined as USB_KBD_xxxx */
)
{
FILE *fout = (FILE *) arg;
fprintf (fout, "pChan = %p, attach code = %s\n", pChan,
(attachCode == USB_MSE_ATTACH) ? "USB_MSE_ATTACH" : "USB_MSE_REMOVE");
if (attachCode == USB_MSE_ATTACH)
{
if (pMseSioChan == NULL)
{
if (usbMouseSioChanLock (pChan) != OK)
fprintf (fout, "usbMouseSioChanLock() returned ERROR\n");
else
{
pMseSioChan = pChan;
/* Register for report callbacks */
if (pMseSioChan != NULL)
{
if ((*pMseSioChan->pDrvFuncs->callbackInstall) (pMseSioChan,
SIO_CALLBACK_PUT_MOUSE_REPORT, mseRptCallback, fout) != OK)
{
fprintf (fout, "callbackInstall() returned ERROR.\n");
}
}
}
}
else
{
fprintf (fout, "Another channel already in use, ignored.\n");
}
}
else
{
if (pChan == pMseSioChan)
{
if (usbMouseSioChanUnlock (pChan) != OK)
fprintf (fout, "usbMouseSioChanUnlock() returned ERROR\n");
pMseSioChan = NULL;
}
}
}
/*************************************************************************
*
* cmdMouseTest - Tests mouse SIO driver for input
*
* RETURNS: RET_CONTINUE
*/
LOCAL UINT16 cmdMouseTest
(
pVOID Param, /* Generic parameter passed down */
char **ppCmd, /* Ptr to remainder of cmd line */
FILE *fin, /* stream for input (if any) */
FILE *fout /* stream for output (if any) */
)
{
THREAD_HANDLE thread;
/* Initialize usbMouseLib. */
if (usbMouseDevInit () != OK)
{
fprintf (fout, "usbMouseDevInit() returned ERROR\n");
return RET_CONTINUE;
}
/* register for attach callbacks */
pMseSioChan = NULL;
mouseX = 0;
mouseY = 0;
if (usbMouseDynamicAttachRegister (mseAttachCallback, (pVOID) fout) != OK)
{
fprintf (fout, "usbMouseDynamicAttachRegister() returned ERROR\n");
goto mouseDown;
}
/* Wait for use to press [enter] to terminate test. */
/* Create thread to watch for keypress */
enterPressed = FALSE;
mouseButtons_1_2 = FALSE;
fprintf (fout, "Press mouse buttons 1 & 2 at the same time to terminate polling.\n");
if (OSS_THREAD_CREATE (enterThread, (pVOID) fout, OSS_PRIORITY_INHERIT, "tEnter",
&thread) != OK)
{
fprintf (fout, "Failed to create tEnter thread.\n");
goto mouseUnreg;
}
/* Wait for mouse to be attached */
while (pMseSioChan == NULL)
{
if (enterPressed)
goto threadDone;
OSS_THREAD_SLEEP (1);
}
/* Let background threads show mouse state */
showMouseState (fout, 0);
while (!enterPressed && !mouseButtons_1_2)
OSS_THREAD_SLEEP (1);
fprintf (fout, "\n");
threadDone:
OSS_THREAD_DESTROY (thread);
mouseUnreg:
/* unregister for attach callbacks */
if (usbMouseDynamicAttachUnRegister (mseAttachCallback, (pVOID) fout) != OK)
fprintf (fout, "usbMouseDynamicAttachUnRegister() returned ERROR\n");
/* Terminate report callbacks */
if (pMseSioChan != NULL)
if ((*pMseSioChan->pDrvFuncs->callbackInstall) (pMseSioChan,
SIO_CALLBACK_PUT_MOUSE_REPORT, NULL, NULL) != OK)
{
fprintf (fout, "callbackInstall() returned ERROR.\n");
}
mouseDown:
if (usbMouseDevShutdown () != OK)
fprintf (fout, "usbMouseDevShutdown() returned ERROR\n");
return RET_CONTINUE;
}
#endif /*INCLUDE_USB_MOUSE*/
#ifdef INCLUDE_USB_PRINTER
/*************************************************************************
*
* closeTxFile - closes any open print tx file
*
* RETURNS: N/A
*/
LOCAL VOID closeTxFile (void)
{
txCharCount = 0;
if (txFile != NULL)
{
fclose (txFile);
txFile = NULL;
}
}
/*************************************************************************
*
* prnTxCallback - feeds characters to USB printer SIO driver
*
* RETURNS: OK
*/
LOCAL STATUS prnTxCallback
(
void *callbackParam,
char *txChar
)
{
/* If no more chars to send, return an error */
if (txCharCount == 0)
return ERROR;
txCharCount--;
/* Check if running a pattern test or a file dump */
if (patternTest)
{
/* Running a pattern test. Return the next pattern char */
if ((nextCharVal & 1) == 0)
*txChar = nextCharVal >> 8;
else
*txChar = nextCharVal & 0xff;
nextCharVal++;
}
else
{
/* Running a file dump test. Return the next char from file */
if (txBfrCount == 0 && txCharCount > 0)
{
/* Read next buffer from file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -