예제 #1
0
    def init_device_helper(self):
        print("EventHelper.init_device_helper")
        try:
            self.process = FSUAEDeviceHelper.start_with_args(
                ["--events"], stdout=subprocess.PIPE)
        except Exception:
            print("exception while listing joysticks and devices")
            traceback.print_exc()
            return

        atexit.register(self.kill_device_helper_on_exit)
        self.start()
예제 #2
0
    def init_device_helper(self):
        print("EventHelper.init_device_helper")
        try:
            self.process = FSUAEDeviceHelper.start_with_args(
                ["--events"], stdout=subprocess.PIPE
            )
        except Exception:
            print("exception while listing joysticks and devices")
            traceback.print_exc()
            return

        atexit.register(self.kill_device_helper_on_exit)
        self.start()
def event_thread(device_name, window_ref):
    process = FSUAEDeviceHelper.start_with_args(
        [device_name], stdout=subprocess.PIPE
    )

    # while not self.stopped and \
    while not Application.instance().stopping():
        # print("stopping?", Application.instance().stopping())
        window = window_ref()
        if window is None:
            print("window was None")
            break

        line = process.stdout.readline()
        line = line.decode("UTF-8", errors="replace")
        line = line.strip()
        parts = line.split(" ")
        if len(parts) < 2:
            continue
        type_ = parts[1]
        states = parts[2:]
        update = window.current_state

        if type_ == "buttons":
            for i, state in enumerate(states):
                state = int(state)
                update["button_{0}".format(i)] = state

        elif type_ == "axes":
            for i, state in enumerate(states):
                state = int(state)
                update["axis_" + str(i) + "_pos"] = state > 20000
                update["axis_" + str(i) + "_neg"] = state < -20000

        elif type_ == "hats":
            for i, state in enumerate(states):
                state = int(state)
                update["hat_" + str(i) + "_left"] = state & HAT_LEFT
                update["hat_" + str(i) + "_right"] = state & HAT_RIGHT
                update["hat_" + str(i) + "_up"] = state & HAT_UP
                update["hat_" + str(i) + "_down"] = state & HAT_DOWN

        # make sure references are freed in every loop iteration, so the
        # Window will get refcount 0 when it is closed.
        del update
        del window

    process.kill()
예제 #4
0
    def init_fsuae(self):
        print("[INPUT] EnumerateHelper: Finding connected joysticks")
        try:
            p = FSUAEDeviceHelper.start_with_args(
                ["--list"], stdout=subprocess.PIPE
            )
            joysticks = p.stdout.read()
            p.wait()
        except Exception:
            print("[INPUT] Exception while listing joysticks and devices")
            traceback.print_exc()
            return
        print("[INPUT]", repr(joysticks))
        # If the character conversion fails, replace will ensure that
        # as much as possible succeeds. The joystick in question will
        # not be pre-selectable in the launcher, but the other ones will
        # work at least.
        joysticks = joysticks.decode("UTF-8", "replace")
        joysticks = [x.strip() for x in joysticks.split("\n") if x.strip()]

        # joysticks.append("J: controller xbox 360 for windows")
        # joysticks.append("Buttons: 10 Hats: 1 Axes: 5 Balls: 0")

        device_name_count = {}
        last_joystick = None

        for line in joysticks:
            if line.startswith("#"):
                continue
            elif line.startswith("Buttons:"):
                parts = line.split(" ")
                last_joystick.buttons = int(parts[1])
                last_joystick.hats = int(parts[3])
                last_joystick.axes = int(parts[5])
                last_joystick.balls = int(parts[7])
                continue
            elif line.startswith("SDLName:"):
                value = line.split(" ", 1)[1]
                # Strip quotes
                last_joystick.sdl_name = value[1:-1]
                continue

            device = Device()
            device_type, name = line.split(" ", 1)

            name_count = device_name_count.get((device_type, name), 0) + 1
            device_name_count[(device_type, name)] = name_count
            if name_count > 1:
                name = name + " #" + str(name_count)
            device.id = name
            name = re.sub("[ ]+", " ", name)
            device.name = name
            if device_type == "J:":
                device.type = "joystick"
                last_joystick = device
                self.joystick_devices.append(device)
            elif device_type == "M:":
                device.type = "mouse"
            elif device_type == "K:":
                # works as an emulated joystick...
                # device_type = "joystick"
                device.type = "keyboard"
                self.keyboard_devices.append(device)
            # self.device_types.append(device_type)
            self.devices.append(device)
        for i, device in enumerate(self.joystick_devices):
            device.index = i
        for i, device in enumerate(self.keyboard_devices):
            device.index = i

        self.joystick_like_devices.extend(self.joystick_devices)
        self.joystick_like_devices.extend(self.keyboard_devices)
