Skip to content

Fix pan/tilt with a negative value and make profile apply reliable - #151

Open
nbougaieff wants to merge 2 commits into
itaybre:masterfrom
nbougaieff:fix-profile-apply-and-pantilt
Open

nbougaieff wants to merge 2 commits into
itaybre:masterfrom
nbougaieff:fix-profile-apply-and-pantilt

Conversation

@nbougaieff

Copy link
Copy Markdown

Two fixes for applying a saved profile, found with a Logitech C922. One commit each.

Pan/tilt: a negative second value corrupts the first

UVCMultipleIntControl combines the two values with an addition. When the second value is negative it borrows from the first, so writing (1, -1) sends 3599 arcseconds instead of 3600 for the first value. On the C922 the camera then stays at 0:

wanted master this branch
(1, -1) (0, -1) (1, -1)
(2, -2) (1, -2) (2, -2)
(0, -1), (1, 1), (-1, 1), (-2, -2) correct correct

The fix masks the second value to its own 4 bytes before combining. #148 and #150 both touch these two lines (parentheses, wrapping operators) but keep the addition, so as far as I can tell they do not change this result.

Profiles are not applied reliably

DeviceController.set assigns each property, and every property setter starts its own unstructured Task. The writes therefore reach the camera in no fixed order, and a manual value can arrive before its auto mode has been turned off, in which case the camera rejects it. A value equal to the cached one is also skipped, although the cache can be stale after the camera has been in auto mode.

Test: reset to defaults, apply a profile with every control set to a non-default value, wait, then read every control back from the device. Two different profiles alternating, 6 rounds per run.

  • master, 2 runs (12 rounds): white balance was not applied in 3 rounds and exposure time in 1; pan was wrong in all 12.
  • this branch, 3 runs (18 rounds): every value correct in every round.

The fix writes the values one after another on a single task, auto modes first, without comparing against the cache. Manual values are read back and retried for up to about a second, because a camera can ignore a write that comes right after auto mode is switched off. A value whose auto mode is on in the profile is written once and not retried. The published values are updated on the main actor after the write, so the sliders follow.

Only the set path is changed. write(), reset() and writeValues() are untouched, to stay out of the way of #148.

Testing

  • Logitech C922 Pro Stream, macOS 15.7.4, Xcode 26.3, arm64.
  • Run through a temporary launch-time harness that reads the controls back from the device. The harness is not part of this PR.
  • Not tested: clicking through the UI, other cameras, and the unit test target.

🤖 Generated with Claude Code

nbougaieff and others added 2 commits December 1, 2026 21:37
The two values were combined with an addition, so a negative second
value borrowed from the first: writing (1, -1) sent 3599 arcseconds
instead of 3600 for the first value and the camera did not move to it.
Mask the second value to its own 4 bytes before combining.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Applying a profile started one unstructured Task per value, so the
writes reached the camera in no fixed order and a manual value could
arrive before its auto mode was turned off. A value equal to the cached
one was also skipped, although the cache can be stale after auto mode.

Write the values one after another on a single task, auto modes first,
without comparing against the cache. Manual values are read back and
retried for a short time, since a camera can ignore a write that comes
right after auto mode is switched off.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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