USBHostGamepad library usage example
Dependencies: USBHostGamepad mbed
main.cpp
00001 #include "mbed.h" 00002 #include "USBHostGamepad.h" 00003 00004 DigitalOut led(LED3); 00005 00006 void onGamepadEvent(uint8_t x, uint8_t y, uint8_t z, uint8_t rz, uint16_t buttons) { 00007 printf("x: %02X, y: %02X, z: %02X, rz: %02X, buttons: %04X\r\n", 00008 x, y, z, rz, buttons); 00009 } 00010 00011 void gamepad_task() { 00012 USBHostGamepad gamepad; 00013 00014 while(1) { 00015 // try to connect a USB Gamepad 00016 while(!gamepad.connect()) 00017 Thread::wait(500); 00018 00019 // when connected, attach handler called on Gamepad event 00020 gamepad.attachEvent(onGamepadEvent); 00021 00022 // wait until the Gamepad is disconnected 00023 while(gamepad.connected()) 00024 Thread::wait(500); 00025 } 00026 } 00027 00028 int main() { 00029 Thread gamepadTask(osPriorityNormal, 1024 * 4); 00030 gamepadTask.start(gamepad_task); 00031 00032 printf("MBED USB GAMEPAD\n\r"); 00033 00034 while(1) { 00035 led=!led; 00036 Thread::wait(500); 00037 } 00038 }
Generated on Wed Jul 20 2022 12:08:41 by
1.7.2
Abdelhak Bougouffa