Samuel Mokrani
/
USBHID_HelloWorld
USBHID Hello World
Diff: main.cpp
- Revision:
- 1:0216a6726c1c
- Parent:
- 0:30b74cf0e645
- Child:
- 2:d07a799c6926
--- a/main.cpp Wed Nov 02 17:18:57 2011 +0000 +++ b/main.cpp Thu Nov 03 12:26:16 2011 +0000 @@ -1,18 +1,35 @@ #include "mbed.h" #include "USBHID.h" -USBHID hid; -HID_REPORT recv; +//We declare a USBHID device: it can send 1 byte and receive 1 byte +USBHID hid(1, 1); + +//Two reports where will be stored values to send and received +HID_REPORT recv_report; +HID_REPORT send_report; + +//Bus of leds BusOut leds(LED1,LED2,LED3,LED4); -/* - * In a loop, this program listens a HID_REPORT over USB. - * The first byte of this report represents the state of BusOut - * I use pywinusb to do that on windows (32bits). - */ +//Bus of buttons +BusInOut buttons(p21, p22, p23, p24); + int main(void) { + uint8_t p_bus = 0; + send_report.length = 1; + while (1) { - hid.read(&recv); - leds = recv.data[0]; + //If a data is received, update led bus + if (hid.readNB(&recv_report)) { + leds = recv_report.data[0]; + } + + //if the bus of buttons has changed, send a report + if (buttons.read() != p_bus) { + p_bus = buttons.read(); + send_report.data[0] = p_bus; + hid.send(&send_report); + } + wait(0.01); } }