Mouse and TouchscreenUSB "cancel" each other? [Teensy 4.1]

I'm working on a way to make a touchpad/keyboard combo device work on Android here:
https://forum.pjrc.com/threads/7037...board-Trackpad-(multi-touch)-HID-combo-device

There I stumbled upon an issue that when I use one-finger-movement to move the mouse and two-finger-movement to do touch input on the target device.
So I made a test sketch that alternates mouse and touch input. See the 4 demo video clips below to see what happens.

Code:
int timeLast, mode, x, y;
bool touchActive;

void setup()
{
    Mouse.screenSize(1920, 1080);
    timeLast = 0;
    touchActive = false;
}

void loop()
{
    if (millis() - timeLast > 10)
    {
        if (mode == 0)
        {
            if (x < 50)
            {
                Mouse.move(1, 1);
            }
            else
            {
                Mouse.move(-1, -1);
            }
        }
        else if (mode == 1)
        {
            if (touchActive == false)
            {
                touchActive = true;
                TouchscreenUSB.begin();
            }
            TouchscreenUSB.press(0, 1000 + x * 30, 1000 + y * 30);
        }

        x++; y++;

        if (x > 100)
        {
            x = 0; y = 0;
            if (mode == 0)
            {
                mode = 1;
            }
            else if (mode == 1)
            {
                if (touchActive == true)
                {
                    touchActive = false;
                    TouchscreenUSB.release(0);
                    TouchscreenUSB.end();
                }
                mode = 0;
            }
        }

        timeLast = millis();
    }
}

Variant 1: mouse commented out
Expected behaviour: press finger and move it to the bottom right, release finger, repeat
Actual behauvior: all fine
https://media.giphy.com/media/Klc3qw3nkNuuaRbEDx/giphy.gif

Variant 2: touchscreenusb commented out
Expected behaviour: move mouse bottom right, then top left, repeat
Actual behauvior: all fine
https://media.giphy.com/media/SecXkxTChaaNL4xsSS/giphy.gif

Variant 3: nothing commented out
Expected behaviour: Alternate between the finger movement and mouse movement, repeat
Actual behauvior: finger movement happens once, mouse movement doesn't work (on the next finger movement it once moves the mouse a little bit, but then doesn't move the finger and also doesn't release it)
https://media.giphy.com/media/rcD93dDigq3f8s1b82/giphy.gif

Variant 4: only touchscreenusb.RELEASE uncommented
Expected behaviour: Alternate between the finger movement and mouse movement, repeat
Actual behauvior: finger movement happens once, then mouse movement works but finger doesn't get moved again
https://media.giphy.com/media/9EK3SwVkjajihpryVj/giphy.gif


This is exactly the same problem I have on my above mentioned project. How can I fix this? The Teensy is set to be Keyboard + Mouse + Touchscreen, frequency 24 Mhz (but using it at 600 for example doesn't change anything).
 
Last edited:
Back
Top