Skip to content

feat(cli): add openlogi haptic play for scriptable haptic pulses - #2662

Open
fahadjibransheikh wants to merge 8 commits into
AprilNEA:masterfrom
fahadjibransheikh:feat/haptic-play-cli
Open

fahadjibransheikh wants to merge 8 commits into
AprilNEA:masterfrom
fahadjibransheikh:feat/haptic-play-cli

Conversation

@fahadjibransheikh

Copy link
Copy Markdown
Contributor

Summary

Adds a scriptable way to play a haptic pulse on a device with HID++ 0x19b0
(MX Master 4): openlogi haptic play [tick|confirm] and openlogi api haptic.
Both go through a new agent IPC call that reuses the Actions Ring haptic
worker, so arming, the budget, the breaker and the restore ledger stay in one
place.

Use cases: a build or CI notification, a macro confirming it ran, and haptic
hover feedback for radial menus outside OpenLogi. I use it to tick on each slot
change of another app's ring.

Changes

  • core: HapticPulse wire enum (SubtleCollision, DampStateChange).
  • ipc: Agent::play_haptic(route, pulse) -> Result<(), WriteError>, appended;
    PROTOCOL_VERSION 46 → 47; golden test.
  • agent-core: reserve_session_id(), so client haptic sessions draw IDs from
    the same counter as ring sessions.
  • agent: the handler checks inventory first (DeviceNotFound,
    DeviceUnreachable, FeatureUnsupported{0x19b0}), then calls
    RingHapticPlayer::play_external, which runs on the existing worker and
    returns the result to the caller. Plays within 2 s on one device share a
    session: the first arms haptics if they were off, and the engine is restored
    2 s after the last play.
  • cli: openlogi haptic [--device NAME] play [tick|confirm] and
    openlogi api haptic --device <id> [--waveform tick|confirm]. Name-based
    agent device selection moved out of backlight into agent.rs so both use it
    (separate refactor commit, backlight behaviour unchanged).
  • docs: "Haptic feedback" section in USAGE.md.

Testing

  • Affected-package gate on macOS with RUSTFLAGS="-D warnings": cargo fmt --all -- --check; clippy --all-targets and cargo test over the 16 affected
    packages (4087 passed, 0 failed, 2 ignored); rustdoc; typos; ast-grep scan;
    cargo xtask release check-publish; both wasm checks; MSRV 1.99 check.
  • Linux clippy (aarch64-unknown-linux-musl) on hook, inject, hid, hidpp,
    core, ipc and permissions. Not run for agent and agent-core: ring needs a
    musl cross C toolchain I don't have. The diff adds no platform-gated code.
  • Agent tests cover: a burst on a haptics-off engine arms once, plays and
    restores; an engine already on gets no config writes; an unadvertised waveform
    is refused with nothing sent; the inventory refusals.
  • Runtime-tested on hardware: MX Master 4 over Bluetooth (046d:b042), macOS,
    dev agent. tick and confirm both play; the first play of a burst takes
    ~140 ms end to end (arming). Against the mock agent one CLI invocation takes
    ~6 ms.

…orker

Any client can now ask the agent to play one 0x19b0 waveform on a device
and hear how it went (protocol v47). Plays go through the Actions Ring's
single-flight haptic worker, so they coalesce with the ring's buzzes and
reuse its arming, budget, breaker, and restore ledger instead of a second
haptic path. Consecutive plays on one device share a session, so a
disarmed engine is turned on once per burst and handed back two seconds
after the last play; later plays cost one round-trip.
The haptic command needs the same human-facing selection, so it moves to
the agent module and takes the feature it selects for.
Scripts and other apps can buzz a 0x19b0 mouse through the agent: a
light tick by default, or a confirmation pulse.
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; the earlier arming loop is fixed.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the earlier arming loop is fixed.

Summary

Adds scriptable haptic pulses through the agent’s existing haptic worker.

  • Scripts can play a named haptic pulse from the command line.
  • The JSON API can request a haptic pulse for a chosen device.
  • The agent routes client pulses through the Actions Ring haptic worker.

The numbered previous finding is fixed. No new actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI haptic request] --> B[Check device inventory]
  B --> C[Join or open client burst]
  C --> D[Queue Play with its session and reply]
  D --> E[Worker selects one Play]
  E --> F[Arm its session if needed]
  F --> G[Play pulse and answer caller]
  G --> H[Run due restores]
  H --> E
Loading

Reviews (3) · Last reviewed commit: "fix(agent): arm at most one haptic sessi..." · Reviewed by Greptile

Comment thread crates/openlogi-agent/src/server.rs Resolved
Comment thread crates/openlogi-agent/src/server.rs Resolved
Comment thread crates/openlogi-agent/src/server.rs Resolved
Comment thread docs/USAGE.md Resolved
The client play scenarios awaited play_external, the shared feature
cache lock and their setup with no limit, so a regression that stranded
the worker's reply would hang the test job instead of failing it. Each
scenario now runs under a deadline once it holds the cache, and waits a
bounded time for it, as the replaced-device scenarios do.
…other

The restore ledger assumed one haptic session open at a time, but a
client burst and an Actions Ring can share a mouse. A burst opened under
an open ring took over the ring's restore, and its idle close turned the
engine off while the ring was still open; a ring closing inside a burst
did the same to the burst, whose later plays reported Ok unfelt.

The ledger now keeps one open session per lane (ring, client) and hands
an engine back only once no open session plays on it.

Arming no longer travels apart from the play it serves: every play
carries its session, and the worker arms a session it has not armed yet
before playing it, so a play queued behind another device's arming waits
for its own instead of playing into an engine still off.

The burst, the pause, and the hand-back request are one state with one
writer, Sessions: a burst cannot survive finish() or open while the
agent is leaving, so the first play after resume() arms again. A client
play while the agent is leaving answers AgentUnavailable, as nothing
arms then and its buzz may not be felt.
The burst's idle timer started when a play was queued, so a worker held
up past BURST_IDLE (a lost ring buzz plus an unreachable restore) let
the burst close while its first play still waited. The worker applies
closes first and never arms a closed session, so that play went out
unarmed and the client heard Ok for a buzz nobody felt. A burst now
counts the plays waiting on it and cannot close while any does; its
idle clock starts once the last is answered or abandoned.

A play is also queued under the lock that ordered its join, so plays
reach the worker in burst order and none carries a burst older than one
the worker may already have armed past.

The ring-inside-a-burst test now waits for the ring's arming before
closing it, so it covers an armed ring closing rather than one that
closed before the worker looked.
Comment thread crates/openlogi-agent/src/server.rs Resolved
play_newest re-armed for every newer play that arrived during an
arming, with no bound on the loop. Clients alternating between two mice
faster than arming completes opened a new burst with each play, so the
worker kept arming, played no pulse, and never reached the restores
after it.

A pass now arms at most one session and plays the play it armed for. A
play that arrived meanwhile stays queued for the next pass, so every
pass plays a pulse and reaches the restores, and nothing queued is lost.

This branch has not been deployed

No deployments
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