I was finally able to find the time to implement a "standard" USB HID GamePad as an Espruino module ( js only for now ) :D
Currently, the triggers are treated as digital buttons, but I'll soon take the time to update the code to support analog triggers ;)
So, YES, Espruino's should now be able to play CoD & GTA ;p .. and make some perfects on guitar hero hardcore ? -> better: make it count & let's do an Espruino-adaptive-controller !!! ;P ( seriously, I'm on it ;) )
=> enjoy :)
basic usage is as simple as Gordon's keyboard & mouse modules:
var gamepad = require('USBGamepad');
// debug easily using http://html5gamepad.com/ ;p
gamepad.sendGamepadState(0b1111111111111111, 127, 127, 127, 127);
gamepad.sendGamepadState(0b1111111111111111, -127, -127, -127, -127);
I plan to:
maybe add possibility of using analog values for buttons as well ?
or so only for the "big" triggers ?
I also consider writing a little wrapper to make it easier to work with if needed:
// press & release buttons
gamepad.press(<btnConst>); // press one
gamepad.press([<btnConst>, <joyConst>, ..]); // press many
gamepad.<btnConst>.press(); // press one
gamepad.<joyConst>.press(); // same for joysticks buttons
gamepad.<btnConst>.release // release one
gamepad.release(<btnConst>, <joyConst>, ..]); // release many
// joysticks only: range [-127..127]
gamepad.<joyConst>.move(<xValue>, <yValue>);
gamepad.<joyConst>.moveX(<value>);
gamepad.<joyConst>.moveY(<value>);
// triggers only: range [0..255]
gamepad.<trigConst>.press(<value>); // if analog, 'll range [0..255]
// global
gamepad.set({ <const>:<value>, .. });
// update
gamepad.sendState(); // or '.update()' ?
Advises are welcome to the above draf of api :)
I also wonder if it'd be somewhat useful to retain the last gamepad state before any further update, as well as the timestamp & the timestamp diff with previous one ? ..
The module should also work to send stuff to an RN42* ( or an HC-05 with its HID firmware ) or an Espruino board based on bluetooth
just add 0xFD, 0x06 & 0x01 before the stuff to be sent ;)
I'll also try to get 2 gamepads & adding the possibility to pass a number of those to the module before it calls 'E.setUSBHID()' after a little rest ( digging through the USB HID docs can make one's eyes burn .. )
On a near subject ( & sorry if I repeat myself ), I have a wip lib aimed to generate hid report descriptors ( currently just easing the mapping between constants & their values ): it's not much but it 'd have been very helpful to write the above ;/ ( I'll add the constants digged to it as soon as can do ;p )
Last but not least, if anyone has suggestions on the 'hid way' to get output descriptors working on Espruino, it 'd be daaaaaaaamn cool :) ( the goal is to be able to send stuff from host to Espruino - and for the moment, the 'stuff' is not quite defined ^^ )
ps: while at it & if enough time to do so, I have some idea of a feedback mouse ;)
+
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi there !
I was finally able to find the time to implement a "standard" USB HID GamePad as an Espruino module ( js only for now ) :D
Currently, the triggers are treated as digital buttons, but I'll soon take the time to update the code to support analog triggers ;)
So, YES, Espruino's should now be able to play CoD & GTA ;p .. and make some perfects on guitar hero hardcore ? -> better: make it count & let's do an Espruino-adaptive-controller !!! ;P ( seriously, I'm on it ;) )
=> enjoy :)
basic usage is as simple as Gordon's keyboard & mouse modules:
I plan to:
I also consider writing a little wrapper to make it easier to work with if needed:
Advises are welcome to the above draf of api :)
I also wonder if it'd be somewhat useful to retain the last gamepad state before any further update, as well as the timestamp & the timestamp diff with previous one ? ..
The module should also work to send stuff to an RN42* ( or an HC-05 with its HID firmware ) or an Espruino board based on bluetooth
I'll also try to get 2 gamepads & adding the possibility to pass a number of those to the module before it calls 'E.setUSBHID()' after a little rest ( digging through the USB HID docs can make one's eyes burn .. )
On a near subject ( & sorry if I repeat myself ), I have a wip lib aimed to generate hid report descriptors ( currently just easing the mapping between constants & their values ): it's not much but it 'd have been very helpful to write the above ;/ ( I'll add the constants digged to it as soon as can do ;p )
Every contribution is welcome ;)
https://github.com/stephaneAG/usbHidDescriptors
Last but not least, if anyone has suggestions on the 'hid way' to get output descriptors working on Espruino, it 'd be daaaaaaaamn cool :) ( the goal is to be able to send stuff from host to Espruino - and for the moment, the 'stuff' is not quite defined ^^ )
ps: while at it & if enough time to do so, I have some idea of a feedback mouse ;)
+
2 Attachments