Modification of USB Joystick to work as a Hitbox-like game controller using the F401RE. Works reasonably well under Windows.

Dependencies:   USBDevice mbed

This is a hobby project trying to recreate a Hitbox Controller for fun .

The original code was based off of http://developer.mbed.org/users/wim/notebook/usb-joystick-device/ Slight modifications were made to the USB HID descriptor to up the number of buttons reported to 13.

Currently, this works well under Windows and Linux, but no luck getting it to work with Mac OS X or a PS3 so far.

If anybody has useful information, feel free to contribute. :)

p.s: My thread for hooking up an F401RE board as a USB device is here: http://developer.mbed.org/questions/5364/Cannot-get-the-Nucleo-F401RE-to-work-as-/

p.s.2: Cabling information and <del>pictures</del> will be uploaded in the near future.

p.s.3: 2015-04-20: added support for FRDM-KL25Z board. Due to the better usb functionality, this hitbox now works on Windows, Mac OS X, Linux and PS3 too! (minus the "PS" button...)

Revision:
1:6b3335ac3862
Parent:
0:c8e9c90ca7f4
Child:
2:278b7a590311
--- a/main.cpp	Wed Dec 03 07:54:52 2014 +0000
+++ b/main.cpp	Mon Dec 08 09:13:59 2014 +0000
@@ -19,9 +19,10 @@
 BusIn hatin(PC_0, PC_1, PB_0, PA_4);
 BusIn buttonin(PH_0, PA_15, PB_7, PH_1, PC_3, PC_2, PC_15, PC_14, PA_13, PA_14);
 DigitalIn psbutton(PC_12);
-Ticker heartbeat;
+//Ticker heartbeat;
 
 // Heartbeat monitor
+/*
 void pulse() {
   heartbeatLED = !heartbeatLED;
 }
@@ -33,12 +34,15 @@
 void heartbeat_stop() {
   heartbeat.detach();
 }
-
+*/
 
 int main() {
     hatin.mode(PullUp);
     buttonin.mode(PullUp);
     psbutton.mode(PullUp);
+    heartbeatLED = 0;
+    #define UPDATEINTERVAL 0.002
+    int i = 0;
     int16_t throttle = 0;
     int16_t rudder = 0;    
     int16_t x = 0;
@@ -53,7 +57,7 @@
     int8_t isRight = 0;
     int16_t ps = 0;
     
-    heartbeat_start();
+    //heartbeat_start();
 
     while (1) {
 
@@ -108,9 +112,11 @@
         }
         
         joystick.update(throttle, rudder, x, y, button, hat);
-        
-        
-        wait(0.003);
+        i = (i + 1) % 500 ;
+        if (i == 0){
+              heartbeatLED = !heartbeatLED;                
+        }      
+        wait(UPDATEINTERVAL);
     }
                      
 }
\ No newline at end of file