Joystick library for leo/due

for awhile i had been running a modified arduino core. it was modified to use my joystick descriptor since there was no way to do it in a stand alone library. the only catch was i had to port my changes to each new version. until i updated to 1.6.7. after freaking out all morning i realized it was for the better.

so i looked at the way the updated mouse and keyboard and realized i could spin my own library now. i really didnt have to change my code much, my descriptor went into its own block of progmem. my class was moved to its own header, and a few lines of code later my joystick descriptor was happily pushing axes hats and buttons.

i got it to work on the leo initially, and i was curious if it would work on my due. the code compiled but at first it didnt work, after including HID.h i found that the due works with my library too.

so i uploaded it all to github. it supports 8 16 bit axes, 2 8-way hats, and 32 buttons. im thinking about what i can do to make it more flexible to support other axis resolutions, more buttons, etc. but for now i hope you all find it useful.

Thanks for sharing, that is very nice. The libraries were changed to allow other USB devices/descriptors. You make it look as if it is easy :wink: That is the new pluggable features you are using ?

yea i was looking at the existing mouse and keyboard libraries and realized there are really just a few calls to get it to work. you create an object with

static HIDSubDescriptor node(_hidReportDescriptorJoystick, sizeof(_hidReportDescriptorJoystick));

where _hidReportDescriptorJoystick is just a chunk of progmem with your descriptor. then you register it

HID().AppendDescriptor(&node);

then to push the data its just

HID().SendReport(3,data,sizeof(data));

the descriptor defines the data structure you need to push, and its size. if you read down the descriptor while looking at the data array in Joystick_::sendState you can kind of see how the descriptor defines the structure.

im not quite sure what the 3 is for. its just what i ported over from the old code i was using (i believe its an id value from inside the descriptor but im not sure).

Tutorial : PluggableUSB and PluggableHID howto · arduino/Arduino Wiki · GitHub

SendReport is here : https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/libraries/HID/src/HID.cpp
The number '3' is the 'id'.

USB_Send is here : https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/USBCore.cpp

I think the id selects the report collection. If for example an a keyboard and mouse is used, one is collection 1 and the other is 2. The number of interfaces is set with PluggableUSBModule(). I assume that there are more interfaces possible per report collection. I don't understand if there is a maximum of report collections and how endPoint is used with that.

Hi There,

Am trying to work out how to do something specific, which would involve an if else statement but cannot seem to get it to work.

What im looking for is to have a 3 position switch on-off-on and to have it as such that if either of the ok switches are off the 3rd button comes on.

Such that if ((button 1 = 0) or (button 2 = 0)) then button 3 = 1 else button 3 = 0.

It is so I can assign a button to the off position if you know what i mean. I just dont know how to code it using your descriptors.

Help appreciated.

Nozzles