USBHostMouse Hello World for ST-Nucleo-F446RE

Dependencies:   F401RE-USBHost mbed

Fork of USBHostMouse_HelloWorld by Samuel Mokrani

Committer:
va009039
Date:
Sun May 01 05:05:48 2016 +0000
Revision:
7:26cbee9ef684
Parent:
2:be0aafb2edc2
USBHostMouse for F446RE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:c14069b9487e 1 #include "mbed.h"
samux 0:c14069b9487e 2 #include "USBHostMouse.h"
samux 0:c14069b9487e 3
samux 0:c14069b9487e 4 DigitalOut led(LED1);
samux 0:c14069b9487e 5
samux 0:c14069b9487e 6 void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z) {
samux 0:c14069b9487e 7 printf("buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
samux 0:c14069b9487e 8 }
samux 0:c14069b9487e 9
va009039 7:26cbee9ef684 10 int main() {
samux 0:c14069b9487e 11 USBHostMouse mouse;
va009039 7:26cbee9ef684 12 // connect a USB mouse
va009039 7:26cbee9ef684 13 if (!mouse.connect()) {
va009039 7:26cbee9ef684 14 error("USB mouse not found.\n");
va009039 7:26cbee9ef684 15 }
va009039 7:26cbee9ef684 16 // when connected, attach handler called on mouse event
va009039 7:26cbee9ef684 17 mouse.attachEvent(onMouseEvent);
va009039 7:26cbee9ef684 18 Timer t;
va009039 7:26cbee9ef684 19 t.reset();
va009039 7:26cbee9ef684 20 t.start();
va009039 7:26cbee9ef684 21 for(;;) {
va009039 7:26cbee9ef684 22 if (t.read_ms() > 500) {
va009039 7:26cbee9ef684 23 led = !led;
va009039 7:26cbee9ef684 24 t.reset();
va009039 7:26cbee9ef684 25 }
va009039 7:26cbee9ef684 26 USBHost::poll();
samux 0:c14069b9487e 27 }
samux 0:c14069b9487e 28 }