Simple USB-MIDI foot controller
Dependencies: PinDetect USBDevice_STM32F103 mbed-STM32F103C8T6
Diff: main.cpp
- Revision:
- 9:d5fa853818dd
- Parent:
- 8:75c5ec68765e
- Child:
- 10:f9a48eedfd59
diff -r 75c5ec68765e -r d5fa853818dd main.cpp --- a/main.cpp Fri Aug 04 05:22:22 2017 +0200 +++ b/main.cpp Fri Aug 04 05:55:36 2017 +0200 @@ -12,8 +12,8 @@ /* array of SwitchConfig structs */ SwitchConfig switches[NUM_SWITCHES] = { // pin, channel, control, on_value, off_value - {PB_4, 0xB0, 1, 1, 127, 0}, - {PB_5, 0xC0, 1, 0, 1, -1}, + {PB_4, 0xB0, 0, 1, 127, 0}, + {PB_5, 0xC0, 0, 0, 1, -1}, }; @@ -35,6 +35,25 @@ midi->write(msg); } +void handle_sysex(MIDIMessage msg) { + uint8_t sw; + + if (msg.data[1] == 0xF0 && msg.data[2] == 0x7D && msg.data[9] == 0xF7) { + sw = msg.data[3]; + if (sw < NUM_SWITCHES) { + switches[sw].type = msg.data[4]; + switches[sw].channel = msg.data[5]; + switches[sw].data1 = msg.data[6]; + switches[sw].on_value = msg.data[7]; + switches[sw].off_value = msg.data[8]; + handlers[sw]->setConfig(switches[sw]); +#ifndef NDEBUG + serial->printf("Changed configuration for switch %s.\r\n", sw); +#endif + } + } +} + int main() { // Configure system clock (72MHz HSE clock, 48MHz USB clock) confSysClock(); @@ -73,6 +92,8 @@ handlers[sw] = new SwitchHandler(&queue, &write_midi_msg, switches[sw]); } + midi->attach(&handle_sysex); + #ifndef NDEBUG serial->printf("Entering main loop...\r\n"); #endif