Skip to content

Conversation

@ruffsl
Copy link
Owner

@ruffsl ruffsl commented Dec 6, 2025

This pull request introduces a flexible multiplexing system for combining multiple controllers into a virtual gamepad, adding support for multiple input modes and refactoring the codebase to improve extensibility and clarity. The main changes include implementing three distinct multiplexing modes (Priority, Average, Toggle), updating the CLI and documentation to reflect these options, and refactoring event handling logic to use a trait-based approach for mode selection.

Multiplexing Modes and Event Handling

  • Refactored controller event handling in src/main.rs to delegate logic to a new trait-based MuxMode system, allowing selection of multiplexing strategies at runtime. ([src/main.rsL213-R235](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcL213-R235))
  • Added three multiplexing modes—Priority, Average, and Toggle—implemented as separate modules and exposed via the ModeType enum and a factory function in src/mux_modes/mod.rs. ([[1]](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-8cdc264ea0ddc74d038076240649a56576081357d53354b4b2654b0d05698dd9R1-R35), [[2]](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-10fd2248ed8f0ac54b7f24da8a12942a809275856d13a2c50201294571ee0915R1-R178))
  • Implemented the Average mode in src/mux_modes/average.rs, which blends analog and digital inputs from both controllers for cooperative or corrective play. ([src/mux_modes/average.rsR1-R178](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-10fd2248ed8f0ac54b7f24da8a12942a809275856d13a2c50201294571ee0915R1-R178))

CLI and User Documentation

  • Updated CLI options in src/main.rs to accept a --mode argument for selecting the desired multiplexing mode, with improved help output and argument parsing. ([[1]](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcL35-R46), [[2]](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcR72-R74), [[3]](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcR104))
  • Expanded the README.md to document the new multiplexing modes, provide usage examples for each, and clarify CLI subcommands and options. ([[1]](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L9-R33), [[2]](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L32-R66), [[3]](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R103-R118))

Miscellaneous

  • Updated the README to remove outdated references to previous mux mode implementations and clarify future development tasks. ([README.mdL120](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L120))

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request successfully refactors the controller multiplexing system to support multiple modes through a trait-based architecture, significantly improving the codebase's extensibility. The changes introduce three distinct multiplexing strategies (Priority, Average, Toggle) while maintaining backward compatibility with Priority as the default mode. The refactoring moves from monolithic event handling in main.rs to a modular, plugin-style architecture using the MuxMode trait.

Key changes:

  • Introduced a trait-based multiplexing system with three modes (Priority, Average, Toggle) implemented as separate modules
  • Refactored main.rs to delegate event handling to mode implementations via the MuxMode trait
  • Updated CLI to accept a --mode parameter for runtime mode selection
  • Enhanced README documentation with detailed descriptions of each mode and usage examples

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
src/mux_modes/mod.rs Defines the MuxMode trait, ModeType enum, and factory function for creating mode instances
src/mux_modes/priority.rs Implements Priority mode where assist controller overrides primary when active (default behavior)
src/mux_modes/average.rs Implements Average mode that blends inputs from both controllers; contains critical unwrap() bugs
src/mux_modes/toggle.rs Implements Toggle mode for switching between controllers via Mode button
src/main.rs Refactored to use trait-based delegation; improved CLI with mode parameter; removed 150+ lines of inline event handling
README.md Added comprehensive mode documentation, usage examples, and CLI help output; contains outdated TODO reference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +48 to +54
gilrs::EventType::ButtonPressed(button, _)
| gilrs::EventType::ButtonReleased(button, _) => {
if let Some(key) = evdev_helpers::gilrs_button_to_evdev_key(button) {
let value = matches!(event.event, gilrs::EventType::ButtonPressed(..)) as i32;
events.push(InputEvent::new(evdev::EventType::KEY.0, key.0, value));
}
}
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Significant code duplication: The event conversion logic for ButtonPressed/ButtonReleased (lines 48-53) is nearly identical across all three mode implementations. Consider extracting this into a shared helper function in the mux_modes module to reduce duplication and improve maintainability.

Suggested change
gilrs::EventType::ButtonPressed(button, _)
| gilrs::EventType::ButtonReleased(button, _) => {
if let Some(key) = evdev_helpers::gilrs_button_to_evdev_key(button) {
let value = matches!(event.event, gilrs::EventType::ButtonPressed(..)) as i32;
events.push(InputEvent::new(evdev::EventType::KEY.0, key.0, value));
}
}
gilrs::EventType::ButtonPressed(_, _)
| gilrs::EventType::ButtonReleased(_, _) => {
if let Some(ev) = convert_button_event_to_evdev(&event.event) {
events.push(ev);
}
}

Copilot uses AI. Check for mistakes.
@ruffsl ruffsl merged commit a958570 into main Dec 6, 2025
1 check passed
@ruffsl ruffsl deleted the assist-modes branch December 6, 2025 22:32
ruffsl added a commit that referenced this pull request Dec 6, 2025
* Wording

* docs: highlight help flag for discoverability

* feat: refactor mux modes into separate modules

* feat: implement ToggleMode with event handling logic

* docs: add todo macro for average mux mode

* docs: enhance README with detailed multiplexing modes and usage examples

* refactor: streamline ToggleMode event handling and initialization logic

* refactor: simplify event handling logic in PriorityMode

* feat: implement AverageMode event handling logic

* docs: clarify Average mode axes behavior in README

* feat: add constructors for AverageMode and PriorityMode

* refactor: simplify mux mode handling using trait objects

- Remove ModeHandler enum and its MuxMode implementation
- Update make_mode_handler to return Box<dyn MuxMode> for dynamic dispatch
- Streamline mode handler creation and event handling
- Improve extensibility and idiomatic Rust usage for adding new muxing modes

* refactor: rename mode handler factory to create_mux_mode for clarity

* doc: clarify comments

* refactor: simplify constructors for AverageMode, PriorityMode, and ToggleMode

* refactor: remove unnecessary constructors from AverageMode, PriorityMode, and ToggleMode

* refactor: update CLI defaults to match enum defaults

* doc: clean up help messages

* refactor: consolidate deadzone functions in AverageMode and PriorityMode

* doc: clarify toggle controller functionality in README

* refactor: improve averaging logic for button values in AverageMode

* refactor: enhance axis value averaging logic in AverageMode

* refactor: extract DPad axis pair logic into a helper function

* style: cargo format code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants