X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/cb779e3d7d32d7c43e0a45bb526de0a04135b0c7..1f1d0710f379a8b08ef646cbadb63d92c35e47fb:/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c diff --git a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c index f6946fbdd..6df052d72 100644 --- a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c +++ b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2010. + Copyright (C) Dean Camera, 2011. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -66,9 +66,12 @@ void SetupHardware(void) clock_prescale_set(clock_div_1); /* Hardware Initialization */ - SerialStream_Init(9600, false); + Serial_Init(9600, false); LEDs_Init(); USB_Init(); + + /* Create a stdio stream for the serial port for stdin and stdout */ + Serial_CreateStream(NULL); } /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and @@ -100,7 +103,7 @@ void EVENT_USB_Host_DeviceEnumerationComplete(void) /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ void EVENT_USB_Host_HostError(const uint8_t ErrorCode) { - USB_ShutDown(); + USB_Disable(); printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n" " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); @@ -149,13 +152,15 @@ void ReadNextReport(void) if (Pipe_IsReadWriteAllowed()) { /* Read in keyboard report data */ - Pipe_Read_Stream_LE(&KeyboardReport, sizeof(KeyboardReport)); + Pipe_Read_Stream_LE(&KeyboardReport, sizeof(KeyboardReport), NULL); /* Indicate if the modifier byte is non-zero (special key such as shift is being pressed) */ LEDs_ChangeLEDs(LEDS_LED1, (KeyboardReport.Modifier) ? LEDS_LED1 : 0); + uint8_t KeyCode = KeyboardReport.KeyCode[0]; + /* Check if a key has been pressed */ - if (KeyboardReport.KeyCode) + if (KeyCode) { /* Toggle status LED to indicate keypress */ LEDs_ToggleLEDs(LEDS_LED2); @@ -163,14 +168,27 @@ void ReadNextReport(void) char PressedKey = 0; /* Retrieve pressed key character if alphanumeric */ - if ((KeyboardReport.KeyCode[0] >= 0x04) && (KeyboardReport.KeyCode[0] <= 0x1D)) - PressedKey = (KeyboardReport.KeyCode[0] - 0x04) + 'A'; - else if ((KeyboardReport.KeyCode[0] >= 0x1E) && (KeyboardReport.KeyCode[0] <= 0x27)) - PressedKey = (KeyboardReport.KeyCode[0] - 0x1E) + '0'; - else if (KeyboardReport.KeyCode[0] == 0x2C) - PressedKey = ' '; - else if (KeyboardReport.KeyCode[0] == 0x28) - PressedKey = '\n'; + if ((KeyCode >= HID_KEYBOARD_SC_A) && (KeyCode <= HID_KEYBOARD_SC_Z)) + { + PressedKey = (KeyCode - HID_KEYBOARD_SC_A) + 'A'; + } + else if ((KeyCode >= HID_KEYBOARD_SC_1_AND_EXCLAMATION) & + (KeyCode < HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS)) + { + PressedKey = (KeyCode - HID_KEYBOARD_SC_1_AND_EXCLAMATION) + '1'; + } + else if (KeyCode == HID_KEYBOARD_SC_0_AND_CLOSING_PARENTHESIS) + { + PressedKey = '0'; + } + else if (KeyCode == HID_KEYBOARD_SC_SPACE) + { + PressedKey = ' '; + } + else if (KeyCode == HID_KEYBOARD_SC_ENTER) + { + PressedKey = '\n'; + } /* Print the pressed key character out through the serial port if valid */ if (PressedKey)