Skip to content

Commit

Permalink
Fix wheel detection once and for a few weeks (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lawstorant authored Oct 12, 2024
1 parent 8794308 commit f0e483e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 22 deletions.
14 changes: 7 additions & 7 deletions boxflat/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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]:
Expand Down
6 changes: 6 additions & 0 deletions boxflat/moza_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 8 additions & 11 deletions boxflat/panels/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions boxflat/serial_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def stop(self):
def write_bytes(self, message: bytes):
if message is None:
return

self._write_queue.put(message)


Expand All @@ -44,7 +43,6 @@ def _notification_handler(self):
response = self._read_queue.get(timeout=0.5)
except:
continue

self._dispatch(response)


Expand Down
2 changes: 1 addition & 1 deletion boxflat/widgets/new_color_picker_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
3 changes: 3 additions & 0 deletions data/serial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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?
# ===========================================
Expand Down
2 changes: 1 addition & 1 deletion data/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.19.6
v1.19.7
13 changes: 13 additions & 0 deletions io.github.lawstorant.boxflat.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@
<update_contact>[email protected]</update_contact>

<releases>
<release version="v1.19.7" date="2024-10-12">
<description>
<p>
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)
</p>
<p>
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.
</p>
</description>
</release>
<release version="v1.19.6" date="2024-10-07">
<description>
<p>Visual update</p>
Expand Down

0 comments on commit f0e483e

Please sign in to comment.