hi, I am trying to connect several midi-devices and a mouse (hid) to the same hub and interact with all of them via USBHost on a teensy 4.1
If I upload just the mouse code, the mouse works. If I upload just the midi code the midi devices work. If I try to combine both, only the midi stuff works. I can see the mouse is recognised in the second sketch as well, but I get no values from it. Any hints on how to combine MIDI and HID in one sketch?
for reference here is the mouse-sketch: (pretty much from the examples, except for the midi sending part for x and y values)
and the midi code with an attempt to massage in the mouse part: (note that the mouse reports as being connected in the serial monitor...I just don't get any values)
this is the serial print I get from the second sketch (only the portion after the midi stuff):
If I upload just the mouse code, the mouse works. If I upload just the midi code the midi devices work. If I try to combine both, only the midi stuff works. I can see the mouse is recognised in the second sketch as well, but I get no values from it. Any hints on how to combine MIDI and HID in one sketch?
for reference here is the mouse-sketch: (pretty much from the examples, except for the midi sending part for x and y values)
Code:
// Simple test of USB Host Mouse/Keyboard
//
// This example is in the public domain
#include "USBHost_t36.h"
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
KeyboardController keyboard1(myusb);
KeyboardController keyboard2(myusb);
USBHIDParser hid1(myusb);
USBHIDParser hid2(myusb);
USBHIDParser hid3(myusb);
USBHIDParser hid4(myusb);
USBHIDParser hid5(myusb);
MouseController mouse1(myusb);
JoystickController joystick1(myusb);
//BluetoothController bluet(myusb, true, "0000"); // Version does pairing to device
BluetoothController bluet(myusb); // version assumes it already was paired
int user_axis[64];
uint32_t buttons_prev = 0;
RawHIDController rawhid1(myusb);
RawHIDController rawhid2(myusb, 0xffc90004);
USBDriver *drivers[] = {&hub1, &hub2,&joystick1, &bluet, &hid1, &hid2, &hid3, &hid4, &hid5};
#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
const char * driver_names[CNT_DEVICES] = {"Hub1","Hub2", "JOY1D", "Bluet", "HID1" , "HID2", "HID3", "HID4", "HID5"};
bool driver_active[CNT_DEVICES] = {false, false, false, false};
// Lets also look at HID Input devices
USBHIDInput *hiddrivers[] = {&mouse1, &keyboard1, &keyboard2, &joystick1, &rawhid1, &rawhid2};
#define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
const char * hid_driver_names[CNT_DEVICES] = {"Mouse1", "KB1", "KB2", "Joystick1", "RawHid1", "RawHid2"};
bool hid_driver_active[CNT_DEVICES] = {false, false};
bool show_changed_only = false;
uint8_t joystick_left_trigger_value = 0;
uint8_t joystick_right_trigger_value = 0;
uint64_t joystick_full_notify_mask = (uint64_t) - 1;
int old_y = 0;
int old_x = 0;
void setup()
{
// while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("\n\nUSB Host Testing");
Serial.println(sizeof(USBHub), DEC);
myusb.begin();
// The below forceBootProtocol will force which ever
// next keyboard that attaches to this device to be in boot protocol
// Only try this if you run into keyboard with issues. If this is a combined
// device like wireless mouse and keyboard this can cause mouse problems.
//keyboard1.forceBootProtocol();
rawhid1.attachReceive(OnReceiveHidData);
rawhid2.attachReceive(OnReceiveHidData);
}
void loop()
{
myusb.Task();
if (Serial.available()) {
int ch = Serial.read(); // get the first char.
while (Serial.read() != -1) ;
if ((ch == 'b') || (ch == 'B')) {
Serial.println("Only notify on Basic Axis changes");
joystick1.axisChangeNotifyMask(0x3ff);
} else if ((ch == 'f') || (ch == 'F')) {
Serial.println("Only notify on Full Axis changes");
joystick1.axisChangeNotifyMask(joystick_full_notify_mask);
} else {
if (show_changed_only) {
show_changed_only = false;
Serial.println("\n*** Show All fields mode ***");
} else {
show_changed_only = true;
Serial.println("\n*** Show only changed fields mode ***");
}
}
}
for (uint8_t i = 0; i < CNT_DEVICES; i++) {
if (*drivers[i] != driver_active[i]) {
if (driver_active[i]) {
Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
driver_active[i] = false;
} else {
Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
driver_active[i] = true;
const uint8_t *psz = drivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = drivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = drivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
}
}
}
for (uint8_t i = 0; i < CNT_HIDDEVICES; i++) {
if (*hiddrivers[i] != hid_driver_active[i]) {
if (hid_driver_active[i]) {
Serial.printf("*** HID Device %s - disconnected ***\n", hid_driver_names[i]);
hid_driver_active[i] = false;
} else {
Serial.printf("*** HID Device %s %x:%x - connected ***\n", hid_driver_names[i], hiddrivers[i]->idVendor(), hiddrivers[i]->idProduct());
hid_driver_active[i] = true;
const uint8_t *psz = hiddrivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = hiddrivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = hiddrivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
// Note: with some keyboards there is an issue that they don't output in boot protocol mode
// and may not work. The above code can try to force the keyboard into boot mode, but there
// are issues with doing this blindly with combo devices like wireless keyboard/mouse, which
// may cause the mouse to not work. Note: the above id is in the builtin list of
// vendor IDs that are already forced
#if 0 // In list in older, newer code should support the N Key rollover directly
if (hiddrivers[i] == &keyboard1) {
if (keyboard1.idVendor() == 0x04D9) {
Serial.println("Gigabyte vendor: force boot protocol");
// Gigabyte keyboard
keyboard1.forceBootProtocol();
}
}
#endif
}
}
}
if (mouse1.available()) {
/* Serial.print("Mouse: buttons = ");
Serial.print(mouse1.getButtons());
Serial.print(", mouseX = ");
Serial.print(mouse1.getMouseX());
Serial.print(", mouseY = ");
Serial.print(mouse1.getMouseY());
Serial.print(", wheel = ");
Serial.print(mouse1.getWheel());
Serial.print(", wheelH = ");
Serial.print(mouse1.getWheelH());
Serial.println();
mouse1.mouseDataClear(); */
int y = mouse1.getMouseY()>>8;
int x = mouse1.getMouseX()>>8;
if (y != old_y) {
usbMIDI.sendControlChange(1,y,1);
}
old_y = y;
if (x != old_x) {
usbMIDI.sendControlChange(2,x,1);
}
old_x = x;
}
// See if we have some RAW data
if (rawhid1) {
Serial.println("we have rawhid");
int ch;
uint8_t buffer[64];
uint8_t count_chars = 0;
memset(buffer, 0, sizeof(buffer));
if (Serial.available()) {
while (((ch = Serial.read()) != -1) && (count_chars < sizeof(buffer))) {
buffer[count_chars++] = ch;
}
rawhid1.sendPacket(buffer);
}
}
}
void OnHIDExtrasRelease(uint32_t top, uint16_t key)
{
Serial.print("HID (");
Serial.print(top, HEX);
Serial.print(") key release:");
Serial.println(key, HEX);
}
bool OnReceiveHidData(uint32_t usage, const uint8_t *data, uint32_t len) {
// Called for maybe both HIDS for rawhid basic test. One is for the Teensy
// to output to Serial. while still having Raw Hid...
if (usage == 0xffc90004) {
// Lets trim off trailing null characters.
while ((len > 0) && (data[len - 1] == 0)) {
len--;
}
if (len) {
Serial.print("RawHid Serial: ");
Serial.write(data, len);
}
} else {
Serial.print("RawHID data: ");
Serial.println(usage, HEX);
while (len) {
uint8_t cb = (len > 16) ? 16 : len;
const uint8_t *p = data;
uint8_t i;
for (i = 0; i < cb; i++) {
Serial.printf("%02x ", *p++);
}
Serial.print(": ");
for (i = 0; i < cb; i++) {
Serial.write(((*data >= ' ') && (*data <= '~')) ? *data : '.');
data++;
}
len -= cb;
Serial.println();
}
}
return true;
}
and the midi code with an attempt to massage in the mouse part: (note that the mouse reports as being connected in the serial monitor...I just don't get any values)
Code:
//cpu speed 600 mhz and fast instead of fastest increases stability?
#include <MIDI.h> // access to serial (5 pin DIN) MIDI
#include <USBHost_t36.h> // access to USB MIDI devices (plugged into 2nd USB port)
//#include "WacomController.h"
//includes for OLEDs
//#include <i2c_driver_wire.h> //Library for I2C interface
#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#include <Wire.h>
extern void leds_update();
extern void led_color(unsigned int num, unsigned int rgb);
extern void led_color(unsigned int num, unsigned char red, unsigned char green, unsigned char blue);
extern void led_channel(unsigned int num, unsigned int val);
#define OFF 0x000000
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define PINK 0xFF1088
#define ORANGE 0xE05800
#define WHITE 0xFFFFFF
U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ 19, /* data=*/ 18);
#define DEBUG
// Create the Serial MIDI ports
MIDI_CREATE_INSTANCE(HardwareSerial, Serial8, MIDI1);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI2);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial4, MIDI3);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial5, MIDI4);
//midi::MidiInterface &SerialMidiList[6] = {MIDI1, MIDI2, MIDI3, MIDI4, MIDI5, MIDI6};
//usb synth devices
int pulse2 = -1;
int keysaxo = -1;
int minitaur = -1;
int axodub = -1;
//int blofeld = -1;
//usb midibass controller
int midibass = -1;
//dmx color routing for cheap thomann light, reordering midi aftertouch to matching colors ...
//3= blue 2= green 1= red 4= white
int color_order[4] {3,2,1,4};
//handle on screen boot messages...
elapsedMillis boottime;
int state = 0;
// Create the ports for USB devices plugged into Teensy's 2nd USB port (via hubs)
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
USBHub hub5(myusb);
USBHub hub6(myusb);
USBHub hub7(myusb);
USBHub hub8(myusb);
MIDIDevice_BigBuffer midi01(myusb);
MIDIDevice_BigBuffer midi02(myusb);
MIDIDevice_BigBuffer midi03(myusb);
MIDIDevice_BigBuffer midi04(myusb);
MIDIDevice_BigBuffer midi05(myusb);
MIDIDevice_BigBuffer midi06(myusb);
MIDIDevice_BigBuffer midi07(myusb);
MIDIDevice_BigBuffer midi08(myusb);
USBHIDParser hid1(myusb);
USBHIDParser hid2(myusb);
MouseController mouse1(myusb);
MIDIDevice_BigBuffer * midilist[8] = {
&midi01, &midi02, &midi03, &midi04, &midi05, &midi06, &midi07, &midi08
};
USBDriver *drivers[] = {&hub1, &hub2,&hub3, &hub4,&hub5, &hub6, &hub7, &hub8, &hid1, &hid2};
#define CNT_DEVICES (sizeof(drivers)/sizeof(drivers[0]))
const char * driver_names[CNT_DEVICES] = {"Hub1","Hub2", "Hub3", "Hub4", "Hub5" , "Hub6", "Hub7", "Hub8", "&HID1", "&HID2"};
bool driver_active[CNT_DEVICES] = {false, false, false, false};
// Lets also look at HID Input devices
USBHIDInput *hiddrivers[] = {&mouse1};
#define CNT_HIDDEVICES (sizeof(hiddrivers)/sizeof(hiddrivers[0]))
const char * hid_driver_names[CNT_DEVICES] = {"Mouse1"};
bool hid_driver_active[CNT_DEVICES] = {false};
/*
USBHIDParser hid1(myusb);
USBHIDParser hid2(myusb);
USBHIDParser hid3(myusb);
USBHIDParser hid4(myusb);
USBHIDParser hid5(myusb);
USBHIDParser hid6(myusb);
USBHIDParser hid7(myusb);
WacomController digi1(myusb);
//wacom stuff
int axis_prev[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
//wacom midi stuff
int x_val;
int y_val;
int old_x_val;
int old_y_val;
USBDriver *drivers[] = { &hub1, &hub2, &hub3, &hub4, &hid1, &hid2, &hid3, &hid4, &hid5, &hid6, &hid7 };
#define CNT_DEVICES (sizeof(drivers) / sizeof(drivers[0]))
const char *driver_names[CNT_DEVICES] = { "Hub1", "Hub2","Hub3", "Hub4", "HID1", "HID2", "HID3", "HID4", "HID5", "HID6", "HID7" };
bool driver_active[CNT_DEVICES] = { false, false, false, false };
// Lets also look at HID Input devices
USBHIDInput *hiddrivers[] = { &digi1 };
#define CNT_HIDDEVICES (sizeof(hiddrivers) / sizeof(hiddrivers[0]))
const char *hid_driver_names[CNT_DEVICES] = { "digi1" };
bool hid_driver_active[CNT_DEVICES] = { false };
bool show_changed_only = false;
// A variable to know how long the LED has been turned on
//elapsedMillis ledOnMillis;
*/
//dmx stuff
long counter = 0;
int decay = 64; //starts decay at the halfway point
elapsedMillis timeout;
int old_y = 0;
int old_x = 0;
void setup() {
Wire.setSDA(18);
Wire.setSCL(19);
u8x8.begin();
u8x8.setPowerSave(0);
u8x8.setFont(u8x8_font_5x8_f);
while (!Serial && millis() < 1200) {
u8x8.drawString(0,4,"Booting...");
};
u8x8.clear();
for (int i=0; i<13; i++) {
pinMode(i,INPUT_DISABLE);
}
for (int i=24; i<34; i++) {
pinMode(i,INPUT_DISABLE);
}
for (int i=36; i<55; i++) {
pinMode(i,INPUT_DISABLE);
}
pinMode(22,INPUT_DISABLE);
pinMode(23,INPUT_DISABLE);
#ifdef DEBUG
Serial.begin(115200);
#endif
pinMode(13, OUTPUT); // LED pin
digitalWrite(13, LOW);
MIDI1.begin(MIDI_CHANNEL_OMNI);
MIDI2.begin(MIDI_CHANNEL_OMNI);
MIDI3.begin(MIDI_CHANNEL_OMNI);
MIDI4.begin(MIDI_CHANNEL_OMNI);
// Wait 3.5 seconds before turning on USB Host. If connected USB devices
// use too much power, Teensy at least completes USB enumeration, which
// makes isolating the power issue easier.
#ifdef DEBUG
Serial.println("Booting...");
#endif
boottime = 0;
while (boottime < 1000) {
if (boottime < 300) {
if (!state) u8x8.drawString(0,4,"W");
state = 1;
} else if (boottime < 600) {
if (state == 1) u8x8.drawString(0,4,"WA");
state = 2;
} else if (boottime < 900) {
if (state == 2) u8x8.drawString(0,4,"WAI");
state = 3;
}
}
// u8x8.drawString(0,0,"Booting");
// delay(3500);
//
//usbMIDI.begin();
myusb.begin();
delay(100);
boottime = 0;
//wait another 10 seconds before enumerating the devices, hopefully by now they have settled.
while (boottime < 3000) {
if (boottime < 300) {
if (state == 3) u8x8.drawString(0,4,"WAIT");
state = 4;
} else if (boottime < 600) {
if (state == 4) u8x8.drawString(0,4,"WAITI");
state = 5;
} else if (boottime < 900) {
if (state == 5) u8x8.drawString(0,4,"WAITIN");
state = 6;
} else if (boottime < 1200) {
if (state == 6) u8x8.drawString(0,4,"WAITING");
state = 7;
} else if (boottime < 1500) {
if (state == 7) u8x8.drawString(0,4,"WAITING.");
state = 8;
} else if (boottime < 1800) {
if (state == 8)u8x8.drawString(0,4,"WAITING..");
state = 9;
} else if (boottime < 2100) {
if (state == 9)u8x8.drawString(0,4,"WAITING...");
state = 10;
} else if (boottime < 2400) {
if (state == 10) u8x8.drawString(0,4,"WAITING....");
state = 11;
} else if (boottime < 2700) {
if (state == 11) u8x8.drawString(0,4,"WAITING.....");
state = 12;
} else if (boottime < 3000){
if (state == 12) u8x8.drawString(0,4,"WAITING......");
state = 13;
}
}
u8x8.clear();
u8x8.drawString(0,0," USB DEVICES ");
u8x8.drawString(0,1,"---------------");
u8x8.drawString(0,7,"---------------");
delay(500);
//delay(10000);
Serial.println("");
Serial.println("------------NEW START--------------");
for (int i=0; i<8; i++) {
if (midilist[i]->manufacturer() != NULL && midilist[i]->serialNumber() != NULL) {
// #ifdef DEBUG
Serial.println("-----------------------------------");
Serial.print("Serial:");
Serial.println((char*)midilist[i]->serialNumber());
Serial.print("ProductID:");
Serial.println(midilist[i]->idProduct());
Serial.println("-----------------------------------");
// #endif
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"003600433435511733353932")) {//Axoloti for qunexus/vocoder serial
#ifdef DEBUG
Serial.println("here is axovocoder");
#endif
u8x8.drawString(0,i+2,"AxoVox");
u8x8.drawString(10,i+2,String(i).c_str());
keysaxo = i;
}
if (midilist[i]->idProduct() == 22) {
#ifdef DEBUG
Serial.println("here is Pulse2");
#endif
u8x8.drawString(0,i+2,"Pulse2");
u8x8.drawString(10,i+2,String(i).c_str());
pulse2 = i;
}
/* if (midilist[i]->idProduct() == 19) {
#ifdef DEBUG
Serial.println("here is Blofeld");
#endif
u8x8.drawString(0,i+2,"Blofeld");
u8x8.drawString(10,i+2,String(i).c_str());
blofeld = i;
} */
/* if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"325B346C3030")) {//typhon dreadbox
#ifdef DEBUG
Serial.println("here is typhon dreadbox");
#endif
dreadbox = i;
} */
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"12209010")) {//midibass
#ifdef DEBUG
Serial.println("here is MIDIBASS!!");
#endif
u8x8.drawString(0,i+2,"MIDIBASS");
u8x8.drawString(10,i+2,String(i).c_str());
midibass = i;
}
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"003500323532470532323631")) {//Axoloti for "serum" sounds
#ifdef DEBUG
Serial.println("here is axodub");
#endif
u8x8.drawString(0,i+2,"AxoDub");
u8x8.drawString(10,i+2,String(i).c_str());
axodub = i;
}
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"MTc537ef")) {//moog minitaur
#ifdef DEBUG
Serial.println("here is the minitaur");
#endif
u8x8.drawString(0,i+2,"Minitaur");
u8x8.drawString(10,i+2,String(i).c_str());
minitaur = i;
}
}
delay(300);
}
delay(100);
Serial.println("------------Finished------------");
for (uint8_t i = 0; i < CNT_DEVICES; i++) {
if (*drivers[i] != driver_active[i]) {
if (driver_active[i]) {
Serial.printf("*** Device %s - disconnected ***\n", driver_names[i]);
driver_active[i] = false;
} else {
Serial.printf("*** Device %s %x:%x - connected ***\n", driver_names[i], drivers[i]->idVendor(), drivers[i]->idProduct());
driver_active[i] = true;
const uint8_t *psz = drivers[i]->manufacturer();
if (psz && *psz) Serial.printf(" manufacturer: %s\n", psz);
psz = drivers[i]->product();
if (psz && *psz) Serial.printf(" product: %s\n", psz);
psz = drivers[i]->serialNumber();
if (psz && *psz) Serial.printf(" Serial: %s\n", psz);
}
}
}
if (pulse2 >= 0) midilist[pulse2]->sendProgramChange(0,6);
// delay(1);
if (axodub >= 0 ) midilist[axodub]->sendProgramChange(0,1);
// delay(1);
if (minitaur >= 0) midilist[minitaur]->sendProgramChange(1,8);
//send to dreadbox typhon...
MIDI1.sendProgramChange(0,9);
usbMIDI.sendProgramChange(0,1);
/* if (blofeld >= 0) {
midilist[blofeld]->sendControlChange(0,127,6);
midilist[blofeld]->sendControlChange(32,127,6);
midilist[blofeld]->sendProgramChange(0,6);
} */
}
void loop() {
leds_update();
myusb.Task();
if (mouse1.available()) {
Serial.print("Mouse: buttons = ");
Serial.print(mouse1.getButtons());
Serial.print(", mouseX = ");
Serial.print(mouse1.getMouseX());
Serial.print(", mouseY = ");
Serial.print(mouse1.getMouseY());
Serial.print(", wheel = ");
Serial.print(mouse1.getWheel());
Serial.print(", wheelH = ");
Serial.print(mouse1.getWheelH());
Serial.println();
mouse1.mouseDataClear();
int y = mouse1.getMouseY()>>8;
int x = mouse1.getMouseX()>>8;
if (y != old_y) {
usbMIDI.sendControlChange(1,y,1);
}
old_y = y;
if (x != old_x) {
usbMIDI.sendControlChange(2,x,1);
}
old_x = x;
}
/* if (digi1.available()) {
int touch_count = digi1.getTouchCount();
int touch_index;
uint16_t buttons_bin = digi1.getPenButtons();
bool pen_button[3];
// Serial.printf("Digitizer: ");
for (int i = 0; i < 3; i++) {
pen_button[i] = (buttons_bin >> i) & 0x1;
// Serial.printf("Pen_Btn%d:%d ",i, pen_button[i]);
}
switch (digi1.eventType()) {
case WacomController::TOUCH:
Serial.print(" Touch:");
for (touch_index = 0; touch_index < touch_count; touch_index++) {
Serial.printf(" (%d, %d)", digi1.getX(touch_index), digi1.getY(touch_index));
}
break;
case WacomController::PEN:
Serial.printf(" Pen: (%d, %d) Pressure: %u Distance: %u", digi1.getX(), digi1.getY(),
digi1.getPenPressure(), digi1.getPenDistance());
Serial.printf(" TiltX: %d TiltY: %d",digi1.getPenTiltX(), digi1.getPenTiltY());
break;
case WacomController::MOUSE:
// Serial.printf(" Pen: (%d, %d) Pressure: %u Distance: %u", digi1.getX(), digi1.getY(),
// digi1.getPenPressure(), digi1.getPenDistance());
x_val = digi1.getX()>>8;
if (x_val != old_x_val) usbMIDI.sendControlChange(4,x_val,1,0);
old_x_val = x_val;
y_val = digi1.getY()/160;
if (y_val != old_y_val) usbMIDI.sendControlChange(5,y_val,1,0);
old_y_val = y_val;
//Serial.printf("Buttons: %d",digi1.getMouseButtons());
// Serial.printf(" TiltX: %d TiltY: %d",digi1.getPenTiltX(), digi1.getPenTiltY());
break;
case WacomController::FRAME:
{
//wheel data 0-71
Serial.printf(" Whl: %d ", digi1.getFrameWheel());
//wheel button binary, no touch functionality
Serial.printf(" WhlBtn: %d ", digi1.getFrameWheelButton());
if (digi1.getFrameWheelButton()) {
static uint8_t mode = 0;
mode = (mode + 1) % 4;
Serial.printf("Mode: %d",mode);
digi1.changeLed(mode);
}
//buttons are saved within one byte for all the 8 buttons, here is a decoding example
uint16_t button_touch_bin = digi1.getFrameTouchButtons();
uint16_t button_press_bin = digi1.getFrameButtons();
bool button_touched[8];
bool button_pressed[8];
for (int i = 0; i < 8; i++) {
button_touched[i] = (button_touch_bin >> i) & 0x1;
button_pressed[i] = (button_press_bin >> i) & 0x1;
Serial.printf("Btn%d: T:%d P:%d ",i,button_touched[i], button_pressed[i]);
}
}
break;
default:
Serial.printf(", X = %u, Y = %u", digi1.getX(), digi1.getY());
Serial.print(", Pressure: = ");
Serial.print(", wheel = ");
Serial.print(digi1.getWheel());
Serial.print(", wheelH = ");
Serial.print(digi1.getWheelH());
if (show_changed_only) Serial.print("\t: ");
else
Serial.println();
for (uint8_t i = 0; i < 16; i++) {
int axis = digi1.getAxis(i);
if (show_changed_only) {
if (axis != axis_prev[i]) Serial.printf(" %d#%d(%x)", i, axis, axis);
} else
Serial.printf(" %d%c%d(%x)", i, (axis == axis_prev[i]) ? ':' : '#', axis, axis);
axis_prev[i] = axis;
}
break;
}
Serial.println();
digi1.digitizerDataClear();
} */
if(usbMIDI.read()) {
uint8_t type = usbMIDI.getType();
uint8_t data1 = usbMIDI.getData1();
uint8_t data2 = usbMIDI.getData2();
uint8_t channel = usbMIDI.getChannel();
uint8_t cable = usbMIDI.getCable();
if (midibass >= 0){
midilist[midibass]->send(type, data1, data2, channel, cable);
}
// int dmxChannel = (channel -1)*128 + data1;
// led_channel(dmxChannel, data2*2);
}
myusb.Task();
if (midibass >= 0){
if (midilist[midibass]->read()) {
uint8_t type = midilist[midibass]->getType();
uint8_t data1 = midilist[midibass]->getData1();
uint8_t data2 = midilist[midibass]->getData2();
uint8_t channel = midilist[midibass]->getChannel();
uint8_t cable = midilist[midibass]->getCable();
// const uint8_t *sys = midilist[midibass]->getSysExArray();
midi::MidiType mtype = (midi::MidiType)type;
if (type != 0xC0) {
if (!cable) {
if (channel == 1) {
sendToMacMini(type, data1, data2, channel, 0);
// if (axodub >= 0) midilist[axodub]->send(type, data1, data2, channel);
}
if (channel == 6) {
if (pulse2 >= 0) midilist[pulse2]->send(type, data1, data2, channel);
// if (blofeld >= 0) midilist[blofeld]->send(type, data1, data2, channel);
}
if (channel == 7) {
if (axodub >= 0) midilist[axodub]->send(type, data1, data2, channel);
}
if (channel == 8) {
if (minitaur >= 0) midilist[minitaur]->send(type, data1, data2, channel);
// if (blofeld >= 0) midilist[blofeld]->send(type, data1, data2, channel);
}
if (channel == 9) {
//if (dreadbox < 11) midilist[dreadbox]->send(type, data1, data2, channel);
MIDI1.send(mtype, data1, data2, channel);
// if (blofeld >= 0) midilist[blofeld]->send(type, data1, data2, channel);
}
if (((channel > 1) && (channel < 6)) || (channel > 9)) {
sendToMacMini(type, data1, data2, channel, 0); // channel 2-5 and 10-16
}
// dmx lightshow based on midi input...
if (type == 0xD0) {
//aftertouch to lights... for now...
int lookup = (channel - 2) % 4;
int dmxChannel = color_order[lookup];
// Serial.println(dmxChannel);
led_channel(dmxChannel, data1*2);
}
if (type == 0xB0) {
if ((channel == 8) && (data1 == 1)) led_channel(1,data2*2); //red for the minitaur
}
}
else if (cable == 1) {
sendToMacMini(type, data1, data2, channel, 1); //send all accordion data to the macmini on port 1
if ((channel > 12) && (keysaxo >= 0)) {
midilist[keysaxo]->send(type, data1, data2, channel);
// MIDI2.send(mtype, data1, data2, channel);
// Serial.println(type);
}
}
} else if (type == 0xC0) {
/* if (blofeld >= 0) {
midilist[blofeld]->sendControlChange(0,127,6);
midilist[blofeld]->sendControlChange(32,127,6);
midilist[blofeld]->sendProgramChange(data1,6);
} */
if (pulse2 >= 0) midilist[pulse2]->sendProgramChange(data1,6);
// delay(1);
if (axodub >= 0 ) midilist[axodub]->sendProgramChange(data1,1);
// delay(1);
if (minitaur >= 0) midilist[minitaur]->sendProgramChange(data1 + 1,8);
//send to dreadbox typhon...
MIDI1.sendProgramChange(data1,9);
//send to macmini...
usbMIDI.sendProgramChange(data1,1);
}
// activity = true;
}
}
}
void sendToMacMini(byte type, byte data1, byte data2, byte channel, byte cable)
{
if (type != midi::SystemExclusive) {
usbMIDI.send(type, data1, data2, channel, cable);
} else {
// unsigned int SysExLength = data1 + data2 * 256;
// usbMIDI.sendSysEx(SysExLength, sysexarray, true, cable);
}
}
this is the serial print I get from the second sketch (only the portion after the midi stuff):
Code:
17:09:15.053 -> ------------Finished------------
17:09:15.053 -> *** Device Hub1 5e3:610 - connected ***
17:09:15.053 -> manufacturer: GenesysLogic
17:09:15.053 -> product: USB2.1 Hub
17:09:15.053 -> *** Device Hub2 5e3:610 - connected ***
17:09:15.053 -> manufacturer: GenesysLogic
17:09:15.053 -> product: USB2.1 Hub
17:09:15.053 -> *** Device &HID1 16c0:485 - connected ***
17:09:15.053 -> manufacturer: Teensyduino
17:09:15.053 -> product: Teensy MIDIx4
17:09:15.053 -> Serial: 12209010
17:09:15.053 -> *** Device &HID2 1ff7:9 - connected ***
17:09:15.053 -> manufacturer: IrScreen ca