yg lim
/
USBHID_HelloWorld
....
Fork of USBHID_HelloWorld by
Diff: main.cpp
- Revision:
- 5:b1d34990a376
- Parent:
- 3:8f52e961548d
- Child:
- 6:3f614fb580cd
--- a/main.cpp Mon Nov 14 11:43:09 2011 +0000 +++ b/main.cpp Wed Nov 30 11:10:44 2011 +0000 @@ -1,21 +1,36 @@ #include "mbed.h" #include "USBHID.h" -//We declare a USBHID device -USBHID hid; +//We declare a USBHID device. By default input and output reports are 64 bytes long. +USBHID hid(8, 8); + +Serial pc(USBTX, USBRX); //This report will contain data to be sent HID_REPORT send_report; +HID_REPORT recv_report; + +DigitalOut l1(LED1); int main(void) { - //Fill the report - for(int i = 0; i < 64; i++) - send_report.data[i] = i; - send_report.length = 64; - + send_report.length = 8; + while (1) { + + //Fill the report + for (int i = 0; i < send_report.length; i++) + send_report.data[i] = rand() & 0xff; + //Send the report hid.send(&send_report); - wait(0.1); + + //try to read a msg + if(hid.readNB(&recv_report)) { + l1 = !l1; + for(int i = 1; i < recv_report.length; i++) { + pc.printf("%d ", recv_report.data[i]); + } + pc.printf("\r\n"); + } } } \ No newline at end of file