keypad shield

Dependencies:   mbed TextLCD

Committer:
duchonic
Date:
Thu Jul 25 06:53:04 2019 +0000
Revision:
1:643faa48282f
Parent:
0:6eeb987cb865
Child:
2:c1f316e932bc
body

Who changed what in which revision?

UserRevisionLine numberNew contents of line
duchonic 0:6eeb987cb865 1 #include "mbed.h"
duchonic 0:6eeb987cb865 2 #include "USBHostMouse.h"
duchonic 0:6eeb987cb865 3
duchonic 0:6eeb987cb865 4 DigitalOut led1(LED1);
duchonic 0:6eeb987cb865 5
duchonic 0:6eeb987cb865 6 void onMouseEvent(uint8_t buttons, int8_t x, int8_t y, int8_t z)
duchonic 0:6eeb987cb865 7 {
duchonic 0:6eeb987cb865 8 printf("Buttons: %d, x: %d, y: %d, z: %d\r\n", buttons, x, y, z);
duchonic 0:6eeb987cb865 9 }
duchonic 0:6eeb987cb865 10
duchonic 0:6eeb987cb865 11 void mouse_task(void const *)
duchonic 0:6eeb987cb865 12 {
duchonic 0:6eeb987cb865 13 USBHostMouse mouse;
duchonic 0:6eeb987cb865 14
duchonic 0:6eeb987cb865 15 printf("Mouse started\r\n");
duchonic 0:6eeb987cb865 16
duchonic 0:6eeb987cb865 17 while(1) {
duchonic 0:6eeb987cb865 18
duchonic 0:6eeb987cb865 19 // Try to connect a USB mouse
duchonic 0:6eeb987cb865 20 while(!mouse.connect()) {
duchonic 0:6eeb987cb865 21 Thread::wait(500);
duchonic 0:6eeb987cb865 22 }
duchonic 0:6eeb987cb865 23
duchonic 0:6eeb987cb865 24 // When connected, attach handler called on mouse event
duchonic 0:6eeb987cb865 25 mouse.attachEvent(onMouseEvent);
duchonic 0:6eeb987cb865 26
duchonic 0:6eeb987cb865 27 // Wait until the mouse is disconnected
duchonic 0:6eeb987cb865 28 while(mouse.connected()) {
duchonic 0:6eeb987cb865 29 Thread::wait(500);
duchonic 0:6eeb987cb865 30 }
duchonic 0:6eeb987cb865 31
duchonic 0:6eeb987cb865 32 printf("Mouse disconnected\r\n");
duchonic 0:6eeb987cb865 33 }
duchonic 0:6eeb987cb865 34 }
duchonic 0:6eeb987cb865 35
duchonic 0:6eeb987cb865 36 int main()
duchonic 0:6eeb987cb865 37 {
duchonic 0:6eeb987cb865 38 Thread mouseTask(mouse_task, NULL, osPriorityNormal, 1024* 4);
duchonic 0:6eeb987cb865 39 while(1) {
duchonic 0:6eeb987cb865 40 led1 = !led1;
duchonic 0:6eeb987cb865 41 Thread::wait(500);
duchonic 0:6eeb987cb865 42 }
duchonic 0:6eeb987cb865 43 }