from geometry_msgs.msg import Twist
from evdev import AbsInfo, UInput, ecodes as e

class DeviceWriter:
    def __init__(self):
        # most values were taken from running
        # InputDevice('/dev/input/event$N').capabilities()
        vendor=1133
        product = 50726
        version = 273
        bustype = 3
        common_abs = AbsInfo(value=0, min=0, max=32767, fuzz=0, flat=0,
                             resolution=0)
        tracking_abs = AbsInfo(value=0, min=0, max=65535, fuzz=0, flat=0,
                               resolution=0)
        slot_abs = AbsInfo(value=0, min=0, max=9, fuzz=0, flat=0, resolution=0)
        spacenav_events = {
            1L: [256L, 257L],
            2L: [0L, 1L, 2L, 3L, 4L, 5L],
            # the abs values were stolen from the previous hardcoding in
            # evdev_teleport, for some reason device.capabilities() did not
            # show any abs values...
            3L: [(e.ABS_X, common_abs),
                 (e.ABS_Y, common_abs),
                 (e.ABS_MT_POSITION_X, common_abs),
                 (e.ABS_MT_POSITION_Y, common_abs),
                 (e.ABS_MT_TRACKING_ID, tracking_abs),
                 (e.ABS_MT_SLOT, slot_abs)
                ],
            4L: [4L],
            17L: [8L]
        }
        self.ui = UInput(spacenav_events, vendor=vendor, product=product,
                         version=version, bustype=bustype)

    def make_event(self, data):
        # write some event to self.ui based off of the twist data
        pass


@@ -68,18 +68,42 @@
 ut, 
-ecodes as 
+InputEvent, ecodes as e%0Aimport tim
 e%0A%0Ac
@@ -1535,10 +1535,1017 @@
     
-pass%0A
+_time = time.time()%0A        stime = int(_time)%0A        utime = int((float(_time) - stime) * 10 ** 6)%0A        # linear and angular might need to be switched here...%0A        x = InputEvent(stime, utime, e.EV_REL, e.REL_X, translate(data.linear.x))%0A        y = InputEvent(stime, utime, e.EV_REL, e.REL_Y, translate(data.linear.y))%0A        z = InputEvent(stime, utime, e.EV_REL, e.REL_Z, translate(data.linear.z))%0A        ax = InputEvent(stime, utime, e.EV_REL, e.REL_RX, translate(data.angular.x))%0A        ay = InputEvent(stime, utime, e.EV_REL, e.REL_RY, translate(data.angular.y))%0A        az = InputEvent(stime, utime, e.EV_REL, e.REL_RZ, translate(data.angular.z))%0A        # write all events%0A        self.ui.write_event(x)%0A        self.ui.write_event(y)%0A        self.ui.write_event(z)%0A        self.ui.write_event(ax)%0A        self.ui.write_event(ay)%0A        self.ui.write_event(az)%0A        # syn to alert input subsystem%0A        self.ui.syn()%0A%0A    def translate(n):%0A        return n # TODO find the translation...
 %0A

implement subscriber callback for writing to the virtual device