Collapse configuration descriptor size retrieval and size testing into a single if...
[pub/USBasp.git] / Demos / Device / LowLevel / MIDI / MIDI.c
index 84d3778..8aed527 100644 (file)
@@ -116,16 +116,17 @@ void MIDI_Task(void)
 {\r
        static uint8_t PrevJoystickStatus;\r
 \r
-       /* Select the MIDI IN stream */\r
+       /* Device must be connected and configured for the task to run */\r
+       if (USB_DeviceState != DEVICE_STATE_Configured)\r
+         return;\r
+\r
        Endpoint_SelectEndpoint(MIDI_STREAM_IN_EPNUM);\r
 \r
-       /* Check if endpoint is ready to be written to */\r
        if (Endpoint_IsINReady())\r
        {\r
                uint8_t MIDICommand = 0;\r
                uint8_t MIDIPitch;\r
        \r
-               /* Get current joystick mask, XOR with previous to detect joystick changes */\r
                uint8_t JoystickStatus  = Joystick_GetStatus();\r
                uint8_t JoystickChanges = (JoystickStatus ^ PrevJoystickStatus);\r
                \r