Add normalization and calibration for MotionPlus

We now allow the API users to normalize MP input. Automatic recalibration
is also implemented to suppress small data errors.

MP has the problem that it's data is in a range +/- 100 which is really
hard to come-by in applications using it. Therefore, we apply a varying
calibration value and provide an absolute offset as normalization.

(minor coding-style and API fixes)
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
xwiishow: use poll() instead of periodic polling

Instead of polling the FDs periodically, we now use poll() to wait for
events.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
lib: read events from active FDs only

We now save a hint in each epoll_event object so we only read the
devices which were actually reported to be active.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
lib: add hotplug detection and event forwarding

We now provide xwii_iface_watch() which enables or disables hotplug
detection. We do this via udev_monitor and try to detect any kind of
hotplug event.

Whenever a hotplug event occurs, we send an XWII_EVENT_WATCH to the
caller.

Note that this detects generic hotplug events but does not provide any
additional information to the caller. As hotplug events are supposed to
be rare and only provide limited information, we require a caller to
re-enumerate all interfaces of a device to get more information. Sysfs
makes this pretty simple so there is no need for us to provide additional
hotplug payloads which describe what changed (which wouldn't be possible,
anyway).

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
xwiishow: detect hotplug events

We no longer fail on hotplug events but instead notify the user via a
short message. We also re-read static information to refresh the UI.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
lib: return XWII_EVENT_WATCH on EPIPE

Whenever an FD is closed, we now return XWII_EVENT_WATCH instead of
ENODEV so users can properly react to it in a generic way.

Note that this breaks the semantics of xwii_iface_poll(). However, the
next libxwiimote release will be ABI-incompatible, anyway, so we use
this to fix up this API as well.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
xwiishow: don't check for ENODEV

xwii_iface_poll() no longer returns ENODEV so remove this check.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
lib: reread device-nodes on hotplug events

We need to close all devices that got removed during an hotplug event and
we need to re-read all new interfaces.

If we don't do this, a single extension unplug can cause up to XWII_IF_NUM
hotplug events sent to the caller, which is not what we want.

This also fixes a bug were we didn't correctly read new device-nodes that
were hotplugged but required the caller to recreate the state.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
lib: add xwii_iface_available()

This returns a bitmask of all currently available interfaces.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>