Read the lid sensor on its own cadence, in hundredths of a degree - #25
Merged
Merged
Conversation
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.
|
@ReffWu is attempting to deploy a commit to the MagicAPI Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reachedNext included review available in 55 minutes. View limit detailsLimit 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. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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, andmake build.