diff --git a/docs/BUTTON_MAPPING.md b/docs/BUTTON_MAPPING.md index 28b7bb69..43ff7f65 100644 --- a/docs/BUTTON_MAPPING.md +++ b/docs/BUTTON_MAPPING.md @@ -48,7 +48,29 @@ sequential after G1). The D-pad reports as a hat switch (`ABS_HAT0X` / `ABS_HAT0Y`), not as four buttons - diagram callout "D". -Indices 12 to 20 are gaps in the HID descriptor (unused). +## RS H-Shifter (046d:c26b) + +### 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. + +| Index | Button / Gear | evdev Code | Wire bitmask (Report 0x08) | +|---|---|---|---| +| 12 | RS H-Shifter: Gear 1 | `0x12c` (`BTN_BASE`) | Byte 2 bit 0 (`0x01`) | +| 13 | RS H-Shifter: Gear 2 | `0x12d` (`BTN_BASE2`) | Byte 2 bit 1 (`0x02`) | +| 14 | RS H-Shifter: Gear 3 | `0x12e` (`BTN_BASE3`) | Byte 2 bit 2 (`0x04`) | +| 15 | RS H-Shifter: Gear 4 | `0x12f` (`BTN_BASE4`) | Byte 2 bit 3 (`0x08`) | +| 16 | RS H-Shifter: Gear 5 | `0x2c0` (`BTN_TRIGGER_HAPPY1`) | Byte 2 bit 4 (`0x10`) | +| 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`) | - | + +### Connected Directly to PC via USB + +When connected directly to the PC via USB (`046d:c26b Logitech RS H-Shifter`), it enumerates as an independent joystick reporting 8 digital buttons: +- Buttons 0 to 6 (`0x120`..`0x126`): 1st through 7th gear +- Button 7 (`0x127`): Reverse (R) ## G923 diff --git a/docs/PROTOCOL_SPECIFICATION.md b/docs/PROTOCOL_SPECIFICATION.md index b8d00b20..f2a0ede9 100644 --- a/docs/PROTOCOL_SPECIFICATION.md +++ b/docs/PROTOCOL_SPECIFICATION.md @@ -73,7 +73,7 @@ The RS50 presents **3 HID interfaces** to the host: Offset Size Type Description ------ ---- ---- ----------- 0-1 2 uint16 Button bitmask, buttons 0-15 (little-endian) -2-3 2 - Button bitmask high bytes (byte 3 bit 7 = G button; otherwise 0) +2-3 2 - Button bitmask high bytes (Byte 2: RS H-Shifter Gears 1-7; Byte 3 bit 0: Reverse, bit 7: G button) 4-5 2 uint16 Wheel position (little-endian) 6-7 2 uint16 Accelerator pedal (little-endian) 8-9 2 uint16 Brake pedal (little-endian) @@ -108,9 +108,22 @@ Button state is encoded in bytes 0-3 of the input report. | 6 | `0x40` | **LB** (Left Bumper) | | 7 | `0x80` | **RB** (Right Bumper) | +**Byte 2 (RS H-Shifter, Sub-Device 03):** +| Bit | Mask | Button | +|-----|--------|--------| +| 0 | `0x01` | **Gear 1** | +| 1 | `0x02` | **Gear 2** | +| 2 | `0x04` | **Gear 3** | +| 3 | `0x08` | **Gear 4** | +| 4 | `0x10` | **Gear 5** | +| 5 | `0x20` | **Gear 6** | +| 6 | `0x40` | **Gear 7** | +| 7 | `0x80` | Unused | + **Byte 3:** | Bit | Mask | Button | |-----|--------|--------| +| 0 | `0x01` | **Reverse (RS H-Shifter)** | | 7 | `0x80` | **G Button** (Logitech logo) | ### D-pad Encoding (Byte 0 low nibble, bits 0-3) - standard HID hat diff --git a/docs/SYSFS_API.md b/docs/SYSFS_API.md index 426fa03d..e2ee9eed 100644 --- a/docs/SYSFS_API.md +++ b/docs/SYSFS_API.md @@ -992,12 +992,20 @@ Include this output in bug reports - firmware-dependent behaviour **Access**: Read-only **Values**: accessory device name, or `none` -Presence signal for the **RS Shifter & Handbrake**, an optional accessory -that plugs into the base's USB-A port. Reports the accessory's own HID++ -device name when one is discovered at probe time, or `none` when absent. -Unlike the pedal/handbrake attributes below, this never returns an error: -it exists precisely so apps can check for the accessory without inferring -presence from another attribute's error code. +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 +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. + +Both accessories are found at probe time and re-checked on demand: a read +queues a presence re-check in the background, so an accessory plugged in or +pulled after the module loaded shows up within a few reads. An RS H-Shifter +that arrives this way in desktop mode gets its gate routing enabled at the +same time, as it would have at probe. ```bash cat wheel_accessory diff --git a/mainline/hid-logitech-hidpp.c b/mainline/hid-logitech-hidpp.c index ab81cf58..775f2e25 100644 --- a/mainline/hid-logitech-hidpp.c +++ b/mainline/hid-logitech-hidpp.c @@ -5414,6 +5414,8 @@ static void hidpp_ff_retry_work(struct work_struct *work) */ #define HIDPP_DD_PEDAL_BASE_AXIS(pedal) ((pedal) + 1) #define HIDPP_DD_PAGE_CALIBRATE 0x812C /* Centre calibration (G Pro sub-device 0x05) */ +#define HIDPP_DD_PAGE_ATTACHMENTS 0x8120 /* GAMING_ATTACHMENTS accessory slot routing */ +#define HIDPP_DD_PAGE_RS_H_SHIFTER 0x812D /* RS H-Shifter capabilities (sub-device) */ #define HIDPP_DD_PAGE_SYNC 0x1BC0 /* Unknown sync/prepare feature */ /* * BANDED_AXIS and DEVICE_MODE: names are first-party (Solaar's HID++ 2.0 @@ -5932,6 +5934,9 @@ struct hidpp_dd_ff_data { u8 idx_shifter_curve; /* Feature index for 0x80A4 on the accessory (dev shifter_dev_idx, axis 0 = handbrake) */ u8 idx_shifter_banded; /* Feature index for 0x80B1 BANDED_AXIS on the accessory */ 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 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 */ u8 accessory_scan_cursor; /* next candidate index a presence rescan will try */ @@ -6044,7 +6049,7 @@ struct hidpp_dd_ff_data { char serial[13]; /* 12-char Base34 serial + NUL */ char fw_main[16]; /* base firmware, e.g. "U1 65.03.B0038" */ char fw_motor[16]; /* motor firmware (sub-device 0x05) */ - char accessory_name[32]; /* RS Shifter & Handbrake's own 0x0005 name; empty if not discovered */ + char accessory_name[32]; /* wheel_accessory text; empty with no accessory */ u8 led_effect; /* LED effect mode (1-5, 5=custom) */ /* LIGHTSYNC per-slot configuration (full RGB control) */ @@ -8721,6 +8726,56 @@ static void hidpp_dd_query_accessory_name(struct hidpp_dd_ff_data *ff, u8 dev_id ff->accessory_name[index] = '\0'; } +/* + * Record a confirmed RS Shifter & Handbrake at @cand: its response-curve + * index, its BANDED_AXIS index, its DEVICE_MODE index (left absent when the + * accessory does not answer for it) and its queried device name. The caller + * publishes shifter_dev_idx itself, last, because that is what the readers + * gate on. + */ +static void hidpp_dd_adopt_shifter_handbrake(struct hidpp_dd_ff_data *ff, + u8 cand, u8 curve_idx, u8 banded_idx) +{ + struct hidpp_device *hidpp = ff->hidpp; + + ff->idx_shifter_curve = curve_idx; + ff->idx_shifter_banded = banded_idx; + if (hidpp_root_get_feature_on_device(hidpp, cand, + HIDPP_DD_PAGE_DEVICE_MODE, + &ff->idx_shifter_mode)) + ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; + else + dd_dbg(hidpp->hid_dev, "Accessory mode feature at index 0x%02x\n", + ff->idx_shifter_mode); + hidpp_dd_query_accessory_name(ff, cand); +} + +/* + * Probe one candidate sub-device for the RS H-Shifter. It answers + * ROOT.GetFeature(0x812D) on the index of the port it is plugged into, and + * no other sub-device carries that page (contributor-verified on an RS50, + * 2026-10-29). Only called for a candidate already known to answer, so the + * normal transport timeout is fine: a silent index never gets this far. + * + * On a hit this records the feature index and, unless an accessory with a + * queried name already owns it, the wheel_accessory text. The caller + * publishes h_shifter_dev_idx itself, last, because that is what the + * readers gate on. + */ +static bool hidpp_dd_probe_h_shifter(struct hidpp_dd_ff_data *ff, u8 cand) +{ + u8 idx; + + if (hidpp_root_get_feature_on_device(ff->hidpp, 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; +} + /* * Discover HID++ feature indices for the "settings" surface: per-wheel * tuning exposed as wheel_* sysfs attributes, plus profile / mode / @@ -8748,6 +8803,9 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) 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->idx_attachments = HIDPP_DD_FEATURE_NOT_FOUND; ff->accessory_name[0] = '\0'; /* * Explicitly now, not the kzalloc'd 0: jiffies starts at INITIAL_JIFFIES @@ -8924,48 +8982,57 @@ static void hidpp_dd_discover_settings_features(struct hidpp_dd_ff_data *ff) * free. 0x1B30 (DEVICE_MODE) is resolved the same way once the * accessory is confirmed; it is not itself part of the confirmation * since its cross-device uniqueness has not been verified. + * + * The RS H-Shifter rides the same pass. It has no response curve, so + * its port answers the presence check with -ENOENT (present, page + * unknown) in a few milliseconds instead of timing out, and that + * answer, or a curve with an axis count this driver cannot place, is + * what sends a candidate to hidpp_dd_probe_h_shifter(). A silent + * index is never asked twice, so a bare wheel pays nothing for this + * beyond the one probe per candidate it already paid. */ for (i = 0; i < ARRAY_SIZE(hidpp_dd_pedal_dev_candidates); i++) { u8 cand = hidpp_dd_pedal_dev_candidates[i]; - u8 cand_idx, axes; + u8 cand_idx, axes, banded_idx; if (ff->pedal_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && - ff->shifter_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) break; ret = hidpp_root_get_feature_on_device_timeout(hidpp, cand, HIDPP_DD_PAGE_RESPONSE_CURVE, &cand_idx, HIDPP_DD_PROBE_TIMEOUT); - if (ret) - continue; - if (hidpp_dd_pedal_axis_count(hidpp, cand, cand_idx, &axes)) + if (ret && ret != -ENOENT) continue; - - if (axes == HIDPP_DD_PEDAL_AXIS_COUNT && - ff->pedal_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) { - ff->pedal_dev_idx = cand; - ff->idx_pedal_curve = cand_idx; - continue; - } - - if (axes == HIDPP_DD_SHIFTER_AXIS_COUNT && - ff->shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) { - u8 banded_idx; - - if (hidpp_root_get_feature_on_device(hidpp, cand, + if (ret == 0 && + hidpp_dd_pedal_axis_count(hidpp, cand, cand_idx, &axes) == 0) { + if (axes == HIDPP_DD_PEDAL_AXIS_COUNT) { + if (ff->pedal_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) { + ff->pedal_dev_idx = cand; + ff->idx_pedal_curve = cand_idx; + } + continue; + } + if (axes == HIDPP_DD_SHIFTER_AXIS_COUNT && + hidpp_root_get_feature_on_device(hidpp, cand, HIDPP_DD_PAGE_BANDED_AXIS, - &banded_idx)) + &banded_idx) == 0) { + if (ff->shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) { + hidpp_dd_adopt_shifter_handbrake(ff, cand, + cand_idx, banded_idx); + ff->shifter_dev_idx = cand; + } continue; - ff->shifter_dev_idx = cand; - ff->idx_shifter_curve = cand_idx; - ff->idx_shifter_banded = banded_idx; - ret = hidpp_root_get_feature_on_device(hidpp, cand, - HIDPP_DD_PAGE_DEVICE_MODE, - &ff->idx_shifter_mode); - if (ret == 0) - dd_dbg(hid, "Accessory mode feature at index 0x%02x\n", - ff->idx_shifter_mode); - hidpp_dd_query_accessory_name(ff, cand); + } + } + + /* 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)) { + 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); } } if (ff->pedal_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) @@ -9181,6 +9248,10 @@ static void hidpp_dd_discover_lightsync_features(struct hidpp_dd_ff_data *ff) ret = hidpp_root_get_feature(hidpp, HIDPP_DD_PAGE_SYNC, &ff->idx_sync); if (ret == 0) dd_dbg(hid, "Sync feature at index 0x%02x\n", ff->idx_sync); + + ret = hidpp_root_get_feature(hidpp, HIDPP_DD_PAGE_ATTACHMENTS, &ff->idx_attachments); + if (ret == 0) + dd_dbg(hid, "Attachments feature at index 0x%02x\n", ff->idx_attachments); } /* @@ -9206,6 +9277,62 @@ static void hidpp_dd_ff_discover_features(struct hidpp_dd_ff_data *ff) dd_dbg(hid, "Feature discovery completed\n"); } +/* + * Desktop mode shifter enablement. + * + * In Desktop mode (profile 0), direct-drive wheel bases suppress sub-device + * gate reporting (gears 1-6 and Reverse) unless G HUB's slot routing, + * sync and accessory enable commands are sent. In Onboard mode (profiles + * 1-5), the base routes all gates automatically. + */ +static void hidpp_dd_enable_desktop_shifter(struct hidpp_dd_ff_data *ff) +{ + static const u8 slot_routing[16] = { + 0x0a, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a + }; + struct hidpp_device *hidpp = ff->hidpp; + struct hid_device *hid = hidpp->hid_dev; + struct hidpp_report response; + u8 params[16]; + int ret; + + if (ff->h_shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND) + return; + + /* 1. Feature 0x8120 GAMING_ATTACHMENTS on base */ + if (ff->idx_attachments != HIDPP_DD_FEATURE_NOT_FOUND) { + memset(params, 0, sizeof(params)); + ret = hidpp_send_fap_command_sync(hidpp, ff->idx_attachments, + 0x00 /* fn0 */, params, 0, &response); + if (ret) + dd_warn(hid, "Desktop shifter: attachments fn0 failed: %d\n", ret); + + memcpy(params, slot_routing, sizeof(slot_routing)); + ret = hidpp_send_fap_command_sync(hidpp, ff->idx_attachments, + 0x20 /* fn2 */, params, + sizeof(slot_routing), &response); + if (ret) + dd_warn(hid, "Desktop shifter: attachments fn2 failed: %d\n", ret); + + memset(params, 0, sizeof(params)); + ret = hidpp_send_fap_command_sync(hidpp, ff->idx_attachments, + 0x10 /* fn1 */, params, 0, &response); + if (ret) + dd_warn(hid, "Desktop shifter: attachments fn1 failed: %d\n", ret); + } + + /* 2. Feature 0x1BC0 SYNC on base: sync notify (fn2) */ + if (ff->idx_sync != HIDPP_DD_FEATURE_NOT_FOUND) { + memset(params, 0, sizeof(params)); + ret = hidpp_send_fap_command_sync(hidpp, ff->idx_sync, + 0x20 /* fn2 */, params, 0, &response); + if (ret) + dd_warn(hid, "Desktop shifter: base sync fn2 failed: %d\n", ret); + } + + dd_dbg(hid, "Desktop mode shifter enablement completed\n"); +} + /* * Query current mode/profile from device. * Feature 0x8137 fn1 returns: [profile] [mode?] ... @@ -9559,6 +9686,16 @@ 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. + * 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) + hidpp_dd_enable_desktop_shifter(ff); } /* @@ -11691,6 +11828,11 @@ static int hidpp_dd_lightsync_apply_slot(struct hidpp_device *hidpp, int ok = 0; for (i = 0; i < ARRAY_SIZE(desktop_sync_zones); i++) { + /* Skip GAMING_ATTACHMENTS (0x8120) so sync does not reset slot routing */ + if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + desktop_sync_zones[i] == ff->idx_attachments) + continue; + sync_params[0] = 0x01; sync_params[1] = 0x00; sync_params[2] = 0x09; @@ -12613,6 +12755,10 @@ static void hidpp_dd_oled_handback(struct hidpp_device *hidpp, struct hidpp_dd_f mutex_lock(&hidpp->send_mutex); hidpp_dd_oled_send(hidpp, ff->idx_display, 0x2, NULL, 0); mutex_unlock(&hidpp->send_mutex); + if (atomic_read_acquire(&ff->stopping)) + return; + if (ff->current_mode == 0) + hidpp_dd_enable_desktop_shifter(ff); } /* @@ -12700,6 +12846,7 @@ static ssize_t wheel_oled_store(struct device *dev, struct device_attribute *att struct hidpp_device *hidpp = hid_get_drvdata(to_hid_device(dev)); struct hidpp_dd_ff_data *ff = hidpp ? hidpp->private_data : NULL; u8 frame[HIDPP_DD_OLED_FRAME]; + bool was_active; int ret; if (!ff) @@ -12722,6 +12869,7 @@ static ssize_t wheel_oled_store(struct device *dev, struct device_attribute *att return ret; mutex_lock(&ff->oled_lock); + was_active = ff->oled_active; memcpy(ff->oled_frame, frame, sizeof(frame)); strscpy(ff->oled_text, buf, sizeof(ff->oled_text)); strim(ff->oled_text); @@ -12729,6 +12877,8 @@ static ssize_t wheel_oled_store(struct device *dev, struct device_attribute *att mutex_unlock(&ff->oled_lock); /* Now, not on the next tick: the first frame is what the user is waiting for. */ mod_delayed_work(ff->wq, &ff->oled_work, 0); + if (ff->current_mode == 0 && !was_active) + hidpp_dd_enable_desktop_shifter(ff); return count; } @@ -14970,10 +15120,11 @@ static DEVICE_ATTR(wheel_firmware, 0444, wheel_firmware_show, NULL); * up yet: their wire protocol is uncaptured. */ /* - * Re-check whether the RS Shifter & Handbrake is attached. + * Re-check which accessories are attached: the RS Shifter & Handbrake and + * the RS H-Shifter. * - * Discovery runs once at probe, but the accessory plugs into the base's own - * USB-A port, so it can arrive or leave while the driver is loaded and the + * Discovery runs once at probe, but an accessory plugs into the base's own + * USB-A ports, so it can arrive or leave while the driver is loaded and the * wheel never re-enumerates. Without this, a wheel that came up bare reports * "none" for as long as the module stays loaded, and everything keyed on * wheel_accessory stays wrong with it (hardware-verified 2026-07-28: plugging @@ -14995,18 +15146,15 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) struct hid_device *hid = hidpp->hid_dev; u8 idx; - if (ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) { + if (ff->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_root_get_feature_on_device_timeout(hidpp, ff->shifter_dev_idx, + HIDPP_DD_PAGE_BANDED_AXIS, &idx, + HIDPP_DD_PROBE_TIMEOUT)) { /* * Believed present, so one GetFeature on the index we already * know is enough to notice it has been unplugged: a sub-device * that is really there answers in about 2.5 ms. - */ - if (hidpp_root_get_feature_on_device_timeout(hidpp, - ff->shifter_dev_idx, - HIDPP_DD_PAGE_BANDED_AXIS, &idx, - HIDPP_DD_PROBE_TIMEOUT) == 0) - return; - /* + * * Retire the index first: wheel_accessory_show gates on it, so * clearing it before the name means a concurrent reader sees * "none" rather than a half-erased name. @@ -15016,13 +15164,30 @@ 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"); - return; } + if (ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_root_get_feature_on_device_timeout(hidpp, ff->h_shifter_dev_idx, + HIDPP_DD_PAGE_RS_H_SHIFTER, &idx, + HIDPP_DD_PROBE_TIMEOUT)) { + /* 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->shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND && + ff->h_shifter_dev_idx != HIDPP_DD_FEATURE_NOT_FOUND) + return; /* - * Believed absent: spend each pass on ONE candidate, round-robin, - * classified exactly as discovery does. + * Something is believed absent: spend each pass on ONE candidate, + * round-robin, classified exactly as discovery does. * * Sweeping the whole list every pass would be the obvious thing and the * wrong one: a silent candidate costs HIDPP_DD_PROBE_TIMEOUT, so a bare @@ -15043,55 +15208,75 @@ static void hidpp_dd_rescan_accessory(struct hidpp_dd_ff_data *ff) { u8 cand = hidpp_dd_pedal_dev_candidates[ff->accessory_scan_cursor]; u8 cand_idx, axes, banded_idx; + int ret; ff->accessory_scan_cursor = (ff->accessory_scan_cursor + 1) % ARRAY_SIZE(hidpp_dd_pedal_dev_candidates); - if (hidpp_root_get_feature_on_device_timeout(hidpp, cand, - HIDPP_DD_PAGE_RESPONSE_CURVE, &cand_idx, - HIDPP_DD_PROBE_TIMEOUT)) + /* Just confirmed above; nothing new can sit on that port. */ + if (cand == ff->shifter_dev_idx || cand == ff->h_shifter_dev_idx) return; - if (hidpp_dd_pedal_axis_count(hidpp, cand, cand_idx, &axes)) + ret = hidpp_root_get_feature_on_device_timeout(hidpp, cand, + HIDPP_DD_PAGE_RESPONSE_CURVE, &cand_idx, + HIDPP_DD_PROBE_TIMEOUT); + if (ret && ret != -ENOENT) return; - /* - * A sub-device index belongs to the base's physical port, not to - * whatever is plugged into it (hardware-verified 2026-07-28: - * moving the accessory to the pedals' port made it report on the - * pedals' index). So the pedal index is not a safe thing to skip - * over here, and it is not a safe thing to keep believing either: - * classify whatever actually answers, and correct the cached - * pedal index when the wheel disagrees with it. - */ - if (axes == HIDPP_DD_PEDAL_AXIS_COUNT) { - if (ff->pedal_dev_idx != cand) { - ff->pedal_dev_idx = cand; - ff->idx_pedal_curve = cand_idx; - dd_info(hid, "Pedals now at dev 0x%02x (curve idx 0x%02x)\n", - cand, cand_idx); + if (ret == 0 && + hidpp_dd_pedal_axis_count(hidpp, cand, cand_idx, &axes) == 0) { + /* + * A sub-device index belongs to the base's physical port, + * not to whatever is plugged into it (hardware-verified + * 2026-07-28: moving the accessory to the pedals' port + * made it report on the pedals' index). So the pedal + * index is not a safe thing to skip over here, and it is + * not a safe thing to keep believing either: classify + * whatever actually answers, and correct the cached pedal + * index when the wheel disagrees with it. + */ + if (axes == HIDPP_DD_PEDAL_AXIS_COUNT) { + if (ff->pedal_dev_idx != cand) { + ff->pedal_dev_idx = cand; + ff->idx_pedal_curve = cand_idx; + dd_info(hid, "Pedals now at dev 0x%02x (curve idx 0x%02x)\n", + cand, cand_idx); + } + return; + } + if (axes == HIDPP_DD_SHIFTER_AXIS_COUNT && + ff->shifter_dev_idx == HIDPP_DD_FEATURE_NOT_FOUND && + hidpp_root_get_feature_on_device(hidpp, cand, + HIDPP_DD_PAGE_BANDED_AXIS, + &banded_idx) == 0) { + hidpp_dd_adopt_shifter_handbrake(ff, cand, cand_idx, + banded_idx); + /* + * Publish the index last, for the same reason removal + * clears it first: it is what the reader gates on, so + * everything it will then go on to read is already in + * place. + */ + WRITE_ONCE(ff->shifter_dev_idx, cand); + dd_info(hid, "RS Shifter & Handbrake at dev 0x%02x (curve idx 0x%02x, banded idx 0x%02x)\n", + cand, ff->idx_shifter_curve, ff->idx_shifter_banded); + return; } - return; } - if (axes != HIDPP_DD_SHIFTER_AXIS_COUNT) - return; - if (hidpp_root_get_feature_on_device(hidpp, cand, - HIDPP_DD_PAGE_BANDED_AXIS, - &banded_idx)) + + /* 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)) return; - ff->idx_shifter_curve = cand_idx; - ff->idx_shifter_banded = banded_idx; - if (hidpp_root_get_feature_on_device(hidpp, cand, - HIDPP_DD_PAGE_DEVICE_MODE, - &ff->idx_shifter_mode)) - ff->idx_shifter_mode = HIDPP_DD_FEATURE_NOT_FOUND; - hidpp_dd_query_accessory_name(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); /* - * Publish the index last, for the same reason removal clears it - * first: it is what the reader gates on, so everything it will - * then go on to read is already in place. + * 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. */ - WRITE_ONCE(ff->shifter_dev_idx, cand); - dd_info(hid, "RS Shifter & Handbrake at dev 0x%02x (curve idx 0x%02x, banded idx 0x%02x)\n", - cand, ff->idx_shifter_curve, ff->idx_shifter_banded); - return; + if (ff->current_mode == 0) + hidpp_dd_enable_desktop_shifter(ff); } } @@ -15129,7 +15314,8 @@ 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 || + 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]) return sysfs_emit(buf, "none\n"); return sysfs_emit(buf, "%s\n", ff->accessory_name); 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 730a88cb..cd52d447 100644 --- a/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs +++ b/userspace/logi-wheel/crates/logi-wheel-core/src/evtest.rs @@ -638,6 +638,115 @@ pub fn scan_wheel_input_under(sysfs_input: &Path, usb: &Path) -> Option bool { + let upper = name.to_uppercase(); + upper.contains("RS H-SHIFTER") || upper.contains("DRIVING FORCE SHIFTER") +} + +/// Scan `sysfs_input` for `event*` entries whose device name satisfies `predicate`. +pub fn scan_input_by_name(sysfs_input: &Path, predicate: F) -> Option +where + F: Fn(&str) -> bool, +{ + let mut files: Vec = fs::read_dir(sysfs_input) + .ok()? + .filter_map(Result::ok) + .collect(); + files.sort_by_cached_key(|f| event_index(&f.file_name().to_string_lossy())); + + files.into_iter().find_map(|f| { + let ename = f.file_name().into_string().ok()?; + if !ename.starts_with("event") { + return None; + } + let dev_name = fs::read_to_string(f.path().join("device/name")).ok()?; + let trimmed = dev_name.trim(); + predicate(trimmed).then(|| WheelInput { + event_path: format!("/dev/input/{ename}"), + name: trimmed.to_string(), + }) + }) +} + +/// Scan `sysfs_input` for `event*` entries matching [`is_shifter_name`]. +pub fn scan_shifter_input(sysfs_input: &Path) -> Option { + scan_input_by_name(sysfs_input, is_shifter_name) +} + +/// Find a standalone USB shifter's evdev node, or `None` if not connected via USB. +pub fn discover_shifter_input() -> Option { + scan_shifter_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)] = &[ + (0x12c, "Gear 1"), + (0x12d, "Gear 2"), + (0x12e, "Gear 3"), + (0x12f, "Gear 4"), + (0x2c0, "Gear 5"), + (0x2c1, "Gear 6"), + (0x2c2, "Gear 7"), + (0x2c3, "Reverse"), +]; + +/// Decode a gear index (1..=7, 8 for Reverse) from a wheel evdev button code +/// when the RS H-Shifter is attached to a direct-drive base (RS50 or G PRO). +/// +/// Gated strictly to RS50 and G PRO: G923 editions assign physical wheel buttons +/// to these codes (e.g. Plus, Minus, Dial Push), so they must not decode as +/// shifter gates on non-direct-drive wheels. +pub fn gear_from_wheel_code(model: WheelModel, code: u16) -> Option { + match model { + WheelModel::Rs50 | WheelModel::GPro => match code { + 0x12c => Some(1), + 0x12d => Some(2), + 0x12e => Some(3), + 0x12f => Some(4), + 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) + _ => None, + }, + _ => None, + } +} + +/// Decode a gear index (1..=7, 8 for Reverse) from a standalone USB shifter +/// (`046d:c26b`). +pub fn gear_from_standalone_code(code: u16) -> Option { + match code { + 0x120 | 0x2c0 => Some(1), + 0x121 | 0x2c1 => Some(2), + 0x122 | 0x2c2 => Some(3), + 0x123 | 0x2c3 => Some(4), + 0x124 | 0x2c4 => Some(5), + 0x125 | 0x2c5 => Some(6), + 0x126 | 0x2c6 => Some(7), + 0x127 | 0x2c7 => 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 { + 1 => "1st", + 2 => "2nd", + 3 => "3rd", + 4 => "4th", + 5 => "5th", + 6 => "6th", + 7 => "7th", + 8 => "R", + _ => "N", + } +} + #[cfg(test)] mod tests { use super::*; @@ -1014,3 +1123,80 @@ mod xbox_button_tests { ); } } + +#[cfg(test)] +mod shifter_tests { + use super::*; + + #[test] + fn shifter_name_matching() { + const MATCHES: &[&str] = &[ + "Logitech RS H-Shifter", + "Logitech G RS H-Shifter", + "Logitech Driving Force Shifter USB", + ]; + const NON_MATCHES: &[&str] = &[ + "Logitech RS50 Base", + "G923 Racing Wheel", + "Generic Gamepad", + ]; + + for name in MATCHES { + assert!(is_shifter_name(name), "expected {name:?} to match"); + } + for name in NON_MATCHES { + assert!(!is_shifter_name(name), "expected {name:?} not to match"); + } + } + + #[test] + fn shifter_gear_decoding_from_wheel_base() { + const CASES: &[(u16, Option)] = &[ + (0x12c, Some(1)), // Gear 1 (BTN_BASE) + (0x12d, Some(2)), // Gear 2 (BTN_BASE2) + (0x12e, Some(3)), // Gear 3 (BTN_BASE3) + (0x12f, Some(4)), // Gear 4 (BTN_BASE4) + (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 + (0x12b, None), // Wheel rim LSB button + (0x120, None), // Wheel rim button A + ]; + + // Direct-Drive wheels (RS50 and G PRO) decode accessory gate indices + for model in [WheelModel::Rs50, WheelModel::GPro] { + for &(code, expected) in CASES { + assert_eq!( + gear_from_wheel_code(model, code), + expected, + "failed for model {model:?} with code 0x{code:03x}" + ); + } + } + + // Non-DD wheels (G923, Unknown) must strictly ignore accessory gates + for &(code, _) in CASES { + assert_eq!(gear_from_wheel_code(WheelModel::G923, code), None); + assert_eq!(gear_from_wheel_code(WheelModel::Unknown, code), None); + } + } + + #[test] + fn shifter_gear_decoding_from_standalone() { + // Direct USB reports 8 sequential buttons (0x120..=0x127) for 1st..7th and Reverse + for (i, code) in (0x120..=0x127).enumerate() { + assert_eq!(gear_from_standalone_code(code), Some((i + 1) as u8)); + } + assert_eq!(gear_from_standalone_code(0x128), None); + } + + #[test] + fn gear_names() { + assert_eq!(gear_name(0), "N"); + assert_eq!(gear_name(1), "1st"); + assert_eq!(gear_name(7), "7th"); + assert_eq!(gear_name(8), "R"); + } +} 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 72dbd0a9..ec22b043 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/main.rs @@ -925,6 +925,10 @@ fn apply_test_snapshot(app: &App, snap: &testio::Snapshot, model: WheelModel, wh .map(|(label, i)| TestAxis { label: (*label).into(), value: snap.axes[*i] }) .collect(); 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_shifter_connected(snap.shifter_connected); + app.set_test_shifter_mode(snap.shifter_mode.as_str().into()); } /// Stop (and join) the Test page's reader thread, if one is running. @@ -1007,6 +1011,7 @@ fn start_test_monitor( let wheel_name = wheel.name.clone(); match testio::Reader::start( &wheel.event_path, + model, 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 1323a95d..e0ca15ae 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs +++ b/userspace/logi-wheel/crates/logi-wheel-gui/src/testio.rs @@ -20,6 +20,7 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use logi_wheel_core::evtest::{self, TestEvent, EVENT_SIZE}; +use logi_wheel_core::WheelModel; /// One UI push worth of live wheel state. `buttons` is parallel to /// whichever code list `Reader::start` was given (see @@ -33,6 +34,9 @@ pub struct Snapshot { pub buttons: Vec, pub hat: (i32, i32), pub axes: [i32; 4], + pub gear: i32, + pub shifter_connected: bool, + pub shifter_mode: String, } /// How often the reader pushes a fresh [`Snapshot`] at most. @@ -50,6 +54,47 @@ pub struct Reader { handle: Option>, } +fn open_standalone_shifter(wheel_path: &str) -> Option { + let s = evtest::discover_shifter_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() +} + +/// 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). +fn poll_wheel_events( + file: &mut std::fs::File, + buf: &mut [u8; EVENT_SIZE * 64], + snapshot: &mut Snapshot, + codes: &[u16], + axes: evtest::PedalAxes, + model: WheelModel, +) -> Result { + match file.read(buf) { + Ok(0) => Err(()), // A closed/unplugged evdev node reads EOF. + Ok(n) => { + let mut changed = false; + let (events, _partial) = buf[..n].as_chunks::(); + for chunk in events { + if apply_event(snapshot, chunk, codes, axes, model) { + changed = true; + } + } + Ok(changed) + } + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => Ok(false), + Err(e) if e.kind() == std::io::ErrorKind::Interrupted => Ok(false), + Err(_) => Err(()), + } +} + impl Reader { /// Open `path` and start the read loop, tracking `codes` (see /// `evtest::button_codes_for_model`; `snapshot.buttons` stays parallel @@ -58,6 +103,7 @@ impl Reader { /// in a dead page. pub fn start( path: &str, + model: WheelModel, codes: Vec, axes: evtest::PedalAxes, on_snapshot: impl Fn(Snapshot) + Send + 'static, @@ -67,6 +113,8 @@ impl Reader { .read(true) .custom_flags(libc::O_NONBLOCK | libc::O_CLOEXEC) .open(path)?; + let mut standalone_shifter = open_standalone_shifter(path); + let standalone_detected = standalone_shifter.is_some(); let stop = Arc::new(AtomicBool::new(false)); let thread_stop = stop.clone(); let handle = std::thread::spawn(move || { @@ -76,6 +124,8 @@ impl Reader { // 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 buf = [0u8; EVENT_SIZE * 64]; @@ -85,26 +135,18 @@ impl Reader { if thread_stop.load(Ordering::Relaxed) { return; } - match file.read(&mut buf) { - // A closed/unplugged evdev node reads EOF. - Ok(0) => { - on_gone(); - return; + if let Some(ref mut s_file) = standalone_shifter { + if poll_standalone_shifter(s_file, &mut snapshot) { + dirty = true; } - Ok(n) => { - // as_chunks over chunks_exact: the size is a - // constant, so the compiler knows each slice is a - // whole event rather than checking per iteration. - let (events, _partial) = buf[..n].as_chunks::(); - for chunk in events { - if apply_event(&mut snapshot, chunk, &codes, axes) { - dirty = true; - } + } + match poll_wheel_events(&mut file, &mut buf, &mut snapshot, &codes, axes, model) { + Ok(changed) => { + if changed { + dirty = true; } } - Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {} - Err(e) if e.kind() == std::io::ErrorKind::Interrupted => {} - Err(_) => { + Err(()) => { on_gone(); return; } @@ -138,6 +180,40 @@ 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 { + 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 mut changed = false; + let (events, _partial) = s_buf[..n].as_chunks::(); + for chunk in events { + let (code, pressed) = match evtest::parse_event(chunk) { + Some(TestEvent::Button { code, pressed }) => (code, pressed), + _ => continue, + }; + + let gear = match evtest::gear_from_standalone_code(code) { + Some(g) => g as i32, + None => continue, + }; + + if pressed { + snapshot.gear = gear; + snapshot.shifter_connected = true; + snapshot.shifter_mode = "Direct USB".to_string(); + changed = true; + } else if snapshot.gear == gear { + snapshot.gear = 0; + changed = true; + } + } + changed +} + /// Fold one raw event into `snapshot`; true if anything shown changed. /// `codes` is the same list `snapshot.buttons` is parallel to (see /// `Reader::start`). @@ -146,19 +222,34 @@ fn apply_event( chunk: &[u8], codes: &[u16], axes: evtest::PedalAxes, + model: WheelModel, ) -> bool { match evtest::parse_event(chunk) { Some(TestEvent::Steering(raw)) => { snapshot.steering_raw = raw; true } - Some(TestEvent::Button { code, pressed }) => match codes.iter().position(|c| *c == code) { - Some(i) => { + Some(TestEvent::Button { code, pressed }) => { + let mut changed = false; + if let Some(i) = codes.iter().position(|c| *c == code) { snapshot.buttons[i] = pressed; - true + changed = true; } - None => false, - }, + if let Some(gear) = evtest::gear_from_wheel_code(model, code) { + if pressed { + snapshot.gear = gear as i32; + snapshot.shifter_connected = true; + if snapshot.shifter_mode.is_empty() { + snapshot.shifter_mode = "Wheel base".to_string(); + } + changed = true; + } else if snapshot.gear == gear as i32 { + snapshot.gear = 0; + changed = true; + } + } + changed + } Some(TestEvent::Axis { code, value }) => match code { evtest::ABS_HAT0X => { snapshot.hat.0 = value; @@ -339,9 +430,19 @@ mod tests { use super::*; use logi_wheel_core::device::WheelModel; + /// Helper for tests against a specific wheel model layout. + fn apply_event_for( + model: WheelModel, + snapshot: &mut Snapshot, + chunk: &[u8], + codes: &[u16], + ) -> bool { + apply_event(snapshot, chunk, codes, evtest::pedal_axes(model, None), model) + } + /// The direct-drive layout, which these tests were written against. fn apply_event_dd(snapshot: &mut Snapshot, chunk: &[u8], codes: &[u16]) -> bool { - apply_event(snapshot, chunk, codes, evtest::pedal_axes(WheelModel::Rs50, None)) + apply_event_for(WheelModel::Rs50, snapshot, chunk, codes) } /// A G923's brake reaches the brake bar rather than the handbrake one. @@ -357,7 +458,7 @@ mod tests { let codes = evtest::button_codes_for_model(WheelModel::G923); let mut s = Snapshot { buttons: vec![false; codes.len()], ..Default::default() }; let xbox = evtest::pedal_axes(WheelModel::G923, Some(0xc26e)); - assert!(apply_event(&mut s, &ev(3, evtest::ABS_Z, 200), &codes, xbox), "brake moved"); + assert!(apply_event(&mut s, &ev(3, evtest::ABS_Z, 200), &codes, xbox, WheelModel::G923), "brake moved"); assert_eq!(s.axes[1], 200, "ABS_Z is the brake on this wheel, not the handbrake"); assert_eq!(s.axes[3], 0, "and nothing should reach the handbrake bar"); } @@ -408,7 +509,10 @@ mod tests { assert!(apply_event_dd(&mut s, &ev(3, evtest::ABS_HAT0Y, -1), &codes), "hat up"); assert_eq!(s.hat, (0, -1)); assert!(!apply_event_dd(&mut s, &ev(0, 0, 0), &codes), "SYN is not shown state"); - assert!(!apply_event_dd(&mut s, &ev(1, 0x12c, 1), &codes), "phantom button ignored (RS50)"); + assert!(!apply_event_dd(&mut s, &ev(1, 0x1ff, 1), &codes), "unknown button ignored (RS50)"); + assert!(apply_event_dd(&mut s, &ev(1, 0x12c, 1), &codes), "shifter gear 1 tracked (RS50)"); + assert_eq!(s.gear, 1); + assert!(s.shifter_connected); } #[test] @@ -427,11 +531,14 @@ mod tests { let codes: Vec = logi_wheel_core::evtest::button_codes_for_model(logi_wheel_core::WheelModel::G923); let mut s = Snapshot { buttons: vec![false; codes.len()], ..Snapshot::default() }; - assert!(apply_event_dd(&mut s, &ev(1, 0x2c3, 1), &codes), "tracked on a G923"); - assert!(apply_event_dd(&mut s, &ev(1, 0x2c4, 1), &codes), "tracked on a G923"); + assert!(apply_event_for(WheelModel::G923, &mut s, &ev(1, 0x2c3, 1), &codes), "tracked on a G923"); + assert_eq!(s.gear, 0, "G923 Plus must not be decoded as shifter gear"); + assert!(!s.shifter_connected, "shifter must not be marked connected on G923"); + assert!(apply_event_for(WheelModel::G923, &mut s, &ev(1, 0x2c4, 1), &codes), "tracked on a G923"); + assert_eq!(s.gear, 0, "G923 Minus must not be decoded as shifter gear"); // A descriptor-gap code the live G923 never actually sends is now // correctly absent from its own code list, so it is ignored - the // same as any code neither the wheel nor the code list knows. - assert!(!apply_event_dd(&mut s, &ev(1, 0x12c, 1), &codes), "gap code not tracked"); + assert!(!apply_event_for(WheelModel::G923, &mut s, &ev(1, 0x12c, 1), &codes), "gap code not tracked"); } } 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 884cff51..4eec2a4e 100644 --- a/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint +++ b/userspace/logi-wheel/crates/logi-wheel-gui/ui/app.slint @@ -228,6 +228,10 @@ export component App inherits Window { in property test-hat: "centered"; in property <[TestAxis]> test-axes: []; in property <[TestCallout]> test-callouts: []; + in property test-gear: 0; + in property test-gear-name: "N"; + in property test-shifter-connected: false; + in property test-shifter-mode: ""; in property test-sim-running: false; in property test-sim-error: ""; // The running (or just-finished) sequence's one-line summary (set @@ -779,6 +783,10 @@ export component App inherits Window { hat: root.test-hat; axes: root.test-axes; callouts: root.test-callouts; + gear: root.test-gear; + gear-name: root.test-gear-name; + shifter-connected: root.test-shifter-connected; + shifter-mode: root.test-shifter-mode; 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 4509c7e8..c0bd829f 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 @@ -64,6 +64,36 @@ component AxisBar inherits Rectangle { } } +// One circular gear slot badge for the H-pattern shifter gate. +component GateBadge inherits Rectangle { + in property label; + in property active: false; + in property is-reverse: false; + + width: 38px; + height: 38px; + border-radius: 19px; + border-width: 2px; + border-color: root.active ? (root.is-reverse ? #e0524a : Palette.accent-background) : Theme.panel-border; + background: root.active + ? (root.is-reverse ? #e0524a : Palette.accent-background) + : Theme.control-background; + + animate background { duration: 100ms; } + animate border-color { duration: 100ms; } + + Text { + text: root.label; + font-size: 14px; + font-weight: root.active ? 800 : 600; + horizontal-alignment: center; + vertical-alignment: center; + color: root.active + ? (root.is-reverse ? #ffffff : Palette.accent-foreground) + : Theme.text-color; + } +} + // The Info page: device identity (serial, firmware) on top, then the live // input monitor (the wheel image turning with the live steering angle, // per-button callout highlights, the full button list beside the image, @@ -118,6 +148,10 @@ export component InfoPage inherits Rectangle { in property <[TestButton]> buttons: []; in property hat: "centered"; in property <[TestAxis]> axes: []; + in property gear: 0; + in property gear-name: "N"; + in property shifter-connected: false; + in property shifter-mode: ""; // 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 @@ -661,6 +695,170 @@ export component InfoPage inherits Rectangle { } } + // Section: Logitech G RS H-Shifter (7+R Hall Effect) + Rectangle { + background: Theme.panel-background; + border-radius: Theme.panel-radius; + border-width: 1px; + border-color: Theme.panel-border; + + VerticalLayout { + padding: 14px; + spacing: 12px; + + HorizontalLayout { + alignment: space-between; + VerticalLayout { + spacing: 2px; + Text { + text: "H-Pattern Shifter (Logitech G RS H-Shifter)"; + font-size: 15px; + font-weight: 700; + color: Theme.text-color; + } + Text { + text: root.shifter-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; + } + } + 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 + : (root.gear == 8 ? #e0524a : Palette.accent-background); + } + } + } + + // Interactive 7-speed + Reverse H-gate pattern: + HorizontalLayout { + alignment: center; + Rectangle { + 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; + } + } + } + } + } + } + // Section: the two guarded force simulations. Rectangle { background: Theme.panel-background;