Reading data from a USB Gamepad with USB-Host mode.
Fork of Nucleo_Ex04_USBPAD by
main.cpp@2:7c1379b29ce6, 2016-04-28 (annotated)
- Committer:
- jose_23991
- Date:
- Thu Apr 28 21:17:29 2016 +0000
- Revision:
- 2:7c1379b29ce6
- Parent:
- 1:94e011434208
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jose_23991 | 1:94e011434208 | 1 | // Pins connections: 5V-Vbus | GND-GND | Data+-PA_12 | Data--PA_11 |
jose_23991 | 2:7c1379b29ce6 | 2 | // Cannot establish connection with full speed devices, why??? |
jose_23991 | 1:94e011434208 | 3 | |
beaglescout007 | 0:b5f79b4f741d | 4 | #include "mbed.h" |
beaglescout007 | 0:b5f79b4f741d | 5 | #include "USBHostGamepad.h" |
beaglescout007 | 0:b5f79b4f741d | 6 | |
beaglescout007 | 0:b5f79b4f741d | 7 | USBHostGamepad *pad; |
beaglescout007 | 0:b5f79b4f741d | 8 | |
jose_23991 | 1:94e011434208 | 9 | Serial serial(SERIAL_TX, SERIAL_RX); |
jose_23991 | 1:94e011434208 | 10 | |
beaglescout007 | 0:b5f79b4f741d | 11 | // LED |
jose_23991 | 1:94e011434208 | 12 | DigitalOut led(LED1, 0); // Create the LED object and setup OFF |
beaglescout007 | 0:b5f79b4f741d | 13 | |
beaglescout007 | 0:b5f79b4f741d | 14 | int main() |
beaglescout007 | 0:b5f79b4f741d | 15 | { |
jose_23991 | 1:94e011434208 | 16 | // USB Gamepad Initialize |
beaglescout007 | 0:b5f79b4f741d | 17 | pad = new USBHostGamepad(); |
beaglescout007 | 0:b5f79b4f741d | 18 | if (!pad->connect()) { |
jose_23991 | 1:94e011434208 | 19 | serial.printf("USB Connection failed\r\n"); |
beaglescout007 | 0:b5f79b4f741d | 20 | while(1); |
beaglescout007 | 0:b5f79b4f741d | 21 | } |
jose_23991 | 1:94e011434208 | 22 | else |
jose_23991 | 1:94e011434208 | 23 | { |
jose_23991 | 1:94e011434208 | 24 | led = 1; |
jose_23991 | 1:94e011434208 | 25 | serial.printf("USB Connection stablished\r\n"); |
jose_23991 | 1:94e011434208 | 26 | } |
beaglescout007 | 0:b5f79b4f741d | 27 | |
beaglescout007 | 0:b5f79b4f741d | 28 | while(1) |
beaglescout007 | 0:b5f79b4f741d | 29 | { |
beaglescout007 | 0:b5f79b4f741d | 30 | USBHost::poll(); |
beaglescout007 | 0:b5f79b4f741d | 31 | |
jose_23991 | 1:94e011434208 | 32 | serial.printf("%02x %02x %02x %02x %02x %02x %02x %02x\r\n", pad->report[0],pad->report[1],pad->report[2],pad->report[3],pad->report[4],pad->report[5],pad->report[6],pad->report[7]); |
beaglescout007 | 0:b5f79b4f741d | 33 | wait_ms(16); |
beaglescout007 | 0:b5f79b4f741d | 34 | } |
beaglescout007 | 0:b5f79b4f741d | 35 | } |