\r
#include "MouseHostWithParser.h"\r
\r
-/* Project Tags, for reading out using the ButtLoad project */\r
-BUTTLOADTAG(ProjName, "LUFA Mouse Host App");\r
-BUTTLOADTAG(BuildTime, __TIME__);\r
-BUTTLOADTAG(BuildDate, __DATE__);\r
-BUTTLOADTAG(LUFAVersion, "LUFA V" LUFA_VERSION_STRING);\r
-\r
/* Scheduler Task List */\r
TASK_LIST\r
{\r
Pipe_SelectPipe(MOUSE_DATAPIPE); \r
Pipe_Unfreeze();\r
\r
- /* Check if data has been received from the attached mouse */\r
- if (Pipe_ReadWriteAllowed())\r
+ /* Check to see if a packet has been received */\r
+ if (Pipe_IsINReceived())\r
{\r
- uint8_t LEDMask = LEDS_NO_LEDS;\r
-\r
- /* Create buffer big enough for the report */\r
- uint8_t MouseReport[Pipe_BytesInPipe()];\r
+ /* Check if data has been received from the attached mouse */\r
+ if (Pipe_IsReadWriteAllowed())\r
+ {\r
+ /* Create buffer big enough for the report */\r
+ uint8_t MouseReport[Pipe_BytesInPipe()];\r
\r
- /* Load in the mouse report */\r
- Pipe_Read_Stream_LE(MouseReport, Pipe_BytesInPipe());\r
+ /* Load in the mouse report */\r
+ Pipe_Read_Stream_LE(MouseReport, Pipe_BytesInPipe());\r
\r
- /* Clear the IN endpoint, ready for next data packet */\r
- Pipe_ClearCurrentBank();\r
-\r
- /* Check each HID report item in turn, looking for mouse X/Y/button reports */\r
- for (uint8_t ReportNumber = 0; ReportNumber < HIDReportInfo.TotalReportItems; ReportNumber++)\r
- {\r
- /* Create a temporary item pointer to the next report item */\r
- HID_ReportItem_t* ReportItem = &HIDReportInfo.ReportItems[ReportNumber];\r
- \r
- bool FoundData;\r
-\r
- if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) &&\r
- (ReportItem->ItemType == REPORT_ITEM_TYPE_In))\r
- {\r
- /* Get the mouse button value */\r
- FoundData = GetReportItemInfo(MouseReport, ReportItem);\r
- \r
- /* For multi-report devices - if the requested data was not in the issued report, continue */\r
- if (!(FoundData))\r
- continue;\r
-\r
- /* If button is pressed, all LEDs are turned on */\r
- if (ReportItem->Value)\r
- LEDMask = LEDS_ALL_LEDS;\r
- }\r
- else if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&\r
- ((ReportItem->Attributes.Usage.Usage == USAGE_X) ||\r
- (ReportItem->Attributes.Usage.Usage == USAGE_Y)) &&\r
- (ReportItem->ItemType == REPORT_ITEM_TYPE_In))\r
- {\r
- /* Get the mouse relative position value */\r
- FoundData = GetReportItemInfo(MouseReport, ReportItem);\r
- \r
- /* For multi-report devices - if the requested data was not in the issued report, continue */\r
- if (!(FoundData))\r
- continue;\r
- \r
- int16_t DeltaMovement;\r
- \r
- if (ReportItem->Attributes.BitSize > 8)\r
- DeltaMovement = (int16_t)ReportItem->Value;\r
- else\r
- DeltaMovement = (int8_t)ReportItem->Value;\r
- \r
- /* Determine if the report is for the X or Y delta movement */\r
- if (ReportItem->Attributes.Usage.Usage == USAGE_X)\r
- {\r
- /* Turn on the appropriate LED according to direction if the delta is non-zero */\r
- if (DeltaMovement)\r
- LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);\r
- }\r
- else\r
- {\r
- /* Turn on the appropriate LED according to direction if the delta is non-zero */\r
- if (DeltaMovement)\r
- LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);\r
- }\r
- }\r
+ /* Process the read in mouse report from the device */\r
+ ProcessMouseReport(MouseReport);\r
}\r
\r
- /* Display the button information on the board LEDs */\r
- LEDs_SetAllLEDs(LEDMask);\r
+ /* Clear the IN endpoint, ready for next data packet */\r
+ Pipe_ClearIN();\r
}\r
\r
/* Freeze mouse data pipe */\r
}\r
}\r
\r
+/** Processes a read HID report from an attached mouse, extracting out elements via the HID parser results\r
+ * as required and displays movement and button presses on the board LEDs.\r
+ *\r
+ * \param MouseReport Pointer to a HID report from an attached mouse device\r
+ */\r
+void ProcessMouseReport(uint8_t* MouseReport)\r
+{\r
+ uint8_t LEDMask = LEDS_NO_LEDS;\r
+\r
+ /* Check each HID report item in turn, looking for mouse X/Y/button reports */\r
+ for (uint8_t ReportNumber = 0; ReportNumber < HIDReportInfo.TotalReportItems; ReportNumber++)\r
+ {\r
+ /* Create a temporary item pointer to the next report item */\r
+ HID_ReportItem_t* ReportItem = &HIDReportInfo.ReportItems[ReportNumber];\r
+ \r
+ bool FoundData;\r
+\r
+ if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_BUTTON) &&\r
+ (ReportItem->ItemType == REPORT_ITEM_TYPE_In))\r
+ {\r
+ /* Get the mouse button value */\r
+ FoundData = GetReportItemInfo(MouseReport, ReportItem);\r
+ \r
+ /* For multi-report devices - if the requested data was not in the issued report, continue */\r
+ if (!(FoundData))\r
+ continue;\r
+\r
+ /* If button is pressed, all LEDs are turned on */\r
+ if (ReportItem->Value)\r
+ LEDMask = LEDS_ALL_LEDS;\r
+ }\r
+ else if ((ReportItem->Attributes.Usage.Page == USAGE_PAGE_GENERIC_DCTRL) &&\r
+ ((ReportItem->Attributes.Usage.Usage == USAGE_X) ||\r
+ (ReportItem->Attributes.Usage.Usage == USAGE_Y)) &&\r
+ (ReportItem->ItemType == REPORT_ITEM_TYPE_In))\r
+ {\r
+ /* Get the mouse relative position value */\r
+ FoundData = GetReportItemInfo(MouseReport, ReportItem);\r
+ \r
+ /* For multi-report devices - if the requested data was not in the issued report, continue */\r
+ if (!(FoundData))\r
+ continue;\r
+ \r
+ int16_t DeltaMovement;\r
+ \r
+ if (ReportItem->Attributes.BitSize > 8)\r
+ DeltaMovement = (int16_t)ReportItem->Value;\r
+ else\r
+ DeltaMovement = (int8_t)ReportItem->Value;\r
+ \r
+ /* Determine if the report is for the X or Y delta movement */\r
+ if (ReportItem->Attributes.Usage.Usage == USAGE_X)\r
+ {\r
+ /* Turn on the appropriate LED according to direction if the delta is non-zero */\r
+ if (DeltaMovement)\r
+ LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);\r
+ }\r
+ else\r
+ {\r
+ /* Turn on the appropriate LED according to direction if the delta is non-zero */\r
+ if (DeltaMovement)\r
+ LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);\r
+ }\r
+ }\r
+ }\r
+ \r
+ /* Display the button information on the board LEDs */\r
+ LEDs_SetAllLEDs(LEDMask);\r
+}
\ No newline at end of file