From f740d65c2cb98f629959afa8d2dbbaac353d2b33 Mon Sep 17 00:00:00 2001 From: Gonzalo Adrio Date: Wed, 4 Nov 2026 23:14:19 +0100 Subject: [PATCH] feat: support RS Handbrake, RS H-Shifter and Racing Adapter via USB or base - Detect Logitech Racing Adapter attached to RS50 / G PRO wheel base via HID++ page 0x8120 (GAMING_ATTACHMENTS) confirmed by 0x0005 device name, report comma-separated active accessories in sysfs wheel_accessory, and enable Desktop mode slot routing (0x8120 + 0x1BC0) when either RS H-Shifter or Racing Adapter is connected to the base. - Add evdev discovery and decoding for standalone RS Shifter & Handbrake (046d:c275/046d:c278) and Logitech Racing Adapter (046d:c273). - Dynamically show/hide the Shifter & Handbrake card sections in logi-wheel-gui based on connected accessories (via USB or wheel base): - Sequential Shift Up / Shift Down badges only appear and respond when RS Shifter & Handbrake is connected (so bare wheel paddles do not trigger them). - Separate 7+R (RS H-Shifter) and 6+R (Racing Adapter / Driving Force Shifter) H-gate diagrams, collapsing to a single diagram when both are plugged into the wheel base simultaneously. - Pass the selected device into Reader::start to avoid multi-wheel 1 Hz flicker, and preserve press-driven accessory connection state. - Decode DB9 Driving Force Shifter Reverse through the wheel base on 0x2c4 (BTN_TRIGGER_HAPPY5). - Document standalone and base-connected accessories, DB9 6+R shifter buttons (0x120..0x126 standalone, 0x12c..0x2c4 via base), and base pedal axes in docs/BUTTON_MAPPING.md and docs/SYSFS_API.md. Closes #144 Signed-off-by: Gonzalo Adrio --- docs/BUTTON_MAPPING.md | 67 ++- docs/SYSFS_API.md | 12 +- mainline/hid-logitech-hidpp.c | 167 +++++-- .../crates/logi-wheel-core/src/device.rs | 12 + .../crates/logi-wheel-core/src/evtest.rs | 109 ++++- .../crates/logi-wheel-gui/src/main.rs | 29 +- .../crates/logi-wheel-gui/src/testio.rs | 405 +++++++++++++++- .../crates/logi-wheel-gui/ui/app.slint | 12 + .../crates/logi-wheel-gui/ui/info_page.slint | 457 +++++++++++++----- 9 files changed, 1068 insertions(+), 202 deletions(-) diff --git a/docs/BUTTON_MAPPING.md b/docs/BUTTON_MAPPING.md index 43ff7f6..01b1207 100644 --- a/docs/BUTTON_MAPPING.md +++ b/docs/BUTTON_MAPPING.md @@ -52,7 +52,7 @@ buttons - diagram callout "D". ### Connected to the Wheel Base -When connected to the wheel base accessory port (sub-device 03), gears 1 to 7 and Reverse report on DirectInput button indices 12 to 19 (hardware-verified 2026-10-29). Index 20 is unused. +When connected to a wheel base accessory port, gears 1 to 7 and Reverse report on DirectInput button indices 12 to 19 (hardware-verified 2026-10-29). Index 20 is used by the Racing Adapter DB9 Reverse. | Index | Button / Gear | evdev Code | Wire bitmask (Report 0x08) | |---|---|---|---| @@ -64,7 +64,7 @@ When connected to the wheel base accessory port (sub-device 03), gears 1 to 7 an | 17 | RS H-Shifter: Gear 6 | `0x2c1` (`BTN_TRIGGER_HAPPY2`) | Byte 2 bit 5 (`0x20`) | | 18 | RS H-Shifter: Gear 7 | `0x2c2` (`BTN_TRIGGER_HAPPY3`) | Byte 2 bit 6 (`0x40`) | | 19 | RS H-Shifter: Reverse | `0x2c3` (`BTN_TRIGGER_HAPPY4`) | Byte 3 bit 0 (`0x01`) | -| 20 | Unused | `0x2c4` (`BTN_TRIGGER_HAPPY5`) | - | +| 20 | Racing Adapter DB9 Reverse | `0x2c4` (`BTN_TRIGGER_HAPPY5`) | Byte 3 bit 1 (`0x02`) | ### Connected Directly to PC via USB @@ -72,6 +72,69 @@ When connected directly to the PC via USB (`046d:c26b Logitech RS H-Shifter`), i - Buttons 0 to 6 (`0x120`..`0x126`): 1st through 7th gear - Button 7 (`0x127`): Reverse (R) +## RS Shifter & Handbrake (046d:c278) + +Dual-mode sim accessory featuring a physical toggle switch between progressive analog handbrake mode and dual-direction sequential shifter mode. + +### Connected to the Wheel Base + +When connected to a direct-drive wheel base accessory port (RS50 / G PRO): +- **Handbrake Mode**: Reports as the wheel base's handbrake axis (progressive 0–100%). +- **Sequential Shifter Mode**: Shift Up (pull back) and Shift Down (push forward) are routed directly by base firmware to the wheel paddle button codes: + - Shift Up: Right Paddle (`0x124`, `BTN_TOP2`) + - Shift Down: Left Paddle (`0x125`, `BTN_PINKIE`) + +### Connected Directly to PC via USB + +When connected directly to the PC via USB-C (`046d:c278 Logitech RS Shifter & Handbrake`), it enumerates as a standalone joystick: +- **Handbrake Mode**: Progressive 10-bit analog axis: + - `ABS_Z`: Handbrake lever travel (`0` relaxed .. `1023` fully pulled). +- **Sequential Shifter Mode**: Two digital momentary buttons: + - Button 0 (`0x120`, `BTN_TRIGGER`): Shift Up (pull back) + - Button 1 (`0x121`, `BTN_THUMB`): Shift Down (push forward) + +## Logitech G Racing Adapter (046d:c273) + +USB adapter connecting legacy G29/G920/G923 3-pedal sets and 6+R DB9 Driving Force shifters. + +### Pedals (12-bit Analog Axes) + +Connected via the adapter's dedicated pedal port: +| Pedal | evdev Axis | Raw Range | Notes | +|-------|------------|-----------|-------| +| Throttle | `ABS_Y` | `0`..`4095` | Full travel 12-bit progressive | +| Brake | `ABS_Z` | `0`..`4095` | Full travel 12-bit progressive | +| Clutch | `ABS_RX` | `0`..`4095` | Full travel 12-bit progressive | + +### DB9 Driving Force Shifter (Digital Buttons) + +Connected via the adapter's DB9 shifter port when the adapter is plugged directly into the PC via USB: +| Gear | evdev Code | DirectInput Button | +|------|------------|--------------------| +| 1st Gear | `0x120` (`BTN_TRIGGER`) | Button 0 | +| 2nd Gear | `0x121` (`BTN_THUMB`) | Button 1 | +| 3rd Gear | `0x122` (`BTN_THUMB2`) | Button 2 | +| 4th Gear | `0x123` (`BTN_TOP`) | Button 3 | +| 5th Gear | `0x124` (`BTN_TOP2`) | Button 4 | +| 6th Gear | `0x125` (`BTN_PINKIE`) | Button 5 | +| Reverse (Push-down + 6th) | `0x126` (`BTN_BASE`) | Button 6 | + +### Connected to the Wheel Base + +When the Racing Adapter is plugged into an RS50 / G PRO wheel base USB port (`wheel_accessory` reports `Racing Adapter`): +- **Pedals**: Routed through the wheel base's standard pedal axes (`ABS_RX` Throttle, `ABS_RY` Brake, `ABS_RZ` Clutch). +- **DB9 Driving Force Shifter**: Routed through the wheel base's standard H-shifter button slots (`0x12c`..`0x12f` for 1st–4th, `0x2c0`..`0x2c1` for 5th–6th, and `0x2c4` (`BTN_TRIGGER_HAPPY5`) for Reverse, hardware-verified 2026-11-09). In Desktop mode (`profile 0`), the kernel driver automatically enables `0x8120` (`GAMING_ATTACHMENTS`) slot routing and `0x1BC0` (`SYNC`) when the Racing Adapter sub-device is detected. + +## Pedals Connected to Wheel Base + +When pedals (and optional RS Shifter & Handbrake) are connected to a wheel base's ports, the evdev axis assignment depends on the wheel model (matching `pedal_axes` in `logi_wheel_core::evtest` and `HIDPP_DD_PEDAL_BASE_AXIS` in `hid-logitech-hidpp.c`): +| Axis | RS50 / G PRO | G923 (PlayStation `0xc266`/`0xc267`) | G923 (Xbox `0xc26e`) | +|------|--------------|--------------------------------------|----------------------| +| Throttle | `ABS_RX` | `ABS_Z` | `ABS_Y` | +| Brake | `ABS_RY` | `ABS_RZ` | `ABS_Z` | +| Clutch | `ABS_RZ` | `ABS_Y` | `ABS_RZ` | +| Handbrake | `ABS_Z` | - | - | + ## G923 The G923's own button layout, hardware-captured 2026-07-27 by a guided live diff --git a/docs/SYSFS_API.md b/docs/SYSFS_API.md index e2ee9ee..6c58f6e 100644 --- a/docs/SYSFS_API.md +++ b/docs/SYSFS_API.md @@ -990,13 +990,15 @@ Include this output in bug reports - firmware-dependent behaviour ### wheel_accessory **Access**: Read-only -**Values**: accessory device name, or `none` +**Values**: comma-separated list of active accessory names (e.g. `RS Shifter & Handbrake, RS H-Shifter, Racing Adapter`), or `none` Presence signal for the base's optional accessories: the **RS Shifter & -Handbrake** and the **RS H-Shifter**, which plug into the base's USB-A -ports. Reports the RS Shifter & Handbrake's own HID++ device name, or -`RS H-Shifter`, or `none` when neither is attached. With both attached it -names the RS Shifter & Handbrake. Unlike the pedal/handbrake attributes +Handbrake**, the **RS H-Shifter**, and the **Logitech Racing Adapter**, which +plug into the base's USB-A ports. Reports the attached accessory's name +(`RS Shifter & Handbrake`, `RS H-Shifter`, or `Racing Adapter`), a +comma-separated list when multiple accessories are attached (e.g. +`RS Shifter & Handbrake, RS H-Shifter` or `RS Shifter & Handbrake, Racing Adapter`), +or `none` when none is attached. Unlike the pedal/handbrake attributes below, this never returns an error: it exists precisely so apps can check for an accessory without inferring presence from another attribute's error code. diff --git a/mainline/hid-logitech-hidpp.c b/mainline/hid-logitech-hidpp.c index 775f2e2..a968455 100644 --- a/mainline/hid-logitech-hidpp.c +++ b/mainline/hid-logitech-hidpp.c @@ -5936,6 +5936,7 @@ struct hidpp_dd_ff_data { u8 idx_shifter_mode; /* Feature index for 0x1B30 DEVICE_MODE on the accessory */ u8 h_shifter_dev_idx; /* HID++ dev index of RS H-Shifter */ u8 idx_h_shifter; /* Feature index for 0x812D RS_H_SHIFTER */ + u8 adapter_dev_idx; /* HID++ dev index of Racing Adapter attached to base */ u8 idx_attachments; /* Feature index for 0x8120 GAMING_ATTACHMENTS */ struct work_struct accessory_rescan_work; /* re-checks accessory presence off the sysfs read path */ unsigned long accessory_rescan_next; /* jiffies before which no further rescan is queued */ @@ -8688,42 +8689,52 @@ static int hidpp_dd_pedal_axis_count(struct hidpp_device *hidpp, u8 dev_idx, } /* - * Read the RS Shifter & Handbrake accessory's own DeviceNameType (0x0005) - * name into ff->accessory_name, once the accessory has been confirmed at - * dev_idx (see hidpp_dd_discover_settings_features). Best-effort: any - * failure leaves accessory_name empty, which wheel_accessory_show reports - * as "none" - the same as a genuinely absent accessory, since without a - * name the sysfs attribute cannot usefully distinguish the two anyway. + * Read a sub-device's own DeviceNameType (0x0005) name into @buf. + * Returns 0 on success, negative errno on error. */ -static void hidpp_dd_query_accessory_name(struct hidpp_dd_ff_data *ff, u8 dev_idx) +static int hidpp_dd_read_device_name(struct hidpp_device *hidpp, u8 dev_idx, + char *buf, size_t buf_size) { - struct hidpp_device *hidpp = ff->hidpp; u8 name_idx, name_length; unsigned int index = 0; int ret; - ff->accessory_name[0] = '\0'; - + buf[0] = '\0'; if (hidpp_root_get_feature_on_device(hidpp, dev_idx, HIDPP_PAGE_GET_DEVICE_NAME_TYPE, &name_idx)) - return; + return -ENOENT; if (hidpp_devicenametype_get_count_on_device(hidpp, dev_idx, name_idx, &name_length)) - return; + return -EIO; - while (index < name_length && index < sizeof(ff->accessory_name) - 1) { + while (index < name_length && index < buf_size - 1) { ret = hidpp_devicenametype_get_device_name_on_device(hidpp, dev_idx, name_idx, index, - ff->accessory_name + index, - sizeof(ff->accessory_name) - 1 - index); + buf + index, + buf_size - 1 - index); if (ret <= 0) { - ff->accessory_name[index] = '\0'; - return; + buf[index] = '\0'; + return -EIO; } index += ret; } - ff->accessory_name[index] = '\0'; + buf[index] = '\0'; + return 0; +} + +/* + * Read the RS Shifter & Handbrake accessory's own DeviceNameType (0x0005) + * name into ff->accessory_name, once the accessory has been confirmed at + * dev_idx (see hidpp_dd_discover_settings_features). Best-effort: any + * failure leaves accessory_name empty, which wheel_accessory_show reports + * as "none" - the same as a genuinely absent accessory, since without a + * name the sysfs attribute cannot usefully distinguish the two anyway. + */ +static void hidpp_dd_query_accessory_name(struct hidpp_dd_ff_data *ff, u8 dev_idx) +{ + hidpp_dd_read_device_name(ff->hidpp, dev_idx, ff->accessory_name, + sizeof(ff->accessory_name)); } /* @@ -8770,12 +8781,24 @@ static bool hidpp_dd_probe_h_shifter(struct hidpp_dd_ff_data *ff, u8 cand) HIDPP_DD_PAGE_RS_H_SHIFTER, &idx)) return false; ff->idx_h_shifter = idx; - if (!ff->accessory_name[0]) - strscpy(ff->accessory_name, "RS H-Shifter", - sizeof(ff->accessory_name)); return true; } +static bool hidpp_dd_probe_adapter(struct hidpp_dd_ff_data *ff, u8 cand) +{ + char name[32]; + u8 idx; + + if (hidpp_root_get_feature_on_device(ff->hidpp, cand, + HIDPP_DD_PAGE_ATTACHMENTS, &idx)) + return false; + + if (hidpp_dd_read_device_name(ff->hidpp, cand, name, sizeof(name))) + return false; + + return !strcmp(name, "Racing Adapter"); +} + /* * Discover HID++ feature indices for the "settings" surface: per-wheel * tuning exposed as wheel_* sysfs attributes, plus profile / mode / @@ -8805,6 +8828,7 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; ff->h_shifter_dev_idx = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_h_shifter = HIDPP_DD_FEATURE_NOT_FOUND; + ff->adapter_dev_idx = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_attachments = HIDPP_DD_FEATURE_NOT_FOUND; ff->accessory_name[0] = '\0'; /* @@ -8997,7 +9021,8 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) if (ff->pedal_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && - ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) + ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + ff->adapter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) break; ret = hidpp_root_get_feature_on_device_timeout(hidpp, cand, @@ -9033,6 +9058,12 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) ff->h_shifter_dev_idx = cand; dd_info(hid, "RS H-Shifter at dev 0x%02x (idx 0x%02x)\n", cand, ff->idx_h_shifter); + continue; + } + if (ff->adapter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_dd_probe_adapter(ff, cand)) { + ff->adapter_dev_idx = cand; + dd_info(hid, "Racing Adapter at dev 0x%02x\n", cand); } } if (ff->pedal_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) @@ -9296,7 +9327,8 @@ static void hidpp_dd_enable_desktop_shifter(struct hidpp_dd_ff_data *ff) u8 params[16]; int ret; - if (ff->h_shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) + if (ff->h_shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND && + ff->adapter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) return; /* 1. Feature 0x8120 GAMING_ATTACHMENTS on base */ @@ -9689,12 +9721,11 @@ static void hidpp_dd_ff_query_settings(struct hidpp_dd_ff_data *ff) /* * Enable accessory slot routing in Desktop mode (profile 0) - * when an RS H-Shifter is present. + * when an RS H-Shifter or Racing Adapter is present. * Must run after LIGHTSYNC initialization so the LED sync * sequence does not clobber attachment routing. */ - if (ff->current_mode == 0 && - ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) + if (ff->current_mode == 0) hidpp_dd_enable_desktop_shifter(ff); } @@ -15164,10 +15195,6 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) ff->idx_shifter_banded = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; ff->accessory_name[0] = '\0'; - /* The attribute keeps naming whatever is still attached. */ - if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) - strscpy(ff->accessory_name, "RS H-Shifter", - sizeof(ff->accessory_name)); dd_info(hid, "RS Shifter & Handbrake removed\n"); } if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && @@ -15177,12 +15204,18 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) /* Same order as above: index first, then the name. */ WRITE_ONCE(ff->h_shifter_dev_idx, HIDPP_DD_FEATURE_NOT_FOUND); ff->idx_h_shifter = HIDPP_DD_FEATURE_NOT_FOUND; - if (!strcmp(ff->accessory_name, "RS H-Shifter")) - ff->accessory_name[0] = '\0'; dd_info(hid, "RS H-Shifter removed\n"); } + if (ff->adapter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_root_get_feature_on_device_timeout(hidpp, ff->adapter_dev_idx, + HIDPP_DD_PAGE_ATTACHMENTS, &idx, + HIDPP_DD_PROBE_TIMEOUT)) { + WRITE_ONCE(ff->adapter_dev_idx, HIDPP_DD_FEATURE_NOT_FOUND); + dd_info(hid, "Racing Adapter removed\n"); + } if (ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && - ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) + ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + ff->adapter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) return; /* @@ -15213,7 +15246,8 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) ff->accessory_scan_cursor = (ff->accessory_scan_cursor + 1) % ARRAY_SIZE(hidpp_dd_pedal_dev_candidates); /* Just confirmed above; nothing new can sit on that port. */ - if (cand == ff->shifter_dev_idx || cand == ff->h_shifter_dev_idx) + if (cand == ff->shifter_dev_idx || cand == ff->h_shifter_dev_idx || + cand == ff->adapter_dev_idx) return; ret = hidpp_root_get_feature_on_device_timeout(hidpp, cand, HIDPP_DD_PAGE_RESPONSE_CURVE, &cand_idx, @@ -15262,21 +15296,29 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) } /* Answers, but is neither the pedals nor the RS Shifter & Handbrake. */ - if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND || - !hidpp_dd_probe_h_shifter(ff, cand)) + if (ff->h_shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_dd_probe_h_shifter(ff, cand)) { + WRITE_ONCE(ff->h_shifter_dev_idx, cand); + dd_info(hid, "RS H-Shifter at dev 0x%02x (idx 0x%02x)\n", + cand, ff->idx_h_shifter); + /* + * Desktop mode only routes the gates once G HUB's enablement + * sequence has been sent (hidpp_dd_enable_desktop_shifter). At + * probe that happens from hidpp_dd_ff_query_settings; a shifter + * that arrives later needs it now. Onboard profiles route the + * gates on their own. + */ + if (ff->current_mode == 0) + hidpp_dd_enable_desktop_shifter(ff); return; - WRITE_ONCE(ff->h_shifter_dev_idx, cand); - dd_info(hid, "RS H-Shifter at dev 0x%02x (idx 0x%02x)\n", - cand, ff->idx_h_shifter); - /* - * Desktop mode only routes the gates once G HUB's enablement - * sequence has been sent (hidpp_dd_enable_desktop_shifter). At - * probe that happens from hidpp_dd_ff_query_settings; a shifter - * that arrives later needs it now. Onboard profiles route the - * gates on their own. - */ - if (ff->current_mode == 0) - hidpp_dd_enable_desktop_shifter(ff); + } + if (ff->adapter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_dd_probe_adapter(ff, cand)) { + WRITE_ONCE(ff->adapter_dev_idx, cand); + dd_info(hid, "Racing Adapter at dev 0x%02x\n", cand); + if (ff->current_mode == 0) + hidpp_dd_enable_desktop_shifter(ff); + } } } @@ -15296,6 +15338,8 @@ static ssize_t wheel_accessory_show(struct device *dev, struct hid_device *hid = to_hid_device(dev); struct hidpp_device *hidpp = hid_get_drvdata(hid); struct hidpp_dd_ff_data *ff; + bool has_shifter, has_h_shifter, has_adapter; + ssize_t len = 0; if (!hidpp) return -ENODEV; @@ -15314,11 +15358,20 @@ static ssize_t wheel_accessory_show(struct device *dev, jiffies + HIDPP_DD_ACCESSORY_RESCAN_INTERVAL); queue_work(ff->wq, &ff->accessory_rescan_work); } - if ((READ_ONCE(ff->shifter_dev_idx) == HIDPP_DD_FEATURE_NOT_FOUND && - READ_ONCE(ff->h_shifter_dev_idx) == HIDPP_DD_FEATURE_NOT_FOUND) || - !ff->accessory_name[0]) + has_shifter = READ_ONCE(ff->shifter_dev_idx) != HIDPP_DD_FEATURE_NOT_FOUND && + ff->accessory_name[0]; + has_h_shifter = READ_ONCE(ff->h_shifter_dev_idx) != HIDPP_DD_FEATURE_NOT_FOUND; + has_adapter = READ_ONCE(ff->adapter_dev_idx) != HIDPP_DD_FEATURE_NOT_FOUND; + if (!has_shifter && !has_h_shifter && !has_adapter) return sysfs_emit(buf, "none\n"); - return sysfs_emit(buf, "%s\n", ff->accessory_name); + if (has_shifter) + len += sysfs_emit_at(buf, len, "%s", ff->accessory_name); + if (has_h_shifter) + len += sysfs_emit_at(buf, len, "%sRS H-Shifter", len ? ", " : ""); + if (has_adapter) + len += sysfs_emit_at(buf, len, "%sRacing Adapter", len ? ", " : ""); + len += sysfs_emit_at(buf, len, "\n"); + return len; } static DEVICE_ATTR(wheel_accessory, 0444, wheel_accessory_show, NULL); @@ -16045,6 +16098,16 @@ static int hidpp_dd_ff_init(struct hidpp_device *hidpp) ff->idx_brakeforce = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_filter = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_response_curve = HIDPP_DD_FEATURE_NOT_FOUND; + ff->idx_pedal_curve = HIDPP_DD_FEATURE_NOT_FOUND; + ff->pedal_dev_idx = HIDPP_DD_FEATURE_NOT_FOUND; + ff->shifter_dev_idx = HIDPP_DD_FEATURE_NOT_FOUND; + ff->idx_shifter_curve = HIDPP_DD_FEATURE_NOT_FOUND; + ff->idx_shifter_banded = HIDPP_DD_FEATURE_NOT_FOUND; + ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; + ff->h_shifter_dev_idx = HIDPP_DD_FEATURE_NOT_FOUND; + ff->idx_h_shifter = HIDPP_DD_FEATURE_NOT_FOUND; + ff->adapter_dev_idx = HIDPP_DD_FEATURE_NOT_FOUND; + ff->idx_attachments = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_brightness = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_lightsync = HIDPP_DD_FEATURE_NOT_FOUND; ff->idx_rgb_config = HIDPP_DD_FEATURE_NOT_FOUND; diff --git a/userspace/logi-wheel/crates/logi-wheel-core/src/device.rs b/userspace/logi-wheel/crates/logi-wheel-core/src/device.rs index f0f0463..a67d9e0 100644 --- a/userspace/logi-wheel/crates/logi-wheel-core/src/device.rs +++ b/userspace/logi-wheel/crates/logi-wheel-core/src/device.rs @@ -822,6 +822,18 @@ impl Device { } } + pub fn accessory_name(&self) -> Option { + if !self.io.exists("wheel_accessory") { + return None; + } + let raw = self.io.read("wheel_accessory").ok()?; + let t = raw.trim(); + if t.is_empty() || t == "none" { + return None; + } + Some(t.to_string()) + } + pub fn accessory_attached(&self) -> Option { if !self.io.exists("wheel_accessory") { return None; diff --git a/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs b/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs index cd52d44..54d09cc 100644 --- a/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs +++ b/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs @@ -680,6 +680,38 @@ pub fn discover_shifter_input() -> Option { scan_shifter_input(Path::new("/sys/class/input")) } +/// Whether `name` looks like a Logitech RS Shifter & Handbrake (`046d:c278`). +pub fn is_handbrake_name(name: &str) -> bool { + let upper = name.to_uppercase(); + upper.contains("RS SHIFTER & HANDBRAKE") +} + +/// Scan `sysfs_input` for `event*` entries matching [`is_handbrake_name`]. +pub fn scan_handbrake_input(sysfs_input: &Path) -> Option { + scan_input_by_name(sysfs_input, is_handbrake_name) +} + +/// Find a standalone USB handbrake's evdev node, or `None` if not connected via USB. +pub fn discover_handbrake_input() -> Option { + scan_handbrake_input(Path::new("/sys/class/input")) +} + +/// Whether `name` looks like a Logitech Racing Adapter (`046d:c273`). +pub fn is_racing_adapter_name(name: &str) -> bool { + let upper = name.to_uppercase(); + upper.contains("RACING ADAPTER") +} + +/// Scan `sysfs_input` for `event*` entries matching [`is_racing_adapter_name`]. +pub fn scan_racing_adapter_input(sysfs_input: &Path) -> Option { + scan_input_by_name(sysfs_input, is_racing_adapter_name) +} + +/// Find a standalone Logitech Racing Adapter's evdev node, or `None` if not connected via USB. +pub fn discover_racing_adapter_input() -> Option { + scan_racing_adapter_input(Path::new("/sys/class/input")) +} + /// Evdev button codes and labels for the Logitech RS H-Shifter when attached /// to a direct-drive base (sub-device 03, hardware-verified 2026-10-29). pub const RS_SHIFTER_WHEEL_BUTTONS: &[(u16, &str)] = &[ @@ -709,7 +741,7 @@ pub fn gear_from_wheel_code(model: WheelModel, code: u16) -> Option { 0x2c0 => Some(5), 0x2c1 => Some(6), 0x2c2 => Some(7), - 0x2c3 => Some(8), // Reverse (R): 0x2c3 (Wheel base wire Byte 3 bit 0 / BTN_TRIGGER_HAPPY4) + 0x2c3 | 0x2c4 => Some(8), // Reverse (R): 0x2c3 (RS H-Shifter) / 0x2c4 (Racing Adapter DB9 Shifter) _ => None, }, _ => None, @@ -732,6 +764,21 @@ pub fn gear_from_standalone_code(code: u16) -> Option { } } +/// Decode a gear index (1..=6, 8 for Reverse) from a Driving Force Shifter +/// connected via the Logitech Racing Adapter (`046d:c273`). +pub fn gear_from_adapter_code(code: u16) -> Option { + match code { + 0x120 => Some(1), + 0x121 => Some(2), + 0x122 => Some(3), + 0x123 => Some(4), + 0x124 => Some(5), + 0x125 => Some(6), + 0x126 => Some(8), // Reverse (R) + _ => None, + } +} + /// Human-readable label for a gear (0 = Neutral "N", 1..7 = "1st".."7th", 8 = "R"). pub fn gear_name(gear: i32) -> &'static str { match gear { @@ -1149,6 +1196,61 @@ mod shifter_tests { } } + #[test] + fn handbrake_name_matching() { + const MATCHES: &[&str] = &[ + "Logitech RS Shifter & Handbrake", + "Logitech G RS Shifter & Handbrake", + ]; + const NON_MATCHES: &[&str] = &[ + "Logitech RS50 Base", + "Logitech RS H-Shifter", + "Generic Gamepad", + ]; + for name in MATCHES { + assert!(is_handbrake_name(name), "expected {name:?} to match"); + } + for name in NON_MATCHES { + assert!(!is_handbrake_name(name), "expected {name:?} not to match"); + } + } + + #[test] + fn racing_adapter_name_matching() { + const MATCHES: &[&str] = &[ + "Logitech Racing Adapter", + "Logitech G Racing Adapter", + ]; + const NON_MATCHES: &[&str] = &[ + "Logitech RS50 Base", + "Logitech RS H-Shifter", + "Generic Gamepad", + ]; + for name in MATCHES { + assert!(is_racing_adapter_name(name), "expected {name:?} to match"); + } + for name in NON_MATCHES { + assert!(!is_racing_adapter_name(name), "expected {name:?} not to match"); + } + } + + #[test] + fn racing_adapter_gear_decoding() { + const CASES: &[(u16, Option)] = &[ + (0x120, Some(1)), + (0x121, Some(2)), + (0x122, Some(3)), + (0x123, Some(4)), + (0x124, Some(5)), + (0x125, Some(6)), + (0x126, Some(8)), // Reverse (R) + (0x127, None), + ]; + for &(code, expected) in CASES { + assert_eq!(gear_from_adapter_code(code), expected, "code 0x{code:03x}"); + } + } + #[test] fn shifter_gear_decoding_from_wheel_base() { const CASES: &[(u16, Option)] = &[ @@ -1159,8 +1261,9 @@ mod shifter_tests { (0x2c0, Some(5)), // Gear 5 (BTN_TRIGGER_HAPPY1) (0x2c1, Some(6)), // Gear 6 (BTN_TRIGGER_HAPPY2) (0x2c2, Some(7)), // Gear 7 (BTN_TRIGGER_HAPPY3) - (0x2c3, Some(8)), // Reverse (BTN_TRIGGER_HAPPY4) - (0x2c4, None), // Unused / padding index + (0x2c3, Some(8)), // Reverse: RS H-Shifter (BTN_TRIGGER_HAPPY4) + (0x2c4, Some(8)), // Reverse: Racing Adapter DB9 Shifter (BTN_TRIGGER_HAPPY5) + (0x2c5, None), // Unused / padding index (0x12b, None), // Wheel rim LSB button (0x120, None), // Wheel rim button A ]; diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs b/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs index ec22b04..80eec4e 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs @@ -927,8 +927,14 @@ fn apply_test_snapshot(app: &App, snap: &testio::Snapshot, model: WheelModel, wh app.set_test_axes(slint::ModelRc::new(slint::VecModel::from(axes))); app.set_test_gear(snap.gear); app.set_test_gear_name(evtest::gear_name(snap.gear).into()); + app.set_test_adapter_gear(snap.adapter_gear); + app.set_test_adapter_gear_name(evtest::gear_name(snap.adapter_gear).into()); app.set_test_shifter_connected(snap.shifter_connected); app.set_test_shifter_mode(snap.shifter_mode.as_str().into()); + app.set_test_seq_shift_up(snap.seq_shift_up); + app.set_test_seq_shift_down(snap.seq_shift_down); + app.set_test_handbrake_connected(snap.handbrake_connected); + app.set_test_adapter_connected(snap.adapter_connected); } /// Stop (and join) the Test page's reader thread, if one is running. @@ -971,16 +977,30 @@ fn start_test_monitor( // `wheel_range`; the G923's classic engine has no `wheel_` prefix // at all, so read whichever of the two this device's own registry // actually has. - let (model, range) = match logi_wheel_core::Device::discover() { - Ok(d) => { + let selected_device = { + let all = logi_wheel_core::Device::discover_all(); + if let Some(ref usb_path) = usb { + all.into_iter().find(|d| { + d.sysfs_key() + .as_deref() + .and_then(logi_wheel_core::device::usb_device_dir) + .as_ref() + == Some(usb_path) + }) + } else { + all.into_iter().next() + } + }; + let (model, range, sysfs_dir) = match selected_device { + Some(ref d) => { let attr = if d.available("wheel_range") { "wheel_range" } else { "range" }; let range = match d.read(attr).ok() { Some(Value::Int(n)) => u32::try_from(n).unwrap_or(900), _ => 900, }; - (d.model(), range) + (d.model(), range, d.sysfs_key()) } - Err(_) => (WheelModel::default(), 900), + None => (WheelModel::default(), 900, None), }; *model_cell.lock().unwrap() = model; let _ = slint::invoke_from_event_loop(move || { @@ -1012,6 +1032,7 @@ fn start_test_monitor( match testio::Reader::start( &wheel.event_path, model, + sysfs_dir, evtest::button_codes_for_name(model, &wheel.name), // The wheel's own pedal layout, from the name its input // node reports (issue #68). diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs index e0ca15a..a362d9e 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs @@ -15,6 +15,7 @@ use std::io::{Read, Write}; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::AsRawFd; +use std::path::Path; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -35,14 +36,22 @@ pub struct Snapshot { pub hat: (i32, i32), pub axes: [i32; 4], pub gear: i32, + pub adapter_gear: i32, pub shifter_connected: bool, pub shifter_mode: String, + pub seq_shift_up: bool, + pub seq_shift_down: bool, + pub handbrake_connected: bool, + pub adapter_connected: bool, + pub base_adapter_connected: bool, } /// How often the reader pushes a fresh [`Snapshot`] at most. const PUSH_INTERVAL: Duration = Duration::from_millis(33); /// The idle sleep between non-blocking read sweeps. const POLL_SLEEP: Duration = Duration::from_millis(5); +/// How often the reader re-checks USB and wheel-base accessory hotplug state. +const HOTPLUG_INTERVAL: Duration = Duration::from_secs(1); /// The Test page's reader thread: owns the wheel's evdev node opened /// read-only and non-blocking, decodes events, and pushes throttled @@ -66,6 +75,152 @@ fn open_standalone_shifter(wheel_path: &str) -> Option { .ok() } +fn open_standalone_handbrake(wheel_path: &str) -> Option { + let s = evtest::discover_handbrake_input()?; + if s.event_path == wheel_path { + return None; + } + std::fs::OpenOptions::new() + .read(true) + .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) + .open(&s.event_path) + .ok() +} + +fn open_standalone_adapter(wheel_path: &str) -> Option { + let s = evtest::discover_racing_adapter_input()?; + if s.event_path == wheel_path { + return None; + } + std::fs::OpenOptions::new() + .read(true) + .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) + .open(&s.event_path) + .ok() +} + +fn probe_base_accessories(sysfs_dir: Option<&Path>) -> (bool, bool, bool) { + let Some(dir) = sysfs_dir else { + return (false, false, false); + }; + let acc_path = dir.join("wheel_accessory"); + let Ok(name) = std::fs::read_to_string(acc_path) else { + return (false, false, false); + }; + let base_hb = name.contains("Handbrake"); + let base_hs = name.contains("RS H-Shifter"); + let base_ad = name.contains("Racing Adapter"); + (base_hb, base_hs, base_ad) +} + +fn read_nonblocking(file: &mut std::fs::File, buf: &mut [u8]) -> Result { + match file.read(buf) { + Ok(0) => Err(()), + Ok(n) => Ok(n), + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => Ok(0), + Err(e) if e.kind() == std::io::ErrorKind::Interrupted => Ok(0), + Err(_) => Err(()), + } +} + +/// Read standalone accessories (shifter, handbrake, adapter) and fold into `snapshot`. +fn poll_standalone_devices( + shifter: &mut Option, + handbrake: &mut Option, + adapter: &mut Option, + snapshot: &mut Snapshot, + right_paddle_idx: Option, + left_paddle_idx: Option, +) -> bool { + let mut changed = false; + if let Some(ref mut s_file) = shifter { + match poll_standalone_shifter(s_file, snapshot) { + Ok(true) => changed = true, + Ok(false) => {} + Err(()) => *shifter = None, + } + } + if let Some(ref mut hb_file) = handbrake { + match poll_standalone_handbrake(hb_file, snapshot, right_paddle_idx, left_paddle_idx) { + Ok(true) => changed = true, + Ok(false) => {} + Err(()) => *handbrake = None, + } + } + if let Some(ref mut ad_file) = adapter { + match poll_standalone_adapter(ad_file, snapshot) { + Ok(true) => changed = true, + Ok(false) => {} + Err(()) => *adapter = None, + } + } + changed +} + +fn refresh_accessories( + wheel_path: &str, + sysfs_dir: Option<&Path>, + shifter: &mut Option, + handbrake: &mut Option, + adapter: &mut Option, + snapshot: &mut Snapshot, +) -> bool { + if shifter.is_none() { + *shifter = open_standalone_shifter(wheel_path); + } + if handbrake.is_none() { + *handbrake = open_standalone_handbrake(wheel_path); + } + if adapter.is_none() { + *adapter = open_standalone_adapter(wheel_path); + } + let (base_hb, base_hs, base_ad) = probe_base_accessories(sysfs_dir); + let s_usb = shifter.is_some(); + let hb_usb = handbrake.is_some(); + let ad_usb = adapter.is_some(); + + let new_handbrake = hb_usb || base_hb; + let new_base_adapter = base_ad && !base_hs; + let new_shifter = s_usb || base_hs || (snapshot.shifter_connected && !snapshot.base_adapter_connected); + let new_adapter = ad_usb || new_base_adapter || (snapshot.adapter_connected && snapshot.base_adapter_connected); + + let new_mode = if s_usb || hb_usb { + "Direct USB".to_string() + } else if base_hs || base_hb || base_ad || snapshot.shifter_connected || snapshot.adapter_connected { + if !snapshot.shifter_mode.is_empty() { + snapshot.shifter_mode.clone() + } else { + "Wheel base".to_string() + } + } else if ad_usb { + "Logitech Racing Adapter".to_string() + } else { + String::new() + }; + + let changed = snapshot.handbrake_connected != new_handbrake + || snapshot.shifter_connected != new_shifter + || snapshot.adapter_connected != new_adapter + || snapshot.base_adapter_connected != new_base_adapter + || snapshot.shifter_mode != new_mode; + snapshot.handbrake_connected = new_handbrake; + snapshot.shifter_connected = new_shifter; + snapshot.adapter_connected = new_adapter; + snapshot.base_adapter_connected = new_base_adapter; + snapshot.shifter_mode = new_mode; + if !new_handbrake { + snapshot.seq_shift_up = false; + snapshot.seq_shift_down = false; + } + if !new_shifter { + snapshot.gear = 0; + } + if !new_adapter { + snapshot.adapter_gear = 0; + } + changed +} + /// Read and fold wheel events from `file` into `snapshot`. /// Returns `Ok(true)` if anything changed, `Ok(false)` if no visible change or would block, /// or `Err(())` if the device was disconnected (EOF or fatal error). @@ -95,6 +250,43 @@ fn poll_wheel_events( } } +fn initial_snapshot( + num_buttons: usize, + standalone_shifter: bool, + standalone_handbrake: bool, + standalone_adapter: bool, + base_handbrake: bool, + base_h_shifter: bool, + base_adapter: bool, +) -> Snapshot { + let shifter_connected = standalone_shifter || base_h_shifter; + let handbrake_connected = standalone_handbrake || base_handbrake; + let base_adapter_connected = base_adapter && !base_h_shifter; + let adapter_connected = standalone_adapter || base_adapter_connected; + let shifter_mode = if standalone_shifter || standalone_handbrake { + "Direct USB".to_string() + } else if base_h_shifter || base_handbrake || base_adapter { + "Wheel base".to_string() + } else if standalone_adapter { + "Logitech Racing Adapter".to_string() + } else { + String::new() + }; + Snapshot { + // A wheel at rest sends no reports at all, so seed the + // steering at center rather than showing full left lock + // until the first real event arrives. + steering_raw: evtest::AXIS_MAX / 2, + buttons: vec![false; num_buttons], + shifter_connected, + shifter_mode, + handbrake_connected, + adapter_connected, + base_adapter_connected, + ..Snapshot::default() + } +} + impl Reader { /// Open `path` and start the read loop, tracking `codes` (see /// `evtest::button_codes_for_model`; `snapshot.buttons` stays parallel @@ -104,6 +296,7 @@ impl Reader { pub fn start( path: &str, model: WheelModel, + sysfs_dir: Option, codes: Vec, axes: evtest::PedalAxes, on_snapshot: impl Fn(Snapshot) + Send + 'static, @@ -113,32 +306,59 @@ impl Reader { .read(true) .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) .open(path)?; - let mut standalone_shifter = open_standalone_shifter(path); + let wheel_path = path.to_string(); + let mut standalone_shifter = open_standalone_shifter(&wheel_path); + let mut standalone_handbrake = open_standalone_handbrake(&wheel_path); + let mut standalone_adapter = open_standalone_adapter(&wheel_path); + let (base_handbrake, base_h_shifter, base_adapter) = + probe_base_accessories(sysfs_dir.as_deref()); let standalone_detected = standalone_shifter.is_some(); + let handbrake_detected = standalone_handbrake.is_some(); + let adapter_detected = standalone_adapter.is_some(); + let right_paddle_idx = codes.iter().position(|c| *c == 0x124); + let left_paddle_idx = codes.iter().position(|c| *c == 0x125); let stop = Arc::new(AtomicBool::new(false)); let thread_stop = stop.clone(); let handle = std::thread::spawn(move || { - let mut snapshot = Snapshot { - // A wheel at rest sends no reports at all, so seed the - // steering at center rather than showing full left lock - // until the first real event arrives. - steering_raw: evtest::AXIS_MAX / 2, - buttons: vec![false; codes.len()], - shifter_connected: standalone_detected, - shifter_mode: if standalone_detected { "Direct USB".to_string() } else { String::new() }, - ..Snapshot::default() - }; + let mut snapshot = initial_snapshot( + codes.len(), + standalone_detected, + handbrake_detected, + adapter_detected, + base_handbrake, + base_h_shifter, + base_adapter, + ); let mut buf = [0u8; EVENT_SIZE * 64]; let mut dirty = true; // push the initial all-idle state once let mut last_push = Instant::now() - PUSH_INTERVAL; + let mut last_hotplug = Instant::now(); loop { if thread_stop.load(Ordering::Relaxed) { return; } - if let Some(ref mut s_file) = standalone_shifter { - if poll_standalone_shifter(s_file, &mut snapshot) { + if last_hotplug.elapsed() >= HOTPLUG_INTERVAL { + if refresh_accessories( + &wheel_path, + sysfs_dir.as_deref(), + &mut standalone_shifter, + &mut standalone_handbrake, + &mut standalone_adapter, + &mut snapshot, + ) { dirty = true; } + last_hotplug = Instant::now(); + } + if poll_standalone_devices( + &mut standalone_shifter, + &mut standalone_handbrake, + &mut standalone_adapter, + &mut snapshot, + right_paddle_idx, + left_paddle_idx, + ) { + dirty = true; } match poll_wheel_events(&mut file, &mut buf, &mut snapshot, &codes, axes, model) { Ok(changed) => { @@ -181,12 +401,12 @@ impl Drop for Reader { } /// Poll standalone USB RS H-Shifter events, updating gear and connection status. -fn poll_standalone_shifter(s_file: &mut std::fs::File, snapshot: &mut Snapshot) -> bool { +fn poll_standalone_shifter(s_file: &mut std::fs::File, snapshot: &mut Snapshot) -> Result { let mut s_buf = [0u8; EVENT_SIZE * 32]; - let n = match s_file.read(&mut s_buf) { - Ok(n) if n > 0 => n, - _ => return false, - }; + let n = read_nonblocking(s_file, &mut s_buf)?; + if n == 0 { + return Ok(false); + } let mut changed = false; let (events, _partial) = s_buf[..n].as_chunks::(); @@ -211,7 +431,135 @@ fn poll_standalone_shifter(s_file: &mut std::fs::File, snapshot: &mut Snapshot) changed = true; } } - changed + Ok(changed) +} + +/// Poll standalone RS Handbrake / Sequential Shifter events. +fn poll_standalone_handbrake( + hb_file: &mut std::fs::File, + snapshot: &mut Snapshot, + right_paddle_idx: Option, + left_paddle_idx: Option, +) -> Result { + let mut hb_buf = [0u8; EVENT_SIZE * 32]; + let n = read_nonblocking(hb_file, &mut hb_buf)?; + if n == 0 { + return Ok(false); + } + + let mut changed = false; + let (events, _partial) = hb_buf[..n].as_chunks::(); + for chunk in events { + let event = match evtest::parse_event(chunk) { + Some(e) => e, + None => continue, + }; + + match event { + TestEvent::Axis { code: evtest::ABS_Z, value } => { + // Scale 10-bit analog handbrake (0..1023) to wheel pedal scale (0..65535) + snapshot.axes[3] = ((value as i64 * 65535) / 1023) as i32; + changed = true; + } + TestEvent::Button { code: 0x120, pressed } => { // BTN_TRIGGER / 288 (Shift Up) + snapshot.seq_shift_up = pressed; + if let Some(idx) = right_paddle_idx { + if idx < snapshot.buttons.len() { + snapshot.buttons[idx] = pressed; + } + } + changed = true; + } + TestEvent::Button { code: 0x121, pressed } => { // BTN_THUMB / 289 (Shift Down) + snapshot.seq_shift_down = pressed; + if let Some(idx) = left_paddle_idx { + if idx < snapshot.buttons.len() { + snapshot.buttons[idx] = pressed; + } + } + changed = true; + } + _ => {} + } + } + Ok(changed) +} + +/// Poll standalone Logitech Racing Adapter events, updating pedal axes and legacy shifter gates. +fn poll_standalone_adapter(ad_file: &mut std::fs::File, snapshot: &mut Snapshot) -> Result { + let mut ad_buf = [0u8; EVENT_SIZE * 32]; + let n = read_nonblocking(ad_file, &mut ad_buf)?; + if n == 0 { + return Ok(false); + } + + let mut changed = false; + let (events, _partial) = ad_buf[..n].as_chunks::(); + for chunk in events { + let event = match evtest::parse_event(chunk) { + Some(e) => e, + None => continue, + }; + + match event { + TestEvent::Axis { code, value } => { + // Scale 12-bit pedal axes (0..4095) to wheel pedal scale (0..65535) + let scaled = ((value as i64 * 65535) / 4095) as i32; + match code { + evtest::ABS_Y => { + snapshot.axes[0] = scaled; // Throttle + changed = true; + } + evtest::ABS_Z => { + snapshot.axes[1] = scaled; // Brake + changed = true; + } + evtest::ABS_RX => { + snapshot.axes[2] = scaled; // Clutch + changed = true; + } + _ => {} + } + } + TestEvent::Button { code, pressed } => { + let gear = match evtest::gear_from_adapter_code(code) { + Some(g) => g as i32, + None => continue, + }; + + if pressed { + snapshot.adapter_gear = gear; + snapshot.adapter_connected = true; + if snapshot.shifter_mode.is_empty() { + snapshot.shifter_mode = "Logitech Racing Adapter".to_string(); + } + changed = true; + } else if snapshot.adapter_gear == gear { + snapshot.adapter_gear = 0; + changed = true; + } + } + _ => {} + } + } + Ok(changed) +} + +fn update_base_sequential(snapshot: &mut Snapshot, code: u16, pressed: bool) -> bool { + if !snapshot.handbrake_connected { + return false; + } + match code { + 0x124 => { + snapshot.seq_shift_up = pressed; + true + } + 0x125 => { + snapshot.seq_shift_down = pressed; + true + } + _ => false, + } } /// Fold one raw event into `snapshot`; true if anything shown changed. @@ -235,8 +583,24 @@ fn apply_event( snapshot.buttons[i] = pressed; changed = true; } + if update_base_sequential(snapshot, code, pressed) { + changed = true; + } if let Some(gear) = evtest::gear_from_wheel_code(model, code) { - if pressed { + if snapshot.base_adapter_connected { + let ad_gear = gear as i32; + if pressed { + snapshot.adapter_gear = ad_gear; + snapshot.adapter_connected = true; + if snapshot.shifter_mode.is_empty() { + snapshot.shifter_mode = "Wheel base".to_string(); + } + changed = true; + } else if snapshot.adapter_gear == ad_gear { + snapshot.adapter_gear = 0; + changed = true; + } + } else if pressed { snapshot.gear = gear as i32; snapshot.shifter_connected = true; if snapshot.shifter_mode.is_empty() { @@ -424,7 +788,6 @@ pub fn run_test_sequence( fftest::run_sequence(&mut device, steps, model, cancel, on_event) } -#[cfg(test)] #[cfg(test)] mod tests { use super::*; diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint b/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint index 4eec2a4..9e6805e 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint +++ b/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint @@ -230,8 +230,14 @@ export component App inherits Window { in property <[TestCallout]> test-callouts: []; in property test-gear: 0; in property test-gear-name: "N"; + in property test-adapter-gear: 0; + in property test-adapter-gear-name: "N"; in property test-shifter-connected: false; in property test-shifter-mode: ""; + in property test-seq-shift-up: false; + in property test-seq-shift-down: false; + in property test-handbrake-connected: false; + in property test-adapter-connected: false; in property test-sim-running: false; in property test-sim-error: ""; // The running (or just-finished) sequence's one-line summary (set @@ -785,8 +791,14 @@ export component App inherits Window { callouts: root.test-callouts; gear: root.test-gear; gear-name: root.test-gear-name; + adapter-gear: root.test-adapter-gear; + adapter-gear-name: root.test-adapter-gear-name; shifter-connected: root.test-shifter-connected; shifter-mode: root.test-shifter-mode; + seq-shift-up: root.test-seq-shift-up; + seq-shift-down: root.test-seq-shift-down; + handbrake-connected: root.test-handbrake-connected; + adapter-connected: root.test-adapter-connected; sim-running: root.test-sim-running; sim-error: root.test-sim-error; sim-status: root.test-sim-status; diff --git a/userspace/logi-wheel/crates/logi-wheel-gui/ui/info_page.slint b/userspace/logi-wheel/crates/logi-wheel-gui/ui/info_page.slint index c0bd829..0e3e67c 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/ui/info_page.slint +++ b/userspace/logi-wheel/crates/logi-wheel-gui/ui/info_page.slint @@ -150,8 +150,14 @@ export component InfoPage inherits Rectangle { in property <[TestAxis]> axes: []; in property gear: 0; in property gear-name: "N"; + in property adapter-gear: 0; + in property adapter-gear-name: "N"; in property shifter-connected: false; in property shifter-mode: ""; + in property seq-shift-up: false; + in property seq-shift-down: false; + in property handbrake-connected: false; + in property adapter-connected: false; // The layout image's callout boxes, tinted while pressed; see // `TestCallout`. Only meaningful over the RS50's numbered layout photo // (`wheel-kind` 0): the G PRO/G923 photos are plain product shots with @@ -711,151 +717,372 @@ export component InfoPage inherits Rectangle { VerticalLayout { spacing: 2px; Text { - text: "H-Pattern Shifter (Logitech G RS H-Shifter)"; + text: "Shifter & Handbrake (Logitech RS & G Series)"; font-size: 15px; font-weight: 700; color: Theme.text-color; } Text { - text: root.shifter-connected + text: (root.shifter-connected || root.handbrake-connected || root.adapter-connected) ? ("Status: Connected (" + root.shifter-mode + ")") : "Status: Waiting for gear input or USB connection..."; font-size: 11px; - color: root.shifter-connected ? Theme.ok-color : Theme.muted-text-color; + color: (root.shifter-connected || root.handbrake-connected || root.adapter-connected) ? Theme.ok-color : Theme.muted-text-color; } } - Rectangle { - width: 145px; - height: 32px; - border-radius: 6px; - background: root.gear == 0 - ? Palette.alternate-background - : (root.gear == 8 ? #e0524a26 : Palette.accent-background.with-alpha(0.2)); - border-width: 1px; - border-color: root.gear == 0 - ? Theme.panel-border - : (root.gear == 8 ? #e0524a : Palette.accent-background); - - Text { - text: root.gear == 0 - ? "Neutral (N)" - : (root.gear == 8 ? "Reverse (R)" : ("Gear " + root.gear-name)); - font-size: 12px; - font-weight: 700; - horizontal-alignment: center; - vertical-alignment: center; - color: root.gear == 0 - ? Theme.text-color + HorizontalLayout { + spacing: 8px; + if root.shifter-connected || (!root.handbrake-connected && !root.adapter-connected) : Rectangle { + width: 155px; + height: 32px; + border-radius: 6px; + background: root.gear == 0 + ? Palette.alternate-background + : (root.gear == 8 ? #e0524a26 : Palette.accent-background.with-alpha(0.2)); + border-width: 1px; + border-color: root.gear == 0 + ? Theme.panel-border : (root.gear == 8 ? #e0524a : Palette.accent-background); + + Text { + text: (root.adapter-connected ? "RS: " : "") + (root.gear == 0 + ? "Neutral (N)" + : (root.gear == 8 ? "Reverse (R)" : ("Gear " + root.gear-name))); + font-size: 12px; + font-weight: 700; + horizontal-alignment: center; + vertical-alignment: center; + color: root.gear == 0 + ? Theme.text-color + : (root.gear == 8 ? #e0524a : Palette.accent-background); + } + } + if root.adapter-connected : Rectangle { + width: 175px; + height: 32px; + border-radius: 6px; + background: root.adapter-gear == 0 + ? Palette.alternate-background + : (root.adapter-gear == 8 ? #e0524a26 : Palette.accent-background.with-alpha(0.2)); + border-width: 1px; + border-color: root.adapter-gear == 0 + ? Theme.panel-border + : (root.adapter-gear == 8 ? #e0524a : Palette.accent-background); + + HorizontalLayout { + padding-left: 10px; + padding-right: 10px; + spacing: 6px; + alignment: center; + + VerticalLayout { + alignment: center; + Rectangle { + width: 7px; + height: 7px; + border-radius: 3.5px; + background: Theme.ok-color; + } + } + + Text { + text: "Adapter: " + (root.adapter-gear == 0 + ? "Neutral (N)" + : (root.adapter-gear == 8 ? "Reverse (R)" : ("Gear " + root.adapter-gear-name))); + font-size: 12px; + font-weight: 700; + vertical-alignment: center; + color: root.adapter-gear == 0 + ? Theme.text-color + : (root.adapter-gear == 8 ? #e0524a : Palette.accent-background); + } + } } } } - // Interactive 7-speed + Reverse H-gate pattern: - HorizontalLayout { + // Interactive H-gate patterns (RS 7+R and/or Racing Adapter 6+R): + if root.shifter-connected || root.adapter-connected || !root.handbrake-connected : HorizontalLayout { alignment: center; - Rectangle { - width: 330px; - height: 160px; - border-radius: 10px; - background: Theme.control-background; - border-width: 1px; - border-color: Theme.panel-border; + spacing: 16px; - // Neutral center rail: - Rectangle { - x: 35px; - y: 74px; - width: 260px; - height: 12px; - border-radius: 6px; - background: root.gear == 0 - ? Palette.accent-background.with-alpha(0.35) - : Palette.alternate-background; - } - - // 4 vertical slots: - // Gate 1-2 - Rectangle { - x: 48px; - y: 24px; - width: 12px; - height: 112px; - border-radius: 6px; - background: (root.gear == 1 || root.gear == 2) - ? Palette.accent-background.with-alpha(0.35) - : Palette.alternate-background; + if root.shifter-connected || (!root.handbrake-connected && !root.adapter-connected) : VerticalLayout { + spacing: 4px; + if root.shifter-connected && root.adapter-connected : Text { + text: "RS H-Shifter (7+R)"; + font-size: 11px; + font-weight: 600; + horizontal-alignment: center; + color: Theme.muted-text-color; } - // Gate 3-4 Rectangle { - x: 123px; - y: 24px; - width: 12px; - height: 112px; - border-radius: 6px; - background: (root.gear == 3 || root.gear == 4) - ? Palette.accent-background.with-alpha(0.35) - : Palette.alternate-background; + width: 330px; + height: 160px; + border-radius: 10px; + background: Theme.control-background; + border-width: 1px; + border-color: Theme.panel-border; + + // Neutral center rail: + Rectangle { + x: 35px; + y: 74px; + width: 260px; + height: 12px; + border-radius: 6px; + background: root.gear == 0 + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + + // 4 vertical slots: + // Gate 1-2 + Rectangle { + x: 48px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.gear == 1 || root.gear == 2) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate 3-4 + Rectangle { + x: 123px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.gear == 3 || root.gear == 4) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate 5-6 + Rectangle { + x: 198px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.gear == 5 || root.gear == 6) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate 7-R + Rectangle { + x: 270px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.gear == 7 || root.gear == 8) + ? (root.gear == 8 ? #e0524a40 : Palette.accent-background.with-alpha(0.35)) + : Palette.alternate-background; + } + + // Gear badges: + // Top row (1, 3, 5, 7): + GateBadge { x: 35px; y: 12px; label: "1"; active: root.gear == 1; } + GateBadge { x: 110px; y: 12px; label: "3"; active: root.gear == 3; } + GateBadge { x: 185px; y: 12px; label: "5"; active: root.gear == 5; } + GateBadge { x: 257px; y: 12px; label: "7"; active: root.gear == 7; } + + // Bottom row (2, 4, 6, R): + GateBadge { x: 35px; y: 110px; label: "2"; active: root.gear == 2; } + GateBadge { x: 110px; y: 110px; label: "4"; active: root.gear == 4; } + GateBadge { x: 185px; y: 110px; label: "6"; active: root.gear == 6; } + GateBadge { x: 257px; y: 110px; label: "R"; active: root.gear == 8; is-reverse: true; } + + // Neutral (N) badge: + Rectangle { + x: 147px; + y: 62px; + width: 36px; + height: 36px; + border-radius: 18px; + border-width: 2px; + border-color: root.gear == 0 ? Palette.accent-background : Theme.panel-border; + background: root.gear == 0 ? Palette.accent-background : Theme.control-background; + animate background { duration: 100ms; } + + Text { + text: "N"; + font-size: 13px; + font-weight: root.gear == 0 ? 800 : 500; + horizontal-alignment: center; + vertical-alignment: center; + color: root.gear == 0 ? Palette.accent-foreground : Theme.muted-text-color; + } + } } - // Gate 5-6 - Rectangle { - x: 198px; - y: 24px; - width: 12px; - height: 112px; - border-radius: 6px; - background: (root.gear == 5 || root.gear == 6) - ? Palette.accent-background.with-alpha(0.35) - : Palette.alternate-background; + } + + if root.adapter-connected : VerticalLayout { + spacing: 4px; + if root.shifter-connected : Text { + text: "Racing Adapter (6+R)"; + font-size: 11px; + font-weight: 600; + horizontal-alignment: center; + color: Theme.muted-text-color; } - // Gate 7-R Rectangle { - x: 270px; - y: 24px; - width: 12px; - height: 112px; - border-radius: 6px; - background: (root.gear == 7 || root.gear == 8) - ? (root.gear == 8 ? #e0524a40 : Palette.accent-background.with-alpha(0.35)) - : Palette.alternate-background; - } + width: 330px; + height: 160px; + border-radius: 10px; + background: Theme.control-background; + border-width: 1px; + border-color: Theme.panel-border; - // Gear badges: - // Top row (1, 3, 5, 7): - GateBadge { x: 35px; y: 12px; label: "1"; active: root.gear == 1; } - GateBadge { x: 110px; y: 12px; label: "3"; active: root.gear == 3; } - GateBadge { x: 185px; y: 12px; label: "5"; active: root.gear == 5; } - GateBadge { x: 257px; y: 12px; label: "7"; active: root.gear == 7; } + // Neutral center rail: + Rectangle { + x: 35px; + y: 74px; + width: 260px; + height: 12px; + border-radius: 6px; + background: root.adapter-gear == 0 + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } - // Bottom row (2, 4, 6, R): - GateBadge { x: 35px; y: 110px; label: "2"; active: root.gear == 2; } - GateBadge { x: 110px; y: 110px; label: "4"; active: root.gear == 4; } - GateBadge { x: 185px; y: 110px; label: "6"; active: root.gear == 6; } - GateBadge { x: 257px; y: 110px; label: "R"; active: root.gear == 8; is-reverse: true; } + // 3 full vertical slots + 1 bottom half-slot for Reverse: + // Gate 1-2 + Rectangle { + x: 48px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.adapter-gear == 1 || root.adapter-gear == 2) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate 3-4 + Rectangle { + x: 123px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.adapter-gear == 3 || root.adapter-gear == 4) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate 5-6 + Rectangle { + x: 198px; + y: 24px; + width: 12px; + height: 112px; + border-radius: 6px; + background: (root.adapter-gear == 5 || root.adapter-gear == 6) + ? Palette.accent-background.with-alpha(0.35) + : Palette.alternate-background; + } + // Gate R (bottom half only on 6+R Driving Force Shifter) + Rectangle { + x: 270px; + y: 74px; + width: 12px; + height: 62px; + border-radius: 6px; + background: root.adapter-gear == 8 + ? #e0524a40 + : Palette.alternate-background; + } - // Neutral (N) badge: - Rectangle { - x: 147px; - y: 62px; - width: 36px; - height: 36px; - border-radius: 18px; - border-width: 2px; - border-color: root.gear == 0 ? Palette.accent-background : Theme.panel-border; - background: root.gear == 0 ? Palette.accent-background : Theme.control-background; - animate background { duration: 100ms; } + // Gear badges: + // Top row (1, 3, 5): + GateBadge { x: 35px; y: 12px; label: "1"; active: root.adapter-gear == 1; } + GateBadge { x: 110px; y: 12px; label: "3"; active: root.adapter-gear == 3; } + GateBadge { x: 185px; y: 12px; label: "5"; active: root.adapter-gear == 5; } - Text { - text: "N"; - font-size: 13px; - font-weight: root.gear == 0 ? 800 : 500; - horizontal-alignment: center; - vertical-alignment: center; - color: root.gear == 0 ? Palette.accent-foreground : Theme.muted-text-color; + // Bottom row (2, 4, 6, R): + GateBadge { x: 35px; y: 110px; label: "2"; active: root.adapter-gear == 2; } + GateBadge { x: 110px; y: 110px; label: "4"; active: root.adapter-gear == 4; } + GateBadge { x: 185px; y: 110px; label: "6"; active: root.adapter-gear == 6; } + GateBadge { x: 257px; y: 110px; label: "R"; active: root.adapter-gear == 8; is-reverse: true; } + + // Neutral (N) badge: + Rectangle { + x: 147px; + y: 62px; + width: 36px; + height: 36px; + border-radius: 18px; + border-width: 2px; + border-color: root.adapter-gear == 0 ? Palette.accent-background : Theme.panel-border; + background: root.adapter-gear == 0 ? Palette.accent-background : Theme.control-background; + animate background { duration: 100ms; } + + Text { + text: "N"; + font-size: 13px; + font-weight: root.adapter-gear == 0 ? 800 : 500; + horizontal-alignment: center; + vertical-alignment: center; + color: root.adapter-gear == 0 ? Palette.accent-foreground : Theme.muted-text-color; + } } } } } + + // RS Sequential Shifter status: + if root.handbrake-connected : HorizontalLayout { + alignment: center; + spacing: 12px; + Rectangle { + width: 140px; + height: 32px; + border-radius: 6px; + background: root.seq-shift-up + ? Palette.accent-background + : Palette.alternate-background; + border-width: 1px; + border-color: root.seq-shift-up + ? Palette.accent-background + : Theme.panel-border; + animate background { duration: 80ms; } + + Text { + text: "▲ Shift Up"; + font-size: 12px; + font-weight: 700; + horizontal-alignment: center; + vertical-alignment: center; + color: root.seq-shift-up + ? Palette.accent-foreground + : Theme.text-color; + } + } + Rectangle { + width: 140px; + height: 32px; + border-radius: 6px; + background: root.seq-shift-down + ? Palette.accent-background + : Palette.alternate-background; + border-width: 1px; + border-color: root.seq-shift-down + ? Palette.accent-background + : Theme.panel-border; + animate background { duration: 80ms; } + + Text { + text: "▼ Shift Down"; + font-size: 12px; + font-weight: 700; + horizontal-alignment: center; + vertical-alignment: center; + color: root.seq-shift-down + ? Palette.accent-foreground + : Theme.text-color; + } + } + } } }