Skip to content

Add support for config flag input. - #17

Merged
mlstr0m merged 1 commit into
mlstr0m:mainfrom
jwhpryor:argparse
Sep 28, 2026
Merged

mlstr0m merged 1 commit into
mlstr0m:mainfrom
jwhpryor:argparse

Conversation

@jwhpryor

Copy link
Copy Markdown
Contributor

There's no mechanism to launch multiple controller servers because you can't specify a different server port.

By allowing the user to target a config file, users can create multiple servers on different ports and connect to multiple controllers at once.

mlstr0m commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Thanks! Checked this against current main (v1.3.0): it merges cleanly and the tests pass. Tried --config end to end: a missing parent directory is created, the DSU port from the file is used after a reload, the DSU toggle persists into the chosen file, ~ expands, and -psn_* is ignored. 👍

A few things before merging:

  1. parse_known_args also swallows typos: --conifg x.json silently falls back to the default file. Could the app keep only -psn_* out and reject other unknown args?
  2. A new config file starts on port 26760, so two instances with fresh configs collide until one file is edited. A README note on --config, open -n -a "Switch2 Bridge" --args --config … and per-instance ports would help.
  3. All instances share ~/Library/Logs/Switch2Bridge/bridge.log, and RotatingFileHandler isn't multi-process safe. Maybe name the log after the config file?
  4. For multi-controller use, nothing picks which controller an instance takes: _find_controller returns the first match, so two instances can target the same pad. Untested on hardware, but a ble.address pin in the config would make this deterministic.
  5. Minor: the title says "Fix", but it's a new feature, and a small test would be welcome.

Generated by Claude Code

@jwhpryor jwhpryor changed the title Fix config flag input. Add support for config flag input. Sep 28, 2026
@jwhpryor

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look. I pointed Gemini at it and I think I've got everything addressed. PTAL

mlstr0m commented Sep 28, 2026

Copy link
Copy Markdown
Owner

Thanks, this addresses everything, nice work! Merged locally on current main (v1.3.0): no conflicts, all tests pass (143 bridge + 52 DSU checks). Merging now.

Two small follow-ups I'll handle separately, nothing for you to do:

  • the new tests call setup_logging(), which writes to the real ~/Library/Logs/Switch2Bridge/ (controller2.log) and leaves a handler on the real bridge.log
  • Mappings.set_address() is only used by the tests

Generated by Claude Code

@mlstr0m
mlstr0m merged commit 6f94cd1 into mlstr0m:main Sep 28, 2026
mlstr0m pushed a commit that referenced this pull request Sep 28, 2026
Follow-up to #17:
- the setup_logging tests now point LOG_DIR at a temp dir and detach
  their handler afterwards, instead of creating controller2.log in the
  real ~/Library/Logs/Switch2Bridge and leaving a handler on bridge.log
- Mappings.set_address() had no caller outside its own test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SGsFjHBorX2mfsanZhFyzs
mlstr0m added a commit that referenced this pull request Sep 28, 2026
…ess (#20)

Follow-up to #17: the setup_logging tests use a temp LOG_DIR and detach
their handler; Mappings.set_address() had no caller outside its test.
mlstr0m added a commit that referenced this pull request Sep 28, 2026
* Fix C/Capture swap, read factory stick calibration, hardening (v1.3.0)

Protocol (sources cited in code and README):
- Byte 4 of the input report: Capture is 0x02 and C is 0x10, not the
  reverse. Agreed by ndeadly/switch2_controller_research (hid_reports.md),
  esp-cpp/espp PR #765 (switch2_pro_report.hpp) and the hardware capture
  in issue #14. Also fixes Capture -> DSU Touch.
- Read the factory stick calibration over the command channel
  (649d4ac9-...f005 / replies c765a961-...) and light player LED 1.
  Frame format, SPI addresses 0x130A8/0x130E8 and block layout adapted
  from kennethreitz/switch2bridge-macos@975f329 (issue #14, MIT), based on
  darthcloud/BlueRetro#1249; addresses match SDL's Switch 2 driver.
  Best effort: a silent controller keeps the nominal 2048 range.
- README: 7492866c-...c0f8 is notify-only, document the command channel.

Hardening:
- mappings.json written atomically (temp file + os.replace)
- "dsu.enabled" must be a boolean (bool("false") was True)
- warn when the DSU server is bound to a non-loopback address
- DSU socket: drop SO_REUSEADDR (useless for UDP; on Linux it let a
  second server silently share the port)
- worker -> UI messages taken atomically; stick hysteresis read under lock
- asyncio.get_running_loop(); logging set up at startup, not import

Build: Python 3.10+ (bleak 3 requires it), major-version upper bounds,
py2app moved to requirements-build.txt, CI matrix 3.10/3.12/3.13,
DMG README explains the macOS 15+ Gatekeeper "Open Anyway" flow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SGsFjHBorX2mfsanZhFyzs

* Add a manual Release workflow and the v1.3.0 release notes

Actions → Release → Run workflow (tag input): checks the tag matches
APP_VERSION and doesn't exist yet, runs the tests, builds the DMG, then
creates the tag and the GitHub release with the DMG attached, using
.github/release-notes/<tag>.md as the body with {{SHA256}} replaced by
the DMG checksum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SGsFjHBorX2mfsanZhFyzs

* Tests: keep setup_logging out of ~/Library/Logs; drop unused set_address

Follow-up to #17:
- the setup_logging tests now point LOG_DIR at a temp dir and detach
  their handler afterwards, instead of creating controller2.log in the
  real ~/Library/Logs/Switch2Bridge and leaving a handler on bridge.log
- Mappings.set_address() had no caller outside its own test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SGsFjHBorX2mfsanZhFyzs

* Tidy the repo: lint in CI, cleaner .gitignore, README dev docs

- ruff (pyflakes, bugbear, pyupgrade) configured in ruff.toml and run as
  a CI job; fixed its four findings: `raise ... from None` in config
  validation, `socket.timeout` -> `TimeoutError` (alias since 3.10)
- .gitignore: drop duplicated entries, English comments, ignore .ruff_cache
- README: project structure lists .github/ (CI, release workflow, notes)
  and ruff.toml; new Development section (tests, lint, release steps);
  DriverKit is a system extension needing a paid developer account, not
  "kernel-level" / "not possible"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SGsFjHBorX2mfsanZhFyzs

---------

Co-authored-by: Claude <noreply@anthropic.com>
mlstr0m pushed a commit that referenced this pull request Sep 28, 2026
Covers #17 (--config, ble.address, per-config logs), #20, #21 (lint in
CI) and #22 (…f8 known input characteristic).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SGsFjHBorX2mfsanZhFyzs
@mlstr0m mlstr0m mentioned this pull request Sep 28, 2026
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