USBHost Mouse example.

Dependencies:   USBHost mbed

main.cpp

Committer:
bcostm
Date:
20 months ago
Revision:
0:4456c264d862

File content as of revision 0:4456c264d862:

#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;

    printf("Mouse started\n");

    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);
        }

        printf("Mouse disconnected\n");
    }
}

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