Skip to content

Add support for nudging devices#1

Merged
freezy merged 5 commits into
masterfrom
feature/nudge
Jul 4, 2026
Merged

Add support for nudging devices#1
freezy merged 5 commits into
masterfrom
feature/nudge

Conversation

@freezy

@freezy freezy commented Jul 4, 2026

Copy link
Copy Markdown
Member

This PR adds native HID axis support for cabinet nudge hardware, especially KL25Z / Pinscape-style accelerometer devices.

  • Bumps the NativeInput ABI protocol to v2.
  • Adds axis input events alongside existing action/button events.
  • Adds device and axis enumeration APIs with stable device IDs, display names, axis metadata, raw values, and timestamps.
  • Implements Windows HID joystick/gamepad/multi-axis polling.
  • Normalizes signed HID values correctly, fixing negative accelerometer spikes from devices like KL25Z.
  • Skips HID null-state readings and tightens overlapped I/O shutdown/lifecycle handling.
  • Keeps non-Windows backends ABI-compatible with stubbed axis listing/events.

freezy added 3 commits July 4, 2026 16:07
- Sign-extend raw usage values from the report bit width when the logical
  range is signed (HidP_GetUsageValue does not sign-extend), fixing
  full-scale spikes for negative accelerometer readings.
- Skip null-state readings on axes that declare HasNull.
- Wait for cancelled overlapped reads to complete before freeing the
  OVERLAPPED and report buffer on device close.
- Guard key bindings with a mutex against concurrent rebinding.
- Serve device/axis listings from the live polling snapshot so device
  indices stay consistent with axis events.
- Keep the timestamp epoch stable across re-initialization and guard
  against uninitialized QPC frequency.
- Open devices with zero access rights for listing-only queries.
@freezy freezy self-assigned this Jul 4, 2026
@greptile-apps

greptile-apps Bot commented Jul 4, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds native HID axis support for nudge devices. The main changes are:

  • Native input protocol version 2 and expanded event structs.
  • Device and axis enumeration APIs.
  • Windows HID polling for joystick, gamepad, and multi-axis devices.
  • Hotplug reconciliation for disconnected HID devices.
  • Stubbed axis APIs for non-Windows backends.
  • Windows build updates for HID libraries and target-version macros.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
src/NativeInput_Windows.cpp Adds Windows HID axis polling, device listing, hotplug reconciliation, and protocol acknowledgement before polling.
src/NativeInput.h Defines protocol version 2, event types, device descriptors, axis descriptors, and new enumeration APIs.
CMakeLists.txt Links the Windows HID dependencies and sets explicit Windows target-version definitions.
.github/workflows/build-and-publish.yml Pins Windows CI builds to the VS 2022 runner image.
src/NativeInput_Linux.cpp Adds protocol acknowledgement and stubbed device and axis listing while preserving action polling.
src/NativeInput_Mac.mm Adds protocol acknowledgement and stubbed device and axis listing while preserving action polling.
src/NativeInput_Stub.cpp Exports the new protocol and device-axis API surface for unsupported platforms.
README.md Updates the usage example to check native input protocol version 2 before polling.

Reviews (2): Last reviewed commit: "input: tighten protocol and Windows buil..." | Re-trigger Greptile

Comment thread src/NativeInput_Windows.cpp
Comment thread src/NativeInput_Windows.cpp
Comment thread src/NativeInput.h
freezy added 2 commits July 4, 2026 23:48
Devices unplugged mid-session used to leave a dead handle retrying a
failing ReadFile every poll tick, and devices plugged in after polling
started were never seen until restart.

- Detect removal via read failures: close the handle, mark the slot
  disconnected and request reconciliation.
- Probe the present HID interface list (CM_Get_Device_Interface_ListW,
  much cheaper than a SetupDi pass) every 2s; reconcile only when the
  list actually changed or a read failed, with a 250ms debounce on
  failure-triggered checks and retries for transient open failures.
- Reconciliation keeps device indices stable: missing devices keep
  their slot and report isConnected=0, re-plugged devices reopen in
  place, new joystick-style devices are appended.
- Emit VPE_INPUT_EVENT_DEVICES_CHANGED through the existing callback so
  consumers know to refresh their device list; the event layout is
  unchanged and older consumers ignore the new type.
@freezy freezy merged commit 32d8e54 into master Jul 4, 2026
9 checks passed
@freezy freezy deleted the feature/nudge branch July 4, 2026 22:08
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.

1 participant