9 years, 6 months ago.

Problem with USBHostMouse -> mouse disconnect after thread::wait finished

Hello all,

Can anyone help me with this problem? I trying to connect a mouse in a mbed lpc1768 using the example program in the handbook page (https://developer.mbed.org/handbook/USBHostMouse). I did the hardware connections as described. The mouse connected to the mbed and I received some data but after the thread::wait (500) the mouse disconnect and never connect again.

Any thoughs why this happens?

Code equals to handbook example

#include "mbed.h"
#include "USBHostMouse.h"

DigitalOut led(LED1);

void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) {
    printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
}

void mouse_task(void const *) {
    
    USBHostMouse mouse;
    
    while(1) {
        // try to connect a USB mouse
        while(!mouse.connect())

            Thread::wait(500);

    
        // when connected, attach handler called on mouse event
        mouse.attachEvent(onMouseEvent);
        
        // wait until the mouse is disconnected
        while(mouse.connected())

            Thread::wait(500);

    }
}

int main() {
    Thread mouseTask(mouse_task, NULL, osPriorityNormal, 256 * 4);
    while(1) {
        led=!led;
        Thread::wait(500);
    }
}

And the output:

[USB_INFO: /src/USBHost/USBHost/USBHost.cpp:158]New device connected: 1000299c [hub: 0 - port: 1]
[USB_INFO: /src/USBHost/USBHostHID/USBHostMouse.cpp:67]New Mouse device: VID:0101 PID:0007 [dev: 1000299c - intf: 0]
buttons: 0, x: -128, y: 94, z: -5
buttons: 0, x: 54, y: -1, z: -3
buttons: 0, x: -128, y: 31, z: -1
buttons: 0, x: -66, y: -81, z: -1
buttons: 0, x: -34, y: -17, z: -1
buttons: 0, x: -16, y: -1, z: -1
buttons: 0, x: -7, y: 15, z: 0
buttons: 0, x: -22, y: 15, z: 0
Be the first to answer this question.