Commit for the 090810 release.
[pub/USBasp.git] / Demos / Host / LowLevel / PrinterHost / Lib / PrinterCommands.c
index 4e2a0d9..cb051cd 100644 (file)
   this software.\r
 */\r
 \r
+/** \file\r
+ *\r
+ *  Printer Device commands, to send/recieve data to and from an attached USB\r
+ *  printer, and to send and receive Printer Class control requests.\r
+ */\r
+\r
 #include "PrinterCommands.h"\r
 \r
 /** Sends the given data directly to the printer via the data endpoints, for the sending of print commands in printer\r
@@ -48,7 +54,11 @@ uint8_t Printer_SendData(Printer_Data_t* PrinterCommands)
          return ErrorCode;\r
 \r
        Pipe_ClearOUT();\r
-       while (!(Pipe_IsOUTReady()));\r
+       while (!(Pipe_IsOUTReady()))\r
+       {\r
+               if (USB_HostState == HOST_STATE_Unattached)\r
+                 return PIPE_RWSTREAM_DeviceDisconnected;\r
+       }\r
        \r
        Pipe_Freeze();\r
 \r
@@ -76,6 +86,8 @@ uint8_t Printer_GetDeviceID(char* DeviceIDString, uint16_t BufferSize)
                        wIndex:        0,\r
                        wLength:       sizeof(DeviceIDStringLength),\r
                };\r
+               \r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
 \r
        if ((ErrorCode = USB_Host_SendControlRequest(&DeviceIDStringLength)) != HOST_SENDCONTROL_Successful)\r
          return ErrorCode;\r
@@ -116,6 +128,8 @@ uint8_t Printer_GetPortStatus(uint8_t* PortStatus)
                        wLength:       sizeof(uint8_t),\r
                };\r
 \r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
        return USB_Host_SendControlRequest(PortStatus);\r
 }\r
 \r
@@ -135,6 +149,8 @@ uint8_t Printer_SoftReset(void)
                        wLength:       0,\r
                };\r
 \r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
        return USB_Host_SendControlRequest(NULL);\r
 }\r
 \r