예제 #5
0
    def init_fsuae(cls):
        print("DeviceManager: finding connected joysticks")
        try:
            p = FSUAEDeviceHelper.start_with_args(
                ["--list"], stdout=subprocess.PIPE)
            joysticks = p.stdout.read()
            p.wait()
        except Exception:
            print("exception while listing joysticks and devices")
            traceback.print_exc()
            return
        print(repr(joysticks))
        # If the character conversion fails, replace will ensure that
        # as much as possible succeeds. The joystick in question will
        # not be pre-selectable in the launcher, but the other ones will
        # work at least.
        joysticks = joysticks.decode("UTF-8", "replace")
        joysticks = [x.strip() for x in joysticks.split("\n") if x.strip()]
        last_joystick = ""
        for line in joysticks:
            if line.startswith("#"):
                continue
            if line.startswith("Buttons:"):
                parts = line.split(" ")
                buttons = int(parts[1])
                hats = int(parts[3])
                axes = int(parts[5])
                balls = int(parts[7])
                guid = parts[9]
                cls.joystick_data[last_joystick] = \
                    buttons, hats, axes, balls, guid

                continue
            device_type, name = line.split(" ", 1)
            # if name.lower() in ["keyboard", "mouse"]:
            #     # these are automatically added
            #     continue
            name_count = cls.device_name_count.get((device_type, name), 0) + 1
            cls.device_name_count[(device_type, name)] = name_count
            if name_count > 1:
                name = name + " #" + str(name_count)
            cls.device_ids.append(name)
            name = re.sub("[ ]+", " ", name)
            cls.device_names.append(name)
            if device_type == "J:":
                device_type = "joystick"
                last_joystick = name
            elif device_type == "M:":
                device_type = "mouse"
            elif device_type == "K:":
                # works as an emulated joystick...
                # device_type = "joystick"
                device_type = "keyboard"
            cls.device_types.append(device_type)

        if "--add-dummy-joystick" in sys.argv:
            cls.device_ids.append("Dummy Joystick")
            cls.device_names.append("Dummy Joystick")
            cls.device_types.append("joystick")
            cls.joystick_data["Dummy Joystick"] = \
                1, 0, 2, 0, "c6c1bc29b0124fe6890757bb09ef006f"
