-
Notifications
You must be signed in to change notification settings - Fork 0
Modularize for multiple multiplexing modes #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 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
There was a problem hiding this 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
--modeparameter 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.
| 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)); | ||
| } | ||
| } |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
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.
| 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); | |
| } | |
| } | |
…ode, and ToggleMode
* 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
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
src/main.rsto delegate logic to a new trait-basedMuxModesystem, allowing selection of multiplexing strategies at runtime. ([src/main.rsL213-R235](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcL213-R235))ModeTypeenum and a factory function insrc/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))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
src/main.rsto accept a--modeargument 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))README.mdto 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
[README.mdL120](https://github.com/ruffsl/CtrlAssist/pull/3/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L120))