diff --git a/boxflat/connection_manager.py b/boxflat/connection_manager.py index 9109034..ba4de57 100644 --- a/boxflat/connection_manager.py +++ b/boxflat/connection_manager.py @@ -183,7 +183,7 @@ def _polling_thread(self): continue # print("Polling data: " + command) self._get_setting(command) - time.sleep(0.005) + time.sleep(0.002) def _device_polling(self): @@ -224,7 +224,7 @@ def set_write_active(self, *args): self._connected_thread.start() - def _get_device_id(self, device_type: str) -> int: + def get_device_id(self, device_type: str) -> int: id = int(self._serial_data["device-ids"][device_type]) if device_type != "base" and device_type in self._serial_devices: id = int(self._serial_data["device-ids"]["main"]) @@ -269,7 +269,7 @@ def _handle_command_v2(self, command_data: MozaCommand, rw: int) -> bytes: def _handle_setting(self, value, command_name: str, device_name: str, rw: int) -> bool: command = MozaCommand() command.set_data_from_name(command_name, self._serial_data["commands"], device_name) - command.device_id = self._get_device_id(command.device_type) + command.device_id = self.get_device_id(command.device_type) if command.device_id == -1: print("Invalid Device ID") @@ -343,15 +343,15 @@ def _get_setting(self, command_name: str, exclusive=False): def cycle_wheel_id(self) -> int: with self._devices_lock: - wid = self._serial_data["device-ids"]["wheel"] - 1 + wid = self._serial_data["device-ids"]["wheel"] - 2 - if wid == self._serial_data["device-ids"]["base"] + 1: + if wid < self._serial_data["device-ids"]["base"]: wid = self._serial_data["device-ids"]["pedals"] - 2 self._serial_data["device-ids"]["wheel"] = wid - # print(f"Cycling wheel id. New id: {wid}") - return wid + # print(f"Cycling wheel id. New id: {wid}") + return wid def get_command_data(self) -> dict[str, dict]: diff --git a/boxflat/moza_command.py b/boxflat/moza_command.py index a0aa4ad..9032566 100644 --- a/boxflat/moza_command.py +++ b/boxflat/moza_command.py @@ -58,6 +58,12 @@ def value_from_response(values: bytes, device_name: str, commands_data: dict, de if device_name == "base": device_name = device_ids[device_id] + # Some ES wheels report on main/base IDs for some reason. + # TODO: rewrite the db file and index commands by their rw + # group first. It's the only stable metric. + if 63 <= group <= 66: + device_name = "wheel" + for name, values in commands_data[device_name].items(): if group != values["read"]: continue diff --git a/boxflat/panels/wheel.py b/boxflat/panels/wheel.py index f5c2799..f6de13c 100644 --- a/boxflat/panels/wheel.py +++ b/boxflat/panels/wheel.py @@ -43,24 +43,21 @@ def __init__(self, button_callback, connection_manager: MozaConnectionManager, h super().__init__("Wheel", button_callback, connection_manager, hid_handler) self._cm.subscribe_connected("wheel-indicator-mode", self.active) + self.set_banner_title(f"Device disconnected. Trying wheel id: ...") def active(self, value: int): - new_id = None + super().active(value) if value == -1: new_id = self._cm.cycle_wheel_id() + self.set_banner_title(f"Device disconnected. Trying wheel id: {new_id}...") - if new_id == 21 and self._stick_row: - self._stick_row.set_active(0) - self._combination_row.set_present(0) - elif self._stick_row: - self._stick_row.set_active(1) - self._combination_row.set_present(1) - - super().active(value) + wheel_id = self._cm.get_device_id("wheel") + if self._stick_row is not None: + self._stick_row.set_active(wheel_id == 23) - if value == -1: - self.set_banner_title(f"Device disconnected. Trying wheel id: {new_id}...") + if self._combination_row is not None: + self._combination_row.set_active(wheel_id == 23) def prepare_ui(self): diff --git a/boxflat/serial_handler.py b/boxflat/serial_handler.py index 0840f12..c8dd412 100644 --- a/boxflat/serial_handler.py +++ b/boxflat/serial_handler.py @@ -34,7 +34,6 @@ def stop(self): def write_bytes(self, message: bytes): if message is None: return - self._write_queue.put(message) @@ -44,7 +43,6 @@ def _notification_handler(self): response = self._read_queue.get(timeout=0.5) except: continue - self._dispatch(response) diff --git a/boxflat/widgets/new_color_picker_row.py b/boxflat/widgets/new_color_picker_row.py index 68799be..c70f8b3 100644 --- a/boxflat/widgets/new_color_picker_row.py +++ b/boxflat/widgets/new_color_picker_row.py @@ -67,7 +67,7 @@ def __init__(self, title="", subtitle="", blinking=False): def get_value(self, index: int) -> list[int]: - if index >= 0 and index < len(self._colors): + if 0 <= index < len(self._colors): rgba = self._colors[index].get_rgba() return extract_rgb(rgba) return [] diff --git a/data/serial.yml b/data/serial.yml index 37dd423..fc81841 100644 --- a/data/serial.yml +++ b/data/serial.yml @@ -19,12 +19,15 @@ device-ids: ids-to-names: 18: main 19: base + 21: wheel 23: wheel 25: pedals 26: hpattern 26: sequential 27: handbrake +# TODO: save device group ranges for better command discovery + # TODO: EEPROM commands # Maybe that's how we update FW? # =========================================== diff --git a/data/version b/data/version index 7730a80..1dcc64f 100644 --- a/data/version +++ b/data/version @@ -1 +1 @@ -v1.19.6 +v1.19.7 diff --git a/io.github.lawstorant.boxflat.metainfo.xml b/io.github.lawstorant.boxflat.metainfo.xml index 328391b..d57f4d8 100644 --- a/io.github.lawstorant.boxflat.metainfo.xml +++ b/io.github.lawstorant.boxflat.metainfo.xml @@ -97,6 +97,19 @@ forest10pl@gmail.com + + +

+ This update should fix even more woes with the ES wheel detection. + Kudos to GitHub user TimSchmock who helped massively wit hthe debugging + as I do not own the ES wheel myself (or a few other Moza devices) +

+

+ Huge thanks to GitHub user pseudex for supporting this project! + I'm getting closer to being able to actually buy Moza Universal hub and support it. +

+
+

Visual update