diff --git a/features/unsupported/tests/usb/host/mouse/main.cpp b/features/unsupported/tests/usb/host/mouse/main.cpp new file mode 100644 index 0000000000..0954ead3d6 --- /dev/null +++ b/features/unsupported/tests/usb/host/mouse/main.cpp @@ -0,0 +1,34 @@ +#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); + } +} diff --git a/tools/tests.py b/tools/tests.py index 17ccd2f0dc..037ceea50f 100644 --- a/tools/tests.py +++ b/tools/tests.py @@ -1025,7 +1025,11 @@ TESTS = [ "source_dir": join(TEST_DIR, "usb", "host", "mass_storage"), "dependencies": [MBED_LIBRARIES, USB_HOST_LIBRARIES, FAT_FS, RTOS], }, - + { + "id": "USB_11", "description": "mouse", + "source_dir": join(TEST_DIR, "usb", "host", "mouse"), + "dependencies": [MBED_LIBRARIES, USB_HOST_LIBRARIES, RTOS], + }, # CMSIS DSP { "id": "CMSIS_DSP_1", "description": "FIR",