Skip to content

Commit 815194a

Browse files
committed
USBHOST : add mouse test
1 parent 72dae26 commit 815194a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "mbed.h"
2+
#include "USBHostMouse.h"
3+
4+
DigitalOut led(LED1);
5+
6+
void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) {
7+
printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
8+
}
9+
10+
void mouse_task(void const *) {
11+
12+
USBHostMouse mouse;
13+
14+
while(1) {
15+
// try to connect a USB mouse
16+
while(!mouse.connect())
17+
Thread::wait(500);
18+
19+
// when connected, attach handler called on mouse event
20+
mouse.attachEvent(onMouseEvent);
21+
22+
// wait until the mouse is disconnected
23+
while(mouse.connected())
24+
Thread::wait(500);
25+
}
26+
}
27+
28+
int main() {
29+
Thread mouseTask(mouse_task, NULL, osPriorityNormal, 256 * 4);
30+
while(1) {
31+
led=!led;
32+
Thread::wait(500);
33+
}
34+
}

tools/tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,11 @@
10251025
"source_dir": join(TEST_DIR, "usb", "host", "mass_storage"),
10261026
"dependencies": [MBED_LIBRARIES, USB_HOST_LIBRARIES, FAT_FS, RTOS],
10271027
},
1028-
1028+
{
1029+
"id": "USB_11", "description": "mouse",
1030+
"source_dir": join(TEST_DIR, "usb", "host", "mouse"),
1031+
"dependencies": [MBED_LIBRARIES, USB_HOST_LIBRARIES, RTOS],
1032+
},
10291033
# CMSIS DSP
10301034
{
10311035
"id": "CMSIS_DSP_1", "description": "FIR",

0 commit comments

Comments
 (0)