{\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
USB_MIDI_EventPacket_t MIDIEvent = (USB_MIDI_EventPacket_t)\r
{\r
.CableNumber = 0,\r
- .Command = MIDICommand,\r
+ .Command = (MIDICommand >> 4),\r
\r
- .Data1 = (MIDICommand << 4) | Channel,\r
+ .Data1 = MIDICommand | Channel,\r
.Data2 = MIDIPitch,\r
.Data3 = MIDI_STANDARD_VELOCITY, \r
};\r