Skip to content

Instantly share code, notes, and snippets.

@DonaldKellett
Last active February 16, 2023 02:54
Show Gist options
  • Save DonaldKellett/93d5fa1323e2e5f950a61f72c8d6ba82 to your computer and use it in GitHub Desktop.
Save DonaldKellett/93d5fa1323e2e5f950a61f72c8d6ba82 to your computer and use it in GitHub Desktop.
Disable autofocus and specify absolute focus for Logitech c930e with udev and systemd (Fedora 35 Workstation)
KERNEL=="video[0-9]*", SUBSYSTEM=="video4linux", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="0843", TAG+="systemd", ENV{SYSTEMD_WANTS}="logitech-c930e@$env{MINOR}.service"

Logitech c930e initialization rule

The Logitech c930e has autofocus enabled by default, which fails to focus on objects close to the camera after relaxing the focus to distant objects. This is usually not much of a problem in video meetings, but for use cases such as online proctored exams where the invigilator requests an identity document to be presented close to the camera, this lack of focus can render the text on the identity document unreadable, making the camera useless for such exams.

This gist corrects the issue by disabling autofocus and manually setting the focus so that close-up text can be seen clearly, yet distant objects do not appear too blurry.

This solution has been tested on Fedora 35 Workstation, though it can probably be used on many other Linux distributions as well with minimal modification. In particular, for Ubuntu 20.04, replace focus_automatic_continuous with focus_auto.

Prerequisites

Ensure the v4l-utils package is installed.

Usage

  1. Place the file 90-logitech-c930e.rules under /etc/udev/rules.d

  2. Place the file logitech-c930e@.service under /etc/systemd/system

  3. Place the file logitech-c930e.sh under /root and mark it executable

  4. Restart systemd-udevd.service and reload systemd:

    $ sudo systemctl restart systemd-udevd.service
    $ sudo systemctl daemon-reload
  5. Unplug and re-plug your Logitech c930e webcam. The rules should now be effective. Enjoy ;-)

References

Related questions

License

CC0 (public domain)

#!/bin/bash
if [[ $# -ne 1 ]]; then
echo "Expected minor device number as sole argument" 1>&2
exit 1
fi
while true; do
v4l2-ctl -d $1 --set-ctrl focus_automatic_continuous=0
v4l2-ctl -d $1 --set-ctrl focus_absolute=75
sleep 5
done
[Unit]
Description=Disable autofocus and set absolute focus for Logitech c930e
[Service]
ExecStart=/bin/bash -c "/root/logitech-c930e.sh %I"
[Install]
WantedBy=multi-user.target
@markstos
Copy link

I've been slowing rolling out Ansible at work and it's been a great experience. My team likes the tool and it can be introduced organically without an all at once push. We are getting closer to completely defining servers with Ansible. Ansible has also been useful to help junior developers make proposed DevOps changes as Ansible playbooks, with a senior developer reviewing them because our server definitions get updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment