Tighten up the code in the delta movement detection code in the MouseHostWithParser...
authorDean Camera <dean@fourwalledcubicle.com>
Mon, 9 Aug 2010 12:04:52 +0000 (12:04 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Mon, 9 Aug 2010 12:04:52 +0000 (12:04 +0000)
Demos/Host/ClassDriver/JoystickHostWithParser/JoystickHostWithParser.c
Demos/Host/ClassDriver/MouseHostWithParser/MouseHostWithParser.c
Demos/Host/LowLevel/JoystickHostWithParser/JoystickHostWithParser.c
Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c

index f1b4cac..8420d05 100644 (file)
@@ -148,16 +148,13 @@ int main(void)
                                                                  (ReportItem->Attributes.Usage.Usage == USAGE_Y))                 &&
                                                                 (ReportItem->ItemType                == REPORT_ITEM_TYPE_In))
                                                {
                                                                  (ReportItem->Attributes.Usage.Usage == USAGE_Y))                 &&
                                                                 (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
-                                                       {
-                                                               if (DeltaMovement)
+                                                               else
                                                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
                                                        }
                                                }
                                                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
                                                        }
                                                }
index 111bed4..7482b01 100644 (file)
@@ -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
-                                                       {
-                                                               if (DeltaMovement)
+                                                               else
                                                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
                                                        }
                                                }
                                                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
                                                        }
                                                }
index 91bd288..e92c242 100644 (file)
@@ -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 */
-                       if (ReportItem->Attributes.Usage.Usage == USAGE_X)
+                       /* Check to see if a (non-zero) delta movement has been indicated */
+                       if (DeltaMovement)
                        {
                        {
-                               /* Turn on the appropriate LED according to direction if the delta is non-zero */
-                               if (DeltaMovement)
+                               /* Determine if the report is for the X or Y delta movement, light LEDs as appropriate */
+                               if (ReportItem->Attributes.Usage.Usage == USAGE_X)
                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
-                       }
-                       else
-                       {
-                               /* Turn on the appropriate LED according to direction if the delta is non-zero */
-                               if (DeltaMovement)
+                               else
                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
                        }
                }
                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
                        }
                }
index 1b9c12a..38e4b25 100644 (file)
@@ -299,19 +299,15 @@ void ProcessMouseReport(uint8_t* MouseReport)
                        if (!(FoundData))
                          continue;
                          
                        if (!(FoundData))
                          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 */
-                       if (ReportItem->Attributes.Usage.Usage == USAGE_X)
+                       /* Check to see if a (non-zero) delta movement has been indicated */
+                       if (DeltaMovement)
                        {
                        {
-                               /* Turn on the appropriate LED according to direction if the delta is non-zero */
-                               if (DeltaMovement)
+                               /* Determine if the report is for the X or Y delta movement, light LEDs as appropriate */
+                               if (ReportItem->Attributes.Usage.Usage == USAGE_X)
                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED1 : LEDS_LED2);
-                       }
-                       else
-                       {
-                               /* Turn on the appropriate LED according to direction if the delta is non-zero */
-                               if (DeltaMovement)
+                               else
                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
                        }
                }
                                  LEDMask |= ((DeltaMovement > 0) ? LEDS_LED3 : LEDS_LED4);
                        }
                }