Change device demos to cache the board button values in the same manner as the board...
authorDean Camera <dean@fourwalledcubicle.com>
Wed, 6 May 2009 12:43:00 +0000 (12:43 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Wed, 6 May 2009 12:43:00 +0000 (12:43 +0000)
Demos/Device/Joystick/Joystick.c
Demos/Device/Mouse/Mouse.c
LUFA/Drivers/USB/LowLevel/DevChapter9.c

index b2de42f..cf136d0 100644 (file)
@@ -153,9 +153,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
  */\r
 bool GetNextReport(USB_JoystickReport_Data_t* ReportData)\r
 {\r
-       static uint8_t PrevJoyStatus = 0;\r
-       uint8_t        JoyStatus_LCL        = Joystick_GetStatus();\r
-       bool           InputChanged         = false;\r
+       static uint8_t PrevJoyStatus    = 0;\r
+       uint8_t        JoyStatus_LCL    = Joystick_GetStatus();\r
+       uint8_t        ButtonStatus_LCL = Buttons_GetStatus();\r
+       bool           InputChanged     = false;\r
 \r
        /* Clear the report contents */\r
        memset(ReportData, 0, sizeof(USB_JoystickReport_Data_t));\r
@@ -173,14 +174,15 @@ bool GetNextReport(USB_JoystickReport_Data_t* ReportData)
        if (JoyStatus_LCL & JOY_PRESS)\r
          ReportData->Button  = (1 << 1);\r
          \r
-       if (Buttons_GetStatus() & BUTTONS_BUTTON1)\r
+       if (ButtonStatus_LCL & BUTTONS_BUTTON1)\r
          ReportData->Button |= (1 << 0);\r
          \r
        /* Check if the new report is different to the previous report */\r
-       InputChanged = (uint8_t)(PrevJoyStatus ^ JoyStatus_LCL);\r
+       InputChanged = (uint8_t)(PrevJoyStatus ^ JoyStatus_LCL) | (uint8_t)(PrevButtonStatus ^ ButtonStatus_LCL);\r
 \r
        /* Save the current joystick status for later comparison */\r
-       PrevJoyStatus = JoyStatus_LCL;\r
+       PrevJoyStatus    = JoyStatus_LCL;\r
+       PrevButtonStatus = ButtonStatus_LCL;\r
 \r
        /* Return whether the new report is different to the previous report or not */\r
        return InputChanged;\r
index 7fff291..763d366 100644 (file)
@@ -287,7 +287,8 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
  */\r
 void CreateMouseReport(USB_MouseReport_Data_t* ReportData)\r
 {\r
-       uint8_t JoyStatus_LCL = Joystick_GetStatus();\r
+       uint8_t JoyStatus_LCL    = Joystick_GetStatus();\r
+       uint8_t ButtonStatus_LCL = Buttons_GetStatus();\r
        \r
        /* Clear the report contents */\r
        memset(ReportData, 0, sizeof(USB_MouseReport_Data_t));\r
@@ -305,7 +306,7 @@ void CreateMouseReport(USB_MouseReport_Data_t* ReportData)
        if (JoyStatus_LCL & JOY_PRESS)\r
          ReportData->Button  = (1 << 0);\r
          \r
-       if (Buttons_GetStatus() & BUTTONS_BUTTON1)\r
+       if (ButtonStatus_LCL & BUTTONS_BUTTON1)\r
          ReportData->Button |= (1 << 1);\r
 }\r
 \r
index bf1cb6c..9c319fc 100644 (file)
@@ -131,7 +131,7 @@ static void USB_Device_SetAddress(void)
 \r
 static void USB_Device_SetConfiguration(void)\r
 {\r
-       bool    AlreadyConfigured = (USB_ConfigurationNumber != 0);\r
+       bool AlreadyConfigured = (USB_ConfigurationNumber != 0);\r
 \r
 #if defined(USE_SINGLE_DEVICE_CONFIGURATION)\r
        if ((uint8_t)USB_ControlRequest.wValue > 1)\r
@@ -188,7 +188,7 @@ static void USB_Device_GetDescriptor(void)
        #if defined(USE_RAM_DESCRIPTORS)\r
        Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);\r
        #else\r
-       bool     SendZLP;\r
+       bool SendZLP;\r
        \r
        if (USB_ControlRequest.wLength > DescriptorSize)\r
          USB_ControlRequest.wLength = DescriptorSize;\r