예제 #1
0
 def __enter__(self):
     self.joystick = SixAxis(dead_zone=self.dead_zone, hot_zone=self.hot_zone)
     self.joystick.connect()
     if self.bind_defaults:
         self.joystick.register_button_handler(self.joystick.reset_axis_calibration, SixAxis.BUTTON_START)
         self.joystick.register_button_handler(self.joystick.set_axis_centres, SixAxis.BUTTON_SELECT)
     return self.joystick
예제 #2
0
class SixAxisResource:
    """
    Resource class which will automatically connect and disconnect to and from a joystick, creating a new SixAxis
    object and passing it to the 'with' clause. Also binds a handler to the START button which resets the axis
    calibration, and to the SELECT button which centres the analogue sticks on the current position.
    """

    def __init__(self, bind_defaults=False, dead_zone=0.05, hot_zone=0.0):
        """
        Resource class, produces a :class:`triangula.input.SixAxis` for use in a 'with' binding.

        :param float dead_zone:
            See SixAxis class documentation
        :param float hot_zone:
            See SixAxis class documentation
        :param bind_defaults:
            Defaults to False, if True will automatically bind two actions to the START and SELECT buttons to
            reset the axis calibration and to set the axis centres respectively.
        """
        self.bind_defaults = bind_defaults
        self.dead_zone = dead_zone
        self.hot_zone = hot_zone

    def __enter__(self):
        self.joystick = SixAxis(dead_zone=self.dead_zone, hot_zone=self.hot_zone)
        self.joystick.connect()
        if self.bind_defaults:
            self.joystick.register_button_handler(self.joystick.reset_axis_calibration, SixAxis.BUTTON_START)
            self.joystick.register_button_handler(self.joystick.set_axis_centres, SixAxis.BUTTON_SELECT)
        return self.joystick

    def __exit__(self, exc_type, exc_value, traceback):
        self.joystick.disconnect()
예제 #3
0
파일: input.py 프로젝트: BaseBot/triangula
class SixAxisResource:
    """
    Resource class which will automatically connect and disconnect to and from a joystick, creating a new SixAxis
    object and passing it to the 'with' clause. Also binds a handler to the START button which resets the axis
    calibration, and to the SELECT button which centres the analogue sticks on the current position.
    """

    def __init__(self, bind_defaults=False, dead_zone=0.05, hot_zone=0.0):
        """
        Resource class, produces a :class:`triangula.input.SixAxis` for use in a 'with' binding.

        :param float dead_zone:
            See SixAxis class documentation
        :param float hot_zone:
            See SixAxis class documentation
        :param bind_defaults:
            Defaults to False, if True will automatically bind two actions to the START and SELECT buttons to
            reset the axis calibration and to set the axis centres respectively.
        """
        self.bind_defaults = bind_defaults
        self.dead_zone = dead_zone
        self.hot_zone = hot_zone

    def __enter__(self):
        self.joystick = SixAxis(dead_zone=self.dead_zone, hot_zone=self.hot_zone)
        self.joystick.connect()
        if self.bind_defaults:
            self.joystick.register_button_handler(self.joystick.reset_axis_calibration, SixAxis.BUTTON_START)
            self.joystick.register_button_handler(self.joystick.set_axis_centres, SixAxis.BUTTON_SELECT)
        return self.joystick

    def __exit__(self, exc_type, exc_value, traceback):
        self.joystick.disconnect()
예제 #4
0
파일: input.py 프로젝트: BaseBot/triangula
 def __enter__(self):
     self.joystick = SixAxis(dead_zone=self.dead_zone, hot_zone=self.hot_zone)
     self.joystick.connect()
     if self.bind_defaults:
         self.joystick.register_button_handler(self.joystick.reset_axis_calibration, SixAxis.BUTTON_START)
         self.joystick.register_button_handler(self.joystick.set_axis_centres, SixAxis.BUTTON_SELECT)
     return self.joystick
예제 #5
0
            :param new_value: the raw value from the joystick hardware
            :internal:
            """
            self.value = new_value
            if new_value > self.max:
                self.max = new_value
            elif new_value < self.min:
                self.min = new_value


if __name__ == '__main__':
    from input import SixAxis
    import time

    controller = SixAxis(dead_zone=0.0, hot_zone=0.0, connect=True)


    def handler(button):
        print 'Button! {}'.format(button)


    controller.register_button_handler(handler, SixAxis.BUTTON_CIRCLE)
    controller.register_button_handler(controller.reset_axis_calibration, SixAxis.BUTTON_START)
    controller.register_button_handler(controller.set_axis_centres, SixAxis.BUTTON_SELECT)


    current_milli_time = lambda: int(round(time.time() * 1000))
    last_time = current_milli_time()
    while 1:
        #controller.handle_events()
예제 #6
0
파일: input.py 프로젝트: BaseBot/triangula
            :param new_value: the raw value from the joystick hardware
            :internal:
            """
            self.value = new_value
            if new_value > self.max:
                self.max = new_value
            elif new_value < self.min:
                self.min = new_value


if __name__ == '__main__':
    from input import SixAxis
    import time

    controller = SixAxis(dead_zone=0.0, hot_zone=0.0)


    def handler(button):
        print 'Button! {}'.format(button)


    controller.register_button_handler(handler, SixAxis.BUTTON_CIRCLE)
    controller.register_button_handler(controller.reset_axis_calibration, SixAxis.BUTTON_START)
    controller.register_button_handler(controller.set_axis_centres, SixAxis.BUTTON_SELECT)

    current_milli_time = lambda: int(round(time.time() * 1000))
    last_time = current_milli_time()
    while 1:
        controller.handle_events()
        now = current_milli_time()