X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/8a28fd8e6ccdb6a33727f7df089802b4d34dbea7..064e6a2f32719da5b7ed2ff3a8a32c5788e753d0:/Demos/Host/LowLevel/PrinterHost/PrinterHost.c diff --git a/Demos/Host/LowLevel/PrinterHost/PrinterHost.c b/Demos/Host/LowLevel/PrinterHost/PrinterHost.c index 64adf22c7..9d62fdaa2 100644 --- a/Demos/Host/LowLevel/PrinterHost/PrinterHost.c +++ b/Demos/Host/LowLevel/PrinterHost/PrinterHost.c @@ -73,7 +73,7 @@ void SetupHardware(void) /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and * starts the library USB task to begin the enumeration and USB management process. */ -void EVENT_USB_DeviceAttached(void) +void EVENT_USB_Host_DeviceAttached(void) { puts_P(PSTR(ESC_FG_GREEN "Device Attached.\r\n" ESC_FG_WHITE)); LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); @@ -82,7 +82,7 @@ void EVENT_USB_DeviceAttached(void) /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and * stops the library USB task management process. */ -void EVENT_USB_DeviceUnattached(void) +void EVENT_USB_Host_DeviceUnattached(void) { puts_P(PSTR(ESC_FG_GREEN "\r\nDevice Unattached.\r\n" ESC_FG_WHITE)); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); @@ -91,18 +91,18 @@ void EVENT_USB_DeviceUnattached(void) /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully * enumerated by the host and is now ready to be used by the application. */ -void EVENT_USB_DeviceEnumerationComplete(void) +void EVENT_USB_Host_DeviceEnumerationComplete(void) { LEDs_SetAllLEDs(LEDMASK_USB_READY); } /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ -void EVENT_USB_HostError(uint8_t ErrorCode) +void EVENT_USB_Host_HostError(uint8_t ErrorCode) { USB_ShutDown(); - puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n")); - printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); + printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n" + " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); LEDs_SetAllLEDs(LEDMASK_USB_ERROR); for(;;); @@ -111,12 +111,12 @@ void EVENT_USB_HostError(uint8_t ErrorCode) /** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while * enumerating an attached USB device. */ -void EVENT_USB_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode) +void EVENT_USB_Host_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode) { - puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n")); - printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); - printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode); - printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState); + printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n" + " -- Error Code %d\r\n" + " -- Sub Error Code %d\r\n" + " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState); LEDs_SetAllLEDs(LEDMASK_USB_ERROR); } @@ -157,8 +157,8 @@ void USB_Printer_Host(void) /* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */ if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful) { - puts_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n")); - printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); + printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n" + " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); /* Indicate error via status LEDs */ LEDs_SetAllLEDs(LEDMASK_USB_ERROR); @@ -183,8 +183,8 @@ void USB_Printer_Host(void) if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) { - puts_P(PSTR(ESC_FG_RED "Control Error (Set Interface).\r\n")); - printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); + printf_P(PSTR(ESC_FG_RED "Control Error (Set Interface).\r\n" + " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); /* Indicate error via status LEDs */ LEDs_SetAllLEDs(LEDMASK_USB_ERROR); @@ -195,16 +195,13 @@ void USB_Printer_Host(void) } } - USB_HostState = HOST_STATE_Configured; - break; - case HOST_STATE_Configured: puts_P(PSTR("Retrieving Device ID...\r\n")); - char DeviceIDString[256]; + char DeviceIDString[300]; if ((ErrorCode = Printer_GetDeviceID(DeviceIDString, sizeof(DeviceIDString))) != HOST_SENDCONTROL_Successful) { - puts_P(PSTR(ESC_FG_RED "Control Error (Get DeviceID).\r\n")); - printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); + printf_P(PSTR(ESC_FG_RED "Control Error (Get Device ID).\r\n" + " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); /* Indicate error via status LEDs */ LEDs_SetAllLEDs(LEDMASK_USB_ERROR); @@ -217,26 +214,22 @@ void USB_Printer_Host(void) printf_P(PSTR("Printer Device ID: %s\r\n"), DeviceIDString); puts_P(PSTR("Printer Enumerated.\r\n")); - - USB_HostState = HOST_STATE_Ready; + + USB_HostState = HOST_STATE_Configured; break; - case HOST_STATE_Ready: + case HOST_STATE_Configured: /* Indicate device busy via the status LEDs */ LEDs_SetAllLEDs(LEDMASK_USB_BUSY); - Printer_Data_t TestPageData = - { -// "\033%-12345X\033E LUFA PCL Test Page \033E\033%-12345X", - "\033@\033i\001\033X\001\060\000\r\nLUFA ESCP/2 Test Page\r\n", - (sizeof(TestPageData.Data) - 1) - }; + char TestPageData[] = "\033%-12345X\033E" "LUFA PCL Test Page" "\033E\033%-12345X"; + uint16_t TestPageLength = strlen(TestPageData); - printf_P(PSTR("Sending Test Page (%d bytes)...\r\n"), TestPageData.Length); + printf_P(PSTR("Sending Test Page (%d bytes)...\r\n"), TestPageLength); - if ((ErrorCode = Printer_SendData(&TestPageData)) != PIPE_RWSTREAM_NoError) + if ((ErrorCode = Printer_SendData(&TestPageData, TestPageLength)) != PIPE_RWSTREAM_NoError) { - puts_P(PSTR(ESC_FG_RED "Error Sending Test Page.\r\n")); - printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); + printf_P(PSTR(ESC_FG_RED "Error Sending Test Page.\r\n" + " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); /* Indicate error via status LEDs */ LEDs_SetAllLEDs(LEDMASK_USB_ERROR);