X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/18f7cd3325418585c1d32426456379356247226d..8ba51f090f7cafb36e1108cc58e68f5d71bc13c0:/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 4c88bb4f2..a9f41ba64 100644 --- a/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c +++ b/Demos/Host/LowLevel/PrinterHost/Lib/PrinterCommands.c @@ -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,12 +77,12 @@ 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, + bRequest: REQ_GetDeviceID, wValue: 0, wIndex: 0, wLength: sizeof(DeviceIDStringLength), @@ -87,6 +92,12 @@ uint8_t Printer_GetDeviceID(char* DeviceIDString, uint16_t BufferSize) if ((ErrorCode = USB_Host_SendControlRequest(&DeviceIDStringLength)) != HOST_SENDCONTROL_Successful) return ErrorCode; + + if (!(DeviceIDStringLength)) + { + DeviceIDString[0] = 0x00; + return HOST_SENDCONTROL_Successful; + } DeviceIDStringLength = SwapEndian_16(DeviceIDStringLength); @@ -118,7 +129,7 @@ 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), @@ -139,7 +150,7 @@ uint8_t Printer_SoftReset(void) USB_ControlRequest = (USB_Request_Header_t) { bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - bRequest: SOFT_RESET, + bRequest: REQ_SoftReset, wValue: 0, wIndex: 0, wLength: 0,