Skip to content

fix: auto-detect hidraw input interface in debug tool - #19

Merged
BANANASJIM merged 1 commit into
mainfrom
fix/debug-hidraw-interface
Mar 8, 2026
Merged

fix: auto-detect hidraw input interface in debug tool#19
BANANASJIM merged 1 commit into
mainfrom
fix/debug-hidraw-interface

Conversation

@BANANASJIM

@BANANASJIM BANANASJIM commented Mar 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Debug tool now auto-detects the correct input interface instead of hardcoding interface 0
  • Adds --input N and --config N CLI args for manual override
  • Returns clear error if no valid input interface is found

Changes

  • include/vader5/debug_options.hpp: CLI argument parsing with input validation
  • src/tools/debug.cpp: Replace hardcoded IFACE_INPUT=0 with auto-detection; probe interfaces 0,2,3 for valid HID reports
  • src/tools/test_debug_iface.cpp: Test suite for CLI argument parsing
  • CMakeLists.txt: Add test target

Test plan

  • test-debug-iface passes — verifies CLI parsing (defaults, overrides, unknown args)
  • Manual: run vader5-debug with a controller on a non-standard interface
  • Manual: run vader5-debug --input 2 to verify CLI override

Closes #17

Summary by CodeRabbit

Release Notes

  • New Features

    • Debug tool now supports command-line options (--input, --config) for explicit interface selection.
    • Added automatic detection of input interfaces for improved usability.
    • Enhanced runtime interface configuration parsing and handling.
  • Tests

    • Added comprehensive test suite validating debug interface options and configuration parsing.

@coderabbitai

coderabbitai Bot commented Mar 8, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@BANANASJIM has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 9 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2976c22e-1391-4ffd-b494-c5fabbc21978

📥 Commits

Reviewing files that changed from the base of the PR and between a3287f9 and 5574d21.

📒 Files selected for processing (4)
  • CMakeLists.txt
  • include/vader5/debug_options.hpp
  • src/tools/debug.cpp
  • src/tools/test_debug_iface.cpp
📝 Walkthrough

Walkthrough

This PR adds runtime interface configuration for the debug tool, introducing a DebugOptions struct for CLI argument parsing with --input and --config flags. The debug tool now auto-detects available input interfaces and accepts explicit interface parameters, replacing hardcoded interface values.

Changes

Cohort / File(s) Summary
Build Configuration
CMakeLists.txt
Added new CMake target test-debug-iface executable with clang-tidy disabled and private include directories for testing CLI option parsing.
CLI Options Parsing
include/vader5/debug_options.hpp, src/tools/test_debug_iface.cpp
Introduced DebugOptions struct with input_iface and config_iface fields, static parse() method for argument parsing supporting --input and --config flags with error handling. Added test suite validating CLI parsing behavior for defaults, overrides, and edge cases.
Debug Tool Implementation
src/tools/debug.cpp
Refactored main entry point to accept argc/argv and use DebugOptions parsing. Added find_input_interface() for auto-detecting input interface by probing interfaces 0, 2, and 3. Updated open_hidraw_input() and open_hidraw_config() to accept explicit interface parameters. Replaced hardcoded interface constants with runtime discovery.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

Hop, hop! No more fixed paths we take,
With auto-detect, we adapt and wake,
Pick your interface with flags so bright,
Flexible debugging—feels so right! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: auto-detect hidraw input interface in debug tool' accurately describes the main objective of the PR: adding auto-detection for the hidraw input interface, replacing hardcoded values.
Linked Issues check ✅ Passed The PR fully addresses issue #17 by implementing auto-detection of hidraw interfaces (probing 0, 2, 3), adding CLI argument override support (--input, --config), and removing hardcoded interface constants.
Out of Scope Changes check ✅ Passed All changes are directly related to the PR objectives: auto-detection logic, CLI parsing, test coverage for argument handling, and CMake configuration for the new test executable.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/debug-hidraw-interface

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Remove hardcoded IFACE_INPUT=0 and IFACE_CONFIG=1 constants.
Add auto-detection that probes interfaces {0, 2, 3} for valid input
reports, with --input and --config CLI overrides.
@BANANASJIM
BANANASJIM force-pushed the fix/debug-hidraw-interface branch from a3287f9 to 5574d21 Compare March 8, 2026 00:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/tools/test_debug_iface.cpp (1)

6-6: Consider using a testing framework or returning status codes.

The CHECK macro using std::exit(1) works but makes it impossible to test error paths (like invalid values) since DebugOptions::parse also calls std::exit(1).