예제 #6
0
    def init_fsuae(self):
        print("[INPUT] EnumerateHelper: Finding connected joysticks")
        try:
            p = FSUAEDeviceHelper.start_with_args(["--list"],
                                                  stdout=subprocess.PIPE)
            joysticks = p.stdout.read()
            p.wait()
        except Exception:
            print("[INPUT] Exception while listing joysticks and devices")
            traceback.print_exc()
            return
        print("[INPUT]", repr(joysticks))
        # If the character conversion fails, replace will ensure that
        # as much as possible succeeds. The joystick in question will
        # not be pre-selectable in the launcher, but the other ones will
        # work at least.
        joysticks = joysticks.decode("UTF-8", "replace")
        joysticks = [x.strip() for x in joysticks.split("\n") if x.strip()]

        # joysticks.append("J: controller xbox 360 for windows")
        # joysticks.append("Buttons: 10 Hats: 1 Axes: 5 Balls: 0")

        device_name_count = {}
        last_joystick = None

        for line in joysticks:
            if line.startswith("#"):
                continue
            elif line.startswith("Buttons:"):
                parts = line.split(" ")
                last_joystick.buttons = int(parts[1])
                last_joystick.hats = int(parts[3])
                last_joystick.axes = int(parts[5])
                last_joystick.balls = int(parts[7])
                continue
            elif line.startswith("SDLName:"):
                value = line.split(" ", 1)[1]
                # Strip quotes
                last_joystick.sdl_name = value[1:-1]
                continue

            device = Device()
            device_type, name = line.split(" ", 1)

            name_count = device_name_count.get((device_type, name), 0) + 1
            device_name_count[(device_type, name)] = name_count
            if name_count > 1:
                name = name + " #" + str(name_count)
            device.id = name
            name = re.sub("[ ]+", " ", name)
            device.name = name
            if device_type == "J:":
                device.type = "joystick"
                last_joystick = device
                self.joystick_devices.append(device)
            elif device_type == "M:":
                device.type = "mouse"
            elif device_type == "K:":
                # works as an emulated joystick...
                # device_type = "joystick"
                device.type = "keyboard"
                self.keyboard_devices.append(device)
            # self.device_types.append(device_type)
            self.devices.append(device)
        for i, device in enumerate(self.joystick_devices):
            device.index = i
        for i, device in enumerate(self.keyboard_devices):
            device.index = i

        self.joystick_like_devices.extend(self.joystick_devices)
        self.joystick_like_devices.extend(self.keyboard_devices)
예제 #7
0
    def init_fsuae(cls):
        print("DeviceManager: finding connected joysticks")
        try:
            p = FSUAEDeviceHelper.start_with_args(
                ["--list"], stdout=subprocess.PIPE
            )
            joysticks = p.stdout.read()
            p.wait()
        except Exception:
            print("exception while listing joysticks and devices")
            traceback.print_exc()
            return
        print(repr(joysticks))
        # If the character conversion fails, replace will ensure that
        # as much as possible succeeds. The joystick in question will
        # not be pre-selectable in the launcher, but the other ones will
        # work at least.
        joysticks = joysticks.decode("UTF-8", "replace")
        joysticks = [x.strip() for x in joysticks.split("\n") if x.strip()]
        last_joystick = ""
        for line in joysticks:
            if line.startswith("#"):
                continue
            if line.startswith("Buttons:"):
                parts = line.split(" ")
                buttons = int(parts[1])
                hats = int(parts[3])
                axes = int(parts[5])
                balls = int(parts[7])
                guid = parts[9]
                cls.joystick_data[last_joystick] = (
                    buttons,
                    hats,
                    axes,
                    balls,
                    guid,
                )
                continue
            if line.startswith("SDLName:"):
                value = line.split(" ")[1]
                # Strip quotes
                cls.sdl_names[last_joystick] = value[1:-1]

            device_type, name = line.split(" ", 1)
            # if name.lower() in ["keyboard", "mouse"]:
            #     # these are automatically added
            #     continue
            name_count = cls.device_name_count.get((device_type, name), 0) + 1
            cls.device_name_count[(device_type, name)] = name_count
            if name_count > 1:
                name = name + " #" + str(name_count)
            cls.device_ids.append(name)
            name = re.sub("[ ]+", " ", name)
            cls.device_names.append(name)
            if device_type == "J:":
                device_type = "joystick"
                last_joystick = name
            elif device_type == "M:":
                device_type = "mouse"
            elif device_type == "K:":
                # works as an emulated joystick...
                # device_type = "joystick"
                device_type = "keyboard"
            cls.device_types.append(device_type)

        if "--add-dummy-joystick" in sys.argv:
            cls.device_ids.append("Dummy Joystick")
            cls.device_names.append("Dummy Joystick")
            cls.device_types.append("joystick")
            cls.joystick_data["Dummy Joystick"] = (
                1,
                0,
                2,
                0,
                "c6c1bc29b0124fe6890757bb09ef006f",
            )