GamePad add your own controllers/classes
For some GamePad models, classe have been written already.
For other models, you will have to make your own map of
which button uses which ID number or 'cookie'.
(
GamePad.startHID(0); // read all USB devices
// post everything the connected HIDs know about themselves:
HIDDeviceService.devices.do({arg dev;
"".postln;
[dev.manufacturer, dev.product, dev.vendorID, dev.productID, dev.locID].postln;
dev.elements.do({arg ele;
" ".post; [ele.type, ele.usage, ele.cookie, ele.min, ele.max].postln;
});
});
)
e.g. for a (Chinese) DragonRise Joystick, the vendorID is 121,
and following the posted element descriptions, the maps are something like:
[ DragonRise Inc. , Generic USB Joystick , 121, 6, 990904320 ]
[ Button Input, Button #1, 4, 0, 1 ]
[ Button Input, Button #2, 5, 0, 1 ]
[ Button Input, Button #3, 6, 0, 1 ]
[ Button Input, Button #4, 7, 0, 1 ]
[ Button Input, Button #5, 8, 0, 1 ]
[ Button Input, Button #6, 9, 0, 1 ]
[ Button Input, Button #7, 10, 0, 1 ]
[ Button Input, Button #8, 11, 0, 1 ]
[ Button Input, Button #9, 12, 0, 1 ]
[ Button Input, Button #10, 13, 0, 1 ]
[ Button Input, Button #11, 14, 0, 1 ]
[ Button Input, Button #12, 15, 0, 1 ]
[ Button Input, Page: 0xff00, Usage: 0x1, 16, 0, 1 ]
[ Miscellaneous Input, X-Axis, 17, 0, 255 ]
[ Miscellaneous Input, Y-Axis, 18, 0, 255 ]
[ Miscellaneous Input, Z-Axis, 19, 0, 255 ]
[ Miscellaneous Input, Z-Axis, 20, 0, 255 ]
[ Miscellaneous Input, Z-Rotation, 21, 0, 255 ]
[ Miscellaneous Input, Hatswitch, 22, 0, 7 ]
(
GamePad.cookieMaps[121] = TwoWayIdentityDictionary[
\bt1 -> 4, // 4 buttons, righthand; up is 1, pressed is 0.
\bt2 -> 5,
\bt3 -> 6,
\bt4 -> 7,
\lfTop -> 10, // 4 fire buttons, up 1, down 0
\lfBot -> 8,
\rfTop -> 11,
\rfBot -> 9,
\midL -> 12, // middle shift buttons
\midR -> 13,
\lHat -> 14, // hat switches on joysticks
\rHat -> 15,
\joyLX -> 19, // joystick left x-axis (horizontal) left is 255, right 0!
\joyLY -> 18, // joy left y-axis, up is 255.
\joyRX -> 20, // joystick right x-axis (horizontal) left is 255, right 0!
\joyRY -> 21, // joy right x-axis, up is 255.
\compass -> 22 // west is 1, south is 3, east is 5, north is 7, center is -8
];
// put in normalizing functions for the joysticks and the compass:
GamePad.normMaps[121] =
( joyLX: { |val| 255 - val / 255 },
joyLY: { |val| val / 255 },
joyRX: { |val| 255 - val / 255 },
joyRY: { |val| val / 255 },
compass: { |val| (1: 0, 3: 1, 5: 2, 7: 3, -8: -1)[val] }
);
// you must store the maps in the locIDs also, or do
GamePad.startHID;
/*
GamePad.cookieMaps[990904320] = GamePad.cookieMaps[121];
GamePad.normMaps[990904320] = GamePad.normMaps[121];
*/
)
GamePad.stop;