Skip to content

Commit eb583b4

Browse files
committed
usb-device-midi: Add additional console output on TX.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 87cc34e commit eb583b4

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

micropython/usb/examples/device/midi_example.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414

1515

1616
class MIDIExample(MIDIInterface):
17+
# Very simple example event handler functions, showing how to receive note
18+
# and control change messages sent from the host to the device.
19+
#
20+
# If you need to send MIDI data to the host, then it's fine to instantiate
21+
# MIDIInterface class directly.
22+
23+
def on_open(self):
24+
super().on_open()
25+
print("Device opened by host")
26+
1727
def on_note_on(self, channel, pitch, vel):
1828
print(f"RX Note On channel {channel} pitch {pitch} velocity {vel}")
1929

@@ -35,17 +45,26 @@ def on_control_change(self, channel, controller, value):
3545

3646
print("Starting MIDI loop...")
3747

48+
# TX constants
49+
CHANNEL = 0
50+
PITCH = 60
51+
CONTROLLER = 64
52+
3853
control_val = 0
39-
channel = 0
4054

4155
while m.is_open():
4256
time.sleep(1)
43-
m.note_on(channel, 60)
57+
print(f"TX Note On channel {CHANNEL} pitch {PITCH}")
58+
m.note_on(CHANNEL, PITCH) # Velocity is an optional third argument
4459
time.sleep(0.5)
45-
m.note_off(channel, 60)
60+
print(f"TX Note Off channel {CHANNEL} pitch {PITCH}")
61+
m.note_off(CHANNEL, PITCH)
4662
time.sleep(1)
47-
m.control_change(channel, 64, control_val)
63+
print(f"TX Control channel {CHANNEL} controller {CONTROLLER} value {control_val}")
64+
m.control_change(CHANNEL, CONTROLLER, control_val)
4865
control_val += 1
4966
if control_val == 0x7F:
5067
control_val = 0
5168
time.sleep(1)
69+
70+
print("USB host has reset device, example done.")

0 commit comments

Comments
 (0)