Fix PrinterHost demo so that it will only enumerate printers with Bidirectional proto...
[pub/USBasp.git] / Demos / Host / Incomplete / PrinterHost / PrinterHost.c
index 80fca25..643f919 100644 (file)
@@ -36,8 +36,6 @@
 \r
 #include "PrinterHost.h"\r
 \r
-uint8_t PrinterProtocol;\r
-\r
 \r
 int main(void)\r
 {\r
@@ -150,12 +148,37 @@ void USB_Printer_Host(void)
                                USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
                                break;\r
                        }\r
-\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
+                       if (PrinterAltSetting)\r
+                       {\r
+                               USB_ControlRequest = (USB_Request_Header_t)\r
+                                       {\r
+                                               bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE),\r
+                                               bRequest:      REQ_SetInterface,\r
+                                               wValue:        PrinterAltSetting,\r
+                                               wIndex:        PrinterInterfaceNumber,\r
+                                               wLength:       0,\r
+                                       };\r
+                                       \r
+                               if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
+                               {\r
+                                       puts_P(PSTR("Control Error (Set Interface).\r\n"));\r
+                                       printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
+\r
+                                       /* Indicate error via status LEDs */\r
+                                       LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+\r
+                                       /* Wait until USB device disconnected */\r
+                                       USB_HostState = HOST_STATE_WaitForDeviceRemoval;\r
+                                       break;                                  \r
+                               }\r
+                       }\r
+                       \r
                        USB_HostState = HOST_STATE_Configured;\r
                        break;\r
                case HOST_STATE_Configured:\r
-                       printf_P(PSTR("Printer Protocol: %d\r\n"), PrinterProtocol);\r
-               \r
                        puts_P(PSTR("Retrieving Device ID...\r\n"));\r
                \r
                        Device_ID_String_t DeviceIDString;\r