For a small utility test this is acceptable, but if tests grow, consider a framework that can capture exit calls or refactoring parse to return an error type instead of exiting.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/tools/test_debug_iface.cpp` at line 6, The test harness currently
hard-exits via the CHECK macro and DebugOptions::parse, preventing testing of
error paths; refactor so parse returns an error status (e.g.,
bool/enum/std::optional/Expected) instead of calling std::exit(1), update all
callers to handle and assert on that return, and change the CHECK macro in
test_debug_iface.cpp to record failures (set a local failure flag or return a
non-zero status) instead of calling std::exit so multiple assertions and
invalid-input cases can be exercised; alternatively, replace the custom harness
with a lightweight test framework (e.g., Catch2/GoogleTest) to capture failures
and exit behavior.
include/vader5/debug_options.hpp (1)

23-26: Consider printing the actual invalid value in error message.

The error message shows the flag name but not the invalid value, which would help users debug their command.

📝 Improved error message
-            } catch (const std::exception&) {
-                std::cerr << "Invalid value for " << arg << "\n";
+            } catch (const std::exception& e) {
+                std::cerr << "Invalid value for " << arg << ": " << argv[i] << "\n";
                 std::exit(1);
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/vader5/debug_options.hpp` around lines 23 - 26, The catch block
catching std::exception in include/vader5/debug_options.hpp currently logs only
the flag name (arg); update the catch to capture the exception (e.g., catch
(const std::exception& e)) and augment the error message to include the actual
invalid token/value that was being parsed (the variable holding the parsed
value) along with the flag name and the exception message (e.what()) so the
output reads something like "Invalid value for <arg>: '<value>' - <exception
message>" to aid debugging.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@include/vader5/debug_options.hpp`:
- Around line 18-22: The argument-parsing branch that handles "--input" and
"--config" silently ignores these flags when they are last because it checks "i
+ 1 < argc" and does nothing on failure; update the parsing logic around the
loop over argv (use the same argv/argc and loop variable i) to detect the
missing value case and report a clear error (e.g., print an error message and
exit or throw) when "--input" or "--config" is provided without a following
value instead of silently skipping, ensuring you still assign to
opts.input_iface and opts.config_iface when a value exists.

---

Nitpick comments:
In `@include/vader5/debug_options.hpp`:
- Around line 23-26: The catch block catching std::exception in
include/vader5/debug_options.hpp currently logs only the flag name (arg); update
the catch to capture the exception (e.g., catch (const std::exception& e)) and
augment the error message to include the actual invalid token/value that was
being parsed (the variable holding the parsed value) along with the flag name
and the exception message (e.what()) so the output reads something like "Invalid
value for <arg>: '<value>' - <exception message>" to aid debugging.

In `@src/tools/test_debug_iface.cpp`:
- Line 6: The test harness currently hard-exits via the CHECK macro and
DebugOptions::parse, preventing testing of error paths; refactor so parse
returns an error status (e.g., bool/enum/std::optional/Expected) instead of
calling std::exit(1), update all callers to handle and assert on that return,
and change the CHECK macro in test_debug_iface.cpp to record failures (set a
local failure flag or return a non-zero status) instead of calling std::exit so
multiple assertions and invalid-input cases can be exercised; alternatively,
replace the custom harness with a lightweight test framework (e.g.,
Catch2/GoogleTest) to capture failures and exit behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1cf0d953-0937-4f62-98c7-37417255aa83

📥 Commits

Reviewing files that changed from the base of the PR and between f8649eb and a3287f9.

📒 Files selected for processing (4)
  • CMakeLists.txt
  • include/vader5/debug_options.hpp
  • src/tools/debug.cpp
  • src/tools/test_debug_iface.cpp

Comment on lines +18 to +22
if (arg == "--input" && i + 1 < argc) {
opts.input_iface = std::stoi(argv[++i]);
} else if (arg == "--config" && i + 1 < argc) {
opts.config_iface = std::stoi(argv[++i]);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Missing value for --input/--config is silently ignored.

If a user passes --input or --config as the last argument without a value, the condition i + 1 < argc fails silently and the flag is ignored. This could confuse users who misspell or forget the value.

🛠️ Proposed fix to report an error for missing values
             try {
                 if (arg == "--input" && i + 1 < argc) {
                     opts.input_iface = std::stoi(argv[++i]);
+                } else if (arg == "--input") {
+                    std::cerr << "Error: --input requires a value\n";
+                    std::exit(1);
                 } else if (arg == "--config" && i + 1 < argc) {
                     opts.config_iface = std::stoi(argv[++i]);
+                } else if (arg == "--config") {
+                    std::cerr << "Error: --config requires a value\n";
+                    std::exit(1);
                 }
             } catch (const std::exception&) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (arg == "--input" && i + 1 < argc) {
opts.input_iface = std::stoi(argv[++i]);
} else if (arg == "--config" && i + 1 < argc) {
opts.config_iface = std::stoi(argv[++i]);
}
if (arg == "--input" && i + 1 < argc) {
opts.input_iface = std::stoi(argv[++i]);
} else if (arg == "--input") {
std::cerr << "Error: --input requires a value\n";
std::exit(1);
} else if (arg == "--config" && i + 1 < argc) {
opts.config_iface = std::stoi(argv[++i]);
} else if (arg == "--config") {
std::cerr << "Error: --config requires a value\n";
std::exit(1);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/vader5/debug_options.hpp` around lines 18 - 22, The argument-parsing
branch that handles "--input" and "--config" silently ignores these flags when
they are last because it checks "i + 1 < argc" and does nothing on failure;
update the parsing logic around the loop over argv (use the same argv/argc and
loop variable i) to detect the missing value case and report a clear error
(e.g., print an error message and exit or throw) when "--input" or "--config" is
provided without a following value instead of silently skipping, ensuring you
still assign to opts.input_iface and opts.config_iface when a value exists.

@BANANASJIM
BANANASJIM merged commit 9170223 into main Mar 8, 2026
5 checks passed
@BANANASJIM
BANANASJIM deleted the fix/debug-hidraw-interface branch March 13, 2026 21:13
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.

Debug tool fails to find the correct hidraw interfaces

1 participant