OpenROV/openrov-software — pull request #255 by codewithpassion (2014-07-10 14:14:36+00:00)
Title: Feature/253 centralised input controller

## TL;DR
To simplify the wiring of keyboard and gamepad and to lay the base for a user configurable keyboard/gamepad mapping, this CR introduces a input controller.

## A few things to note:
* introduction of namespaces (so far used only in the input controller system plugin) to prevent possible name clashes. see the utilities.js
* Creation of a 'system-plugins' structure for components that are central to the software but need to be loaded prior to plugins. The same mechanisms as loading plugins are used for the system plugins.
* There are no global variables for the gamepad and keyboard anymore
* if the same keynboard or gamepad mapping is registered again, the first one is overriden.
* It's possible to register keycombinations for the keyboard and, to some extent, for the gamepad (used for the heads-up-menu that will be added in a subsequent PR)

## How to register controls
Registration of controls is done through a emitted event:

this.cockpit.emit('inputController.register',
{
name: "example.keyBoardMapping",
description: "Example for keymapping.",
defaults: { keyboard: 'alt+0', gamepad: 'X' },
down: function() { console.log('0 down'); },
up: function() { console.log('0 up'); }
});

This registers a mapping for the keyboard (keycombination alt+0) and a gamepad mapping button X.

__The 'register' function can accept a single object or a object array!__

For more examples, see the RovPilot.js file.

## Unregistering
For the Tankcontrol we needed a way to override and unregister (aka reapply old bindings) commands.

To override a given command, simply register a new command.
To unregister use:

rov.cockpit.emit('inputController.unregister', ['example.keyBoardMapping', 'example.keyBoardMapping2']);

__The 'unregister' function can accept a single string or a string array!__

After the unregistration, the InputController will reapply all other bindings automatically.