Tighten up the code in the delta movement detection code in the MouseHostWithParser and JoystickHostWithParser demos. Make the ClassDriver JoystickHostWithParser demo use the HID_ALIGN_DATA() macro instead of manual shifting and casting.

pull/1469/head
Dean Camera 14 years ago
parent 508e905d8d
commit eb060db71b

@ -148,16 +148,13 @@ int main(void)
(ReportItem->Attributes.Usage.Usage == USAGE_Y)) && (ReportItem->Attributes.Usage.Usage == USAGE_Y)) &&
(ReportItem->ItemType == REPORT_ITEM_TYPE_In)) (ReportItem->ItemType == REPORT_ITEM_TYPE_In))
{ {
int16_t DeltaMovement = (int16_t)(ReportItem->Value << (16 - ReportItem->Attributes.BitSize)); int16_t DeltaMovement = HID_ALIGN_DATA(ReportItem, int16_t);
if (ReportItem->Attributes.Usage.Usage == USAGE_X) if (DeltaMovement)
{ {
if (DeltaMovement) if (ReportItem->Attributes.Usage.Usage == USAGE_X)
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2); LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
} else
else
{
if (DeltaMovement)
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4); LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
} }
} }

@ -159,14 +159,11 @@ int main(void)
{ {
int16_t DeltaMovement = HID_ALIGN_DATA(ReportItem, int16_t); int16_t DeltaMovement = HID_ALIGN_DATA(ReportItem, int16_t);
if (ReportItem->Attributes.Usage.Usage == USAGE_X) if (DeltaMovement)
{ {
if (DeltaMovement) if (ReportItem->Attributes.Usage.Usage == USAGE_X)
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2); LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
} else
else
{
if (DeltaMovement)
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4); LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
} }
} }

@ -285,17 +285,13 @@ void ProcessJoystickReport(uint8_t* JoystickReport)
int16_t DeltaMovement = HID_ALIGN_DATA(ReportItem, int16_t); int16_t DeltaMovement = HID_ALIGN_DATA(ReportItem, int16_t);
/* Determine if the report is for the X or Y delta movement */ /* Check to see if a (non-zero) delta movement has been indicated */
if (ReportItem->Attributes.Usage.Usage == USAGE_X) if (DeltaMovement)
{ {
/* Turn on the appropriate LED according to direction if the delta is non-zero */ /* Determine if the report is for the X or Y delta movement, light LEDs as appropriate */
if (DeltaMovement) if (ReportItem->Attributes.Usage.Usage == USAGE_X)
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2); LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
} else
else
{
/* Turn on the appropriate LED according to direction if the delta is non-zero */
if (DeltaMovement)
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4); LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
} }
} }

@ -299,19 +299,15 @@ void ProcessMouseReport(uint8_t* MouseReport)
if (!(FoundData)) if (!(FoundData))
continue; continue;
int16_t DeltaMovement = (int16_t)(ReportItem->Value << (16 - ReportItem->Attributes.BitSize)); int16_t DeltaMovement = HID_ALIGN_DATA(ReportItem, int16_t);
/* Determine if the report is for the X or Y delta movement */ /* Check to see if a (non-zero) delta movement has been indicated */
if (ReportItem->Attributes.Usage.Usage == USAGE_X) if (DeltaMovement)
{ {
/* Turn on the appropriate LED according to direction if the delta is non-zero */ /* Determine if the report is for the X or Y delta movement, light LEDs as appropriate */
if (DeltaMovement) if (ReportItem->Attributes.Usage.Usage == USAGE_X)
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2); LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
} else
else
{
/* Turn on the appropriate LED according to direction if the delta is non-zero */
if (DeltaMovement)
LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4); LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
} }
} }

Loading…
Cancel
Save