Samuel Mokrani / Mbed 2 deprecated USBHID_TestCase

Dependencies:   USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBHID.h"
00003  
00004 //We declare a USBHID device. Input out output reports have a length of 8 bytes
00005 USBHID hid(8, 8);
00006  
00007 //This report will contain data to be sent
00008 HID_REPORT send_report;
00009 HID_REPORT recv_report;
00010  
00011 Serial pc(USBTX, USBRX);
00012  
00013 int main(void) {
00014     send_report.length = 8;
00015  
00016     while (1) {
00017         //Fill the report
00018         for (int i = 0; i < send_report.length; i++) {
00019             send_report.data[i] = rand() & 0xff;
00020         }
00021             
00022         //Send the report
00023         hid.send(&send_report);
00024         
00025         //try to read a msg
00026         if(hid.readNB(&recv_report)) {
00027             pc.printf("recv: ");
00028             for(int i = 0; i < recv_report.length; i++) {
00029                 pc.printf("%d ", recv_report.data[i]);
00030             }
00031             pc.printf("\r\n");
00032         }
00033         
00034         wait(0.1);
00035     }
00036 }