Skip to content

Read the lid sensor on its own cadence, in hundredths of a degree - #25

Merged
pulkitxm merged 2 commits into
Noveum:mainfrom
ReffWu:sensor-cadence
Sep 15, 2026
Merged

pulkitxm merged 2 commits into
Noveum:mainfrom
ReffWu:sensor-cadence

Conversation

@ReffWu

@ReffWu ReffWu commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

The lid angle sensor only refreshes its value about every 98 ms, so polling it 120 times a second while Hinge is on mostly re-reads the same whole-degree value.

The reader now prefers feature report 7, which carries hundredths of a degree, with report 1 as the fallback for sensors without it. It follows the sensor's refresh instead of a fixed rate: it learns the period and phase from a change seen right after an unchanged read, reads 6 ms before the next refresh on a strict timer, and repeats every 3 ms until the value changes. A refresh that repeats its value keeps the phase, and after five quiet periods the reader falls back to every 25 ms until the next change. Only changed readings reach LidMotion, so it now holds its velocity for 120 ms after a reading instead of 25 ms. With the effect off, the sensor is still read every 100 ms.

Measured on a 16-inch M1 Max:

  • Against a 1 ms reference poller in a separate process, the reader caught all 206 of 206 value changes while reading about 34 times a second.
  • The reader's CPU use fell from 4.1 to 1.4 percent of one core.
  • A replay of 30, 90 and 200 degree per second closes with the sensor's real refresh kept the p95 lag at 96 to 98 ms, against 93 to 101 ms before, and slow closes came out smoother.

One interaction to flag: #21 decides that the lid has settled from the readings it receives. Since this branch stops forwarding repeated values, a lid at rest sends no further readings, so that check would need a time-based trigger, or the reader could forward one repeat per refresh. Happy to do either here if both land.

Validated with swift-format lint --strict Sources/*.swift, python3 scripts/check.py policy, and make build.

The sensor only refreshes its value about every 98 ms, so polling it 120
times a second while Hinge was on mostly re-read the same whole-degree
value. The reader now prefers feature report 7, which carries hundredths
of a degree, and follows the sensor's refresh: it learns the period and
phase from a change seen right after an unchanged read, reads 6 ms before
the next refresh, and repeats every 3 ms until the value changes. A
refresh that repeats its value keeps the phase, and after five quiet
periods the reader falls back to every 25 ms.

On an M1 Max the reader caught every change a 1 ms reference poll saw
while reading about 34 times a second, and its CPU use fell from 4.1 to
1.4 percent of one core. Only changed readings reach the motion estimator
now, so it holds its velocity for 120 ms after a reading instead of 25 ms.
A replay of 30, 90 and 200 degree per second closes with the sensor's
real refresh kept the p95 lag at 96 to 98 ms and made slow closes
smoother.
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

@ReffWu is attempting to deploy a commit to the MagicAPI Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 662ac8dd-342b-4d5c-b43b-27355d22123a

📥 Commits

Reviewing files that changed from the base of the PR and between c731b0f and a025de8.

📒 Files selected for processing (4)
  • MOTION.md
  • README.md
  • Sources/LidMotion.swift
  • Sources/LidSensor.swift

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

@pulkitxm
pulkitxm merged commit a23baed into Noveum:main Sep 15, 2026
2 of 3 checks passed
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