Add partial project documentation to the incomplete PrinterHost demo.
[pub/USBasp.git] / Demos / Host / Incomplete / PrinterHost / PrinterHost.c
index 643f919..ea179b6 100644 (file)
@@ -150,7 +150,7 @@ void USB_Printer_Host(void)
                        }\r
                        \r
                        /* Some printers use alternate settings to determine the communication protocol used - if so, send a SetInterface\r
-                        * request to switch to the interface alternate setting with the Bidirection protocol */\r
+                        * request to switch to the interface alternate setting with the Bidirectional protocol */\r
                        if (PrinterAltSetting)\r
                        {\r
                                USB_ControlRequest = (USB_Request_Header_t)\r
@@ -181,8 +181,8 @@ void USB_Printer_Host(void)
                case HOST_STATE_Configured:\r
                        puts_P(PSTR("Retrieving Device ID...\r\n"));\r
                \r
-                       Device_ID_String_t DeviceIDString;\r
-                       if ((ErrorCode = Printer_GetDeviceID(&DeviceIDString)) != HOST_SENDCONTROL_Successful)\r
+                       char DeviceIDString[128];\r
+                       if ((ErrorCode = Printer_GetDeviceID(DeviceIDString, sizeof(DeviceIDString))) != HOST_SENDCONTROL_Successful)\r
                        {\r
                                puts_P(PSTR("Control Error (Get DeviceID).\r\n"));\r
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
@@ -195,7 +195,7 @@ void USB_Printer_Host(void)
                                break;\r
                        }\r
 \r
-                       printf_P(PSTR("Printer Device ID: %s\r\n"), DeviceIDString.String);\r
+                       printf_P(PSTR("Printer Device ID: %s\r\n"), DeviceIDString);\r
 \r
                        puts_P(PSTR("Printer Enumerated.\r\n"));\r
                                        \r
@@ -205,30 +205,25 @@ void USB_Printer_Host(void)
                        /* Indicate device busy via the status LEDs */\r
                        LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
                \r
-            //--------------------------------------------------------------\r
-                       #define TEST_TEXT_PAGE "\033%-12345X\033E LUFA PCL Test Page \033E\033%-12345X"\r
-//                     #define TEST_TEXT_PAGE "\033@\033i\001\033X\001\060\000\r\nLUFA ESCP/2 Test Page\r\n"\r
-                       #define PAGE_SIZE      (sizeof(TEST_TEXT_PAGE) - 1)\r
+                       char PCL_Test_Page[]   = "\033%-12345X\033E LUFA PCL Test Page \033E\033%-12345X";\r
+//                     char ESCP2_Test_Page[] =  "\033@\033i\001\033X\001\060\000\r\nLUFA ESCP/2 Test Page\r\n";\r
 \r
-                       Pipe_SelectPipe(PRINTER_DATA_OUT_PIPE);\r
-            Pipe_Unfreeze();\r
-                       \r
-                       puts_P(PSTR("Waiting for Printer to Become Ready...\r\n"));\r
-                       \r
-                       while (!(Pipe_IsReadWriteAllowed()));\r
+                       printf_P(PSTR("Sending Test Page (%d bytes)...\r\n"), strlen(PCL_Test_Page));\r
 \r
-                       printf_P(PSTR("Printer Write Allowed, Sending Page (%d bytes)...\r\n"), PAGE_SIZE);\r
-                               \r
-                       Pipe_Write_Stream_LE(TEST_TEXT_PAGE, PAGE_SIZE);\r
-            Pipe_ClearOUT();\r
+                       if ((ErrorCode = Printer_SendData(PCL_Test_Page)) != PIPE_RWSTREAM_NoError)\r
+                       {\r
+                               puts_P(PSTR("Error Sending Test Page.\r\n"));\r
+                               printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
 \r
-                       puts_P(PSTR("Page Sent, Waiting for Pipe...\r\n"));\r
+                               /* Indicate error via status LEDs */\r
+                               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
 \r
-                       while (!(Pipe_IsReadWriteAllowed()));\r
-            Pipe_Freeze();                             \r
+                               /* Wait until USB device disconnected */\r
+                               USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
+                               break;\r
+                       }\r
 \r
-                       puts_P(PSTR("Pipe Frozen.\r\n"));\r
-            //--------------------------------------------------------------\r
+                       puts_P(PSTR("Test Page Sent, Waiting for Pipe...\r\n"));\r
                \r
                        /* Indicate device no longer busy */\r
                        LEDs_SetAllLEDs(LEDMASK_USB_READY);\r