X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/f9f1bcc25c17b031029200cd9648d76d4ee39dc4..24f730fce3f2022762011d795c3feada5ef874b3:/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c?ds=inline diff --git a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c index 69ba64b13..c29d4debd 100644 --- a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c +++ b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c @@ -37,7 +37,7 @@ #include "MouseHostWithParser.h" /** Main program entry point. This routine configures the hardware required by the application, then - * starts the scheduler to run the application tasks. + * enters a loop to run the application tasks in sequence. */ int main(void) { @@ -171,8 +171,12 @@ void Mouse_HID_Task(void) /* Get and process the device's first HID report descriptor */ if ((ErrorCode = GetHIDReportData()) != ParseSuccessful) { - printf_P(PSTR(ESC_FG_RED "Report Parse Error.\r\n" - " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); + puts_P(PSTR(ESC_FG_RED "Report Parse Error.\r\n")); + + if (!(HIDReportInfo.TotalReportItems)) + puts_P(PSTR("Not a valid Mouse." ESC_FG_WHITE)); + else + printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); /* Indicate error via status LEDs */ LEDs_SetAllLEDs(LEDMASK_USB_ERROR); @@ -181,6 +185,24 @@ void Mouse_HID_Task(void) USB_HostState = HOST_STATE_WaitForDeviceRemoval; break; } + + printf("Total Reports: %d\r\n", HIDReportInfo.TotalDeviceReports); + + for (uint8_t i = 0; i < HIDReportInfo.TotalDeviceReports; i++) + { + HID_ReportSizeInfo_t* CurrReportIDInfo = &HIDReportInfo.ReportIDSizes[i]; + + uint8_t ReportSizeInBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_In]; + uint8_t ReportSizeOutBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Out]; + uint8_t ReportSizeFeatureBits = CurrReportIDInfo->ReportSizeBits[REPORT_ITEM_TYPE_Feature]; + + /* Print out the byte sizes of each report within the device */ + printf_P(PSTR(" + Report ID %d - In: %d bytes, Out: %d bytes, Feature: %d bytes\r\n"), + CurrReportIDInfo->ReportID, + ((ReportSizeInBits >> 3) + ((ReportSizeInBits & 0x07) != 0)), + ((ReportSizeOutBits >> 3) + ((ReportSizeOutBits & 0x07) != 0)), + ((ReportSizeFeatureBits >> 3) + ((ReportSizeFeatureBits & 0x07) != 0))); + } puts_P(PSTR("Mouse Enumerated.\r\n")); @@ -190,7 +212,7 @@ void Mouse_HID_Task(void) /* Select and unfreeze mouse data pipe */ Pipe_SelectPipe(MOUSE_DATAPIPE); Pipe_Unfreeze(); - + /* Check to see if a packet has been received */ if (Pipe_IsINReceived()) { @@ -234,8 +256,8 @@ void ProcessMouseReport(uint8_t* MouseReport) bool FoundData; - if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) && - (ReportItem->ItemType == REPORT_ITEM_TYPE_In)) + if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) && + (ReportItem->ItemType == REPORT_ITEM_TYPE_In)) { /* Get the mouse button value */ FoundData = USB_GetHIDReportItemInfo(MouseReport, ReportItem); @@ -249,6 +271,21 @@ void ProcessMouseReport(uint8_t* MouseReport) LEDMask = LEDS_ALL_LEDS; } else if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL) && + (ReportItem->Attributes.Usage.Usage == USAGE_SCROLL_WHEEL) && + (ReportItem->ItemType == REPORT_ITEM_TYPE_In)) + { + /* Get the mouse wheel value if it is contained within the current + * report, if not, skip to the next item in the parser list + */ + if (!(USB_GetHIDReportItemInfo(MouseReport, ReportItem))) + continue; + + int16_t WheelDelta = HID_ALIGN_DATA(ReportItem, int16_t); + + if (WheelDelta) + LEDMask = (LEDS_LED1 | LEDS_LED2 | ((WheelDelta > 0) ? LEDS_LED3 : LEDS_LED4)); + } + else if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL) && ((ReportItem->Attributes.Usage.Usage == USAGE_X) || (ReportItem->Attributes.Usage.Usage == USAGE_Y)) && (ReportItem->ItemType == REPORT_ITEM_TYPE_In))