Simple USB-MIDI foot controller
Dependencies: PinDetect USBDevice_STM32F103 mbed-STM32F103C8T6
Diff: main.cpp
- Revision:
- 11:ff22140b5119
- Parent:
- 10:f9a48eedfd59
- Child:
- 12:d9ccbfd2cc8c
diff -r f9a48eedfd59 -r ff22140b5119 main.cpp --- a/main.cpp Fri Aug 04 06:08:29 2017 +0200 +++ b/main.cpp Fri Aug 04 07:23:38 2017 +0200 @@ -11,9 +11,9 @@ /* array of SwitchConfig structs */ SwitchConfig switches[NUM_SWITCHES] = { - // pin, channel, control, on_value, off_value - {PB_4, 0xB0, 0, 1, 127, 0}, - {PB_5, 0xC0, 0, 0, 1, -1}, + // pin, type, channel, data1, on_value, off_value + {PB_4, 0xB, 0, 1, 127, 0}, + {PB_5, 0xC, 0, 0, 1, -1}, }; @@ -38,21 +38,32 @@ void handle_sysex(MIDIMessage msg) { uint8_t sw; #ifndef NDEBUG - serial->printf("MIDI recv: status=%02X data1=%02X data2=%02X length=%d\r\n", - msg.data[1], msg.data[2], msg.data[3], msg.length); + serial->printf("MIDI recv: header=0x%02X status=0x%02X data1=0x%02X data2=%02d length=%d\r\n", + msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.length); #endif - if (msg.data[1] == 0xF0 && msg.data[2] == 0x7D && msg.data[9] == 0xF7) { + if (msg.data[1] == 0xF0 && msg.data[2] == 0x7D && msg.data[11] == 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]; + if (msg.data[7] > 0) + switches[sw].on_value = msg.data[8]; + else + switches[sw].on_value = -1; + if (msg.data[9] > 0) + switches[sw].off_value = msg.data[10]; + else + switches[sw].off_value = -1; handlers[sw]->setConfig(switches[sw]); #ifndef NDEBUG - serial->printf("Changed configuration for switch %s.\r\n", sw); + serial->printf("Changed configuration for switch %d.\r\n", sw + 1); + serial->printf("type: 0x%02X\r\n", switches[sw].type); + serial->printf("channel: %02d\r\n", switches[sw].channel); + serial->printf("data1: %02d\r\n", switches[sw].data1); + serial->printf("on_value: %02d\r\n", switches[sw].on_value); + serial->printf("off_value: %02d\r\n", switches[sw].off_value); #endif } }