Esempio n. 1
0
    def __init__(self, bdaddr=None, led=0, rpt_mode=0):
        if bdaddr is None:
            self.__wiimote = cwiid.Wiimote()
        else:
            self.__wiimote = cwiid.Wiimote(bdaddr)
        self.mesg = (0, [(None, None)])
        def set_mesg(mesg, timestamp):
            self.mesg = timestamp, mesg
        self.__wiimote.mesg_callback = set_mesg
        self.__wiimote.enable(cwiid.FLAG_MESG_IFC)

        self.led = led
        self.rpt_mode = rpt_mode

        self._pattern_rumble = PatternRumbler(self)
        # FIXME See threads.PatternRumbler
        #self._pattern_rumble.start()
        self._callback = Callback(self)
        self._callback.start()

        atexit.register(self.close)
Esempio n. 2
0
    def __init__(self, bdaddr=None, led=0, rpt_mode=0, tracker_cls=trackers.PositionTracker):
        if bdaddr is None:
            self.__wiimote = cwiid.Wiimote()
        else:
            self.__wiimote = cwiid.Wiimote(bdaddr)
        self.mesg = (0, [(None, None)])
        def set_mesg(mesg, timestamp):
            self.mesg = timestamp, mesg
        self.__wiimote.mesg_callback = set_mesg
        self.__wiimote.enable(cwiid.FLAG_MESG_IFC)

        self.led = led
        self.rpt_mode = rpt_mode
        self.tracker = tracker_cls(self)

        self._pattern_rumble = PatternRumbler(self)
        # FIXME See threads.PatternRumbler
        #self._pattern_rumble.start()
        self._callback = Callback(self)
        self._callback.start()

        self._new_position = False

        atexit.register(self.terminate)
Esempio n. 3
0
class Wiimote(object):
    IR_X_MAX = cwiid.IR_X_MAX
    IR_Y_MAX = cwiid.IR_Y_MAX
    @property
    def w(self):
        return self.__wiimote

    def __init__(self, bdaddr=None, led=0, rpt_mode=0, tracker_cls=trackers.PositionTracker):
        if bdaddr is None:
            self.__wiimote = cwiid.Wiimote()
        else:
            self.__wiimote = cwiid.Wiimote(bdaddr)
        self.mesg = (0, [(None, None)])
        def set_mesg(mesg, timestamp):
            self.mesg = timestamp, mesg
        self.__wiimote.mesg_callback = set_mesg
        self.__wiimote.enable(cwiid.FLAG_MESG_IFC)

        self.led = led
        self.rpt_mode = rpt_mode
        self.tracker = tracker_cls(self)

        self._pattern_rumble = PatternRumbler(self)
        # FIXME See threads.PatternRumbler
        #self._pattern_rumble.start()
        self._callback = Callback(self)
        self._callback.start()

        self._new_position = False

        atexit.register(self.terminate)

    def terminate(self):
        self._callback.terminate()
        self._pattern_rumble.terminate()
        self.__wiimote.close()

    def register(self, fn):
        """
        Register callback function.
        """
        return self._callback.register(fn)

    def unregister(self, fn_id):
        """
        Unregister callback function.
        """
        return self._callback.unregister(fn_id)

    def notify_callbacks(self):
        return self._callback.notify(mesg)

    def rumble_pattern(self, pattern, repeat=False):
        return self._pattern_rumble.set_pattern(pattern, repeat)

    def rumble_stop(self):
        return self._pattern_rumble.stop()

    @toolkit.dummy
    def generate_feedback(self, severity):
        if severity:
            self.rumble = True
        else:
            self.rumble = False

    def is_calibrated(self):
        return self.tracker.is_calibrated()

    @toolkit.untested
    def get_status(self):
        state = None
        try:
            state = self.__wiimote.state
        except ValueError, e:
            if e.message == "Wiimote is closed":
                return DISCONNECTED
            raise
        try:
            if self._new_position:
                return NEW_POSITION
        except KeyError, e:
            if e != 'ir_src':
                raise
Esempio n. 4
0
class Wiimote(object):
    @property
    def w(self):
        return self.__wiimote

    def __init__(self, bdaddr=None, led=0, rpt_mode=0):
        if bdaddr is None:
            self.__wiimote = cwiid.Wiimote()
        else:
            self.__wiimote = cwiid.Wiimote(bdaddr)
        self.mesg = (0, [(None, None)])
        def set_mesg(mesg, timestamp):
            self.mesg = timestamp, mesg
        self.__wiimote.mesg_callback = set_mesg
        self.__wiimote.enable(cwiid.FLAG_MESG_IFC)

        self.led = led
        self.rpt_mode = rpt_mode

        self._pattern_rumble = PatternRumbler(self)
        # FIXME See threads.PatternRumbler
        #self._pattern_rumble.start()
        self._callback = Callback(self)
        self._callback.start()

        atexit.register(self.close)

    def close(self):
        self._callback.terminate()
        self._pattern_rumble.terminate()
        self.__wiimote.close()

    def register(self, fn):
        return self._callback.register(fn)

    def unregister(self, fn_id):
        return self._callback.unregister(fn_id)

    def notify_callbacks(self):
        return self._callback.notify(mesg)

    def rumble_pattern(self, pattern, repeat=False):
        return self._pattern_rumble.set_pattern(pattern, repeat)

    def rumble_stop(self):
        return self._pattern_rumble.stop()

    @property
    def rumble(self):
        return self._rumble
    
    @rumble.setter
    def rumble(self, value):
        self._rumble = value
        self.__wiimote.rumble = self._rumble

    @property
    def state(self):
        return self.__wiimote.state

    @property
    def led(self):
        return self._led

    @led.setter
    def led(self, value):
        self._led = value
        self.__wiimote.led = self._led

    @property
    def rpt_mode(self):
        return self._rpt_mode

    @rpt_mode.setter
    def rpt_mode(self, value):
        self._rpt_mode = value
        self.__wiimote.rpt_mode = self._rpt_mode