Teensy USB MIDI - problems when expanding PrintIncoming example
I'm a beginner at C++, and I'm having a problem adding a new callback in the PrintIncoming example.
I added my new OnSysEx callback function like this:
I get a compiler error on the first line:
usbMIDI.setHandleSysEx(OnSysEx);
that says:
I don't understand how I need to declare the callback, since the other handlers used different parameters. For example,
and in usb_midi.h it is
I'm a beginner at C++, and I'm having a problem adding a new callback in the PrintIncoming example.
I added my new OnSysEx callback function like this:
Code:
void setup() {
Serial.begin(115200);
[COLOR=#0000ff] usbMIDI.setHandleSysEx(OnSysEx);[/COLOR]
usbMIDI.setHandleNoteOff(OnNoteOff);
usbMIDI.setHandleNoteOn(OnNoteOn);
usbMIDI.setHandleVelocityChange(OnVelocityChange);
usbMIDI.setHandleControlChange(OnControlChange);
usbMIDI.setHandleProgramChange(OnProgramChange);
usbMIDI.setHandleAfterTouch(OnAfterTouch);
usbMIDI.setHandlePitchChange(OnPitchChange);
}
void loop() {
usbMIDI.read(); // USB MIDI receive
}
[COLOR=#0000ff]void OnSysEx(byte *sxdata, word sxlength, bool sx_comp) { // const uint8_t *data, uint16_t length, bool complete
Serial.print("Sysex first byte ");
Serial.print(*sxdata, DEC);
Serial.print(", length=");
Serial.print(sxlength, DEC);
if (sx_comp) {
Serial.print(", done");
}
Serial.println();
}
[/COLOR]
void OnNoteOn(byte channel, byte note, byte velocity) {
Serial.print("Note On, ch=");
Serial.print(channel, DEC);
Serial.print(", note=");
Serial.print(note, DEC);
Serial.print(", velocity=");
Serial.print(velocity, DEC);
Serial.println();
}
I get a compiler error on the first line:
usbMIDI.setHandleSysEx(OnSysEx);
that says:
Code:
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.5-r2 (Windows 7), Board: "Teensy 3.1"
PrintIncomingSX.ino: In function 'void setup()':
PrintIncomingSX:13: error: invalid conversion from 'void (*)(byte*, word, bool) {aka void (*)(unsigned char*, unsigned int, bool)}' to 'void (*)(const uint8_t*, uint16_t, bool) {aka void (*)(const unsigned char*, short unsigned int, bool)}' [-fpermissive]
In file included from C:\Program Files\Arduino\hardware\teensy\cores\teensy3/WProgram.h:28:0,
from C:\Program Files\Arduino\hardware\teensy\cores\teensy3/Arduino.h:1,
from PrintIncomingSX.ino:11:
C:\Program Files\Arduino\hardware\teensy\cores\teensy3/usb_midi.h:168:21: error: initializing argument 1 of 'void usb_midi_class::setHandleSysEx(void (*)(const uint8_t*, uint16_t, bool))' [-fpermissive]
I don't understand how I need to declare the callback, since the other handlers used different parameters. For example,
Code:
void OnNoteOn(byte channel, byte note, byte velocity)
Code:
extern void (*usb_midi_handleNoteOn)(uint8_t ch, uint8_t note, uint8_t vel);
Last edited: