X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/8a28fd8e6ccdb6a33727f7df089802b4d34dbea7..d11ed10c5314c44dc01c06954d1d73d4894cbff8:/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c diff --git a/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c b/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c index 6ed7fa908..9308e122d 100644 --- a/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c +++ b/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c @@ -1,21 +1,21 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -30,7 +30,7 @@ /** \file * - * Printer Device commands, to send/recieve data to and from an attached USB + * Printer Device commands, to send/receive data to and from an attached USB * printer, and to send and receive Printer Class control requests. */ @@ -39,22 +39,27 @@ /** Sends the given data directly to the printer via the data endpoints, for the sending of print commands in printer * languages accepted by the attached printer (e.g. PCL). * - * \param[in] PrinterCommands Pointer to a structure containing the commands and length of the data to send + * \param[in] PrinterCommands Pointer to the data to send to the attached printer + * \param[in] CommandSize Size of the data to send to the attached printer * * \return A value from the Pipe_Stream_RW_ErrorCodes_t enum */ -uint8_t Printer_SendData(Printer_Data_t* PrinterCommands) +uint8_t Printer_SendData(void* PrinterCommands, uint16_t CommandSize) { uint8_t ErrorCode; Pipe_SelectPipe(PRINTER_DATA_OUT_PIPE); Pipe_Unfreeze(); - if ((ErrorCode = Pipe_Write_Stream_LE(PrinterCommands->Data, PrinterCommands->Length)) != PIPE_RWSTREAM_NoError) + if ((ErrorCode = Pipe_Write_Stream_LE(PrinterCommands, CommandSize)) != PIPE_RWSTREAM_NoError) return ErrorCode; Pipe_ClearOUT(); - while (!(Pipe_IsOUTReady())); + while (!(Pipe_IsOUTReady())) + { + if (USB_HostState == HOST_STATE_Unattached) + return PIPE_RWSTREAM_DeviceDisconnected; + } Pipe_Freeze(); @@ -72,19 +77,27 @@ uint8_t Printer_SendData(Printer_Data_t* PrinterCommands) uint8_t Printer_GetDeviceID(char* DeviceIDString, uint16_t BufferSize) { uint8_t ErrorCode = HOST_SENDCONTROL_Successful; - uint16_t DeviceIDStringLength; + uint16_t DeviceIDStringLength = 0; USB_ControlRequest = (USB_Request_Header_t) { - bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), - bRequest: GET_DEVICE_ID, - wValue: 0, - wIndex: 0, - wLength: sizeof(DeviceIDStringLength), + .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), + .bRequest = REQ_GetDeviceID, + .wValue = 0, + .wIndex = 0, + .wLength = sizeof(DeviceIDStringLength), }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); if ((ErrorCode = USB_Host_SendControlRequest(&DeviceIDStringLength)) != HOST_SENDCONTROL_Successful) return ErrorCode; + + if (!(DeviceIDStringLength)) + { + DeviceIDString[0] = 0x00; + return HOST_SENDCONTROL_Successful; + } DeviceIDStringLength = SwapEndian_16(DeviceIDStringLength); @@ -116,12 +129,14 @@ uint8_t Printer_GetPortStatus(uint8_t* PortStatus) USB_ControlRequest = (USB_Request_Header_t) { bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), - bRequest: GET_PORT_STATUS, + bRequest: REQ_GetPortStatus, wValue: 0, wIndex: 0, wLength: sizeof(uint8_t), }; + Pipe_SelectPipe(PIPE_CONTROLPIPE); + return USB_Host_SendControlRequest(PortStatus); } @@ -134,13 +149,15 @@ uint8_t Printer_SoftReset(void) { USB_ControlRequest = (USB_Request_Header_t) { - bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - bRequest: SOFT_RESET, - wValue: 0, - wIndex: 0, - wLength: 0, + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), + .bRequest = REQ_SoftReset, + .wValue = 0, + .wIndex = 0, + .wLength = 0, }; + Pipe_SelectPipe(PIPE_CONTROLPIPE); + return USB_Host_SendControlRequest(NULL); }