Skip to content

Sensors

Federico Di Pierro edited this page Jun 9, 2023 · 25 revisions

Sensors support

Clightd supports various different sensors to capture ambient backlight. It offers an unified API to use these sensors under /org/clightd/clightd/Sensor: Capture and IsAvailable. When using these methods, if no device is specified, first supported sensor found will be used.
Obviously, ALS devices have higher priority as they are less power hungry and offer better results.
This is the priority list:

  • ALS
  • YoctoLight
  • Pipewire (since Clightd 5.5)
  • Camera
  • Custom (since Clightd 4.1)

API also offers specific paths for each sensor: /org/clightd/clightd/Sensor/Als, /org/clightd/clightd/Sensor/YoctoLight, /org/clightd/clightd/Sensor/Pipewire, /org/clightd/clightd/Sensor/Camera and /org/clightd/clightd/Sensor/Custom implement org.clightd.clightd.Sensor interface, but only for chosen sensor type.

Camera

Clightd should support any capture device, both internal or USB, through udev.
Supported capture format are Greyscale, YUYV and MJPEG (V4L2_PIX_FMT_GREY, V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_MJPEG).
To find out your camera supported formats, use: v4l2-ctl --device /dev/video0 --list-formats

To test it right away, issue:
busctl call org.clightd.clightd /org/clightd/clightd/Sensor/Camera org.clightd.clightd.Sensor Capture "sis" "" 5 ""

Note that Clightd forces a well-known initial camera settings that corresponds to webcam default values.
Users can override these settings through https://github.com/FedeDP/Clightd/wiki/Sensors#camera-1.

Pipewire

Clightd 5.5 supports using Pipewire for camera frames captures.
The support is experimental, waiting for Pipewire to mature enough; that is why it is not built by default.
Give a look at Pipewire wiki page for more informations.

To test it right away, issue:
busctl call org.clightd.clightd /org/clightd/clightd/Sensor/Pipewire org.clightd.clightd.Sensor Capture "sis" "" 5 ""

ALS

Clightd should support any ALS device through udev. If you have an acpi-als device and it does not work properly, it was reported that you may need an additional acpi call to enable the sensor:
echo \\_SB.PCI0.LPCB.EC0.ALSC 0x1 > /proc/acpi/call.
This call is needed at each reboot; thanks to u/bradbrad2x for its kind testing!

To test it right away, issue:
busctl call org.clightd.clightd /org/clightd/clightd/Sensor/Als org.clightd.clightd.Sensor Capture "sis" "" 5 ""

YoctoLight

Clightd does support Yoctolight devices through libusb.
Those are tiny usb als devices.
I am in no way affiliated to this project; i just bought one some time ago to experiment with it and then added support for it.

To test it right away, issue:
busctl call org.clightd.clightd /org/clightd/clightd/Sensor/YoctoLight org.clightd.clightd.Sensor Capture "sis" "" 5 ""

Custom

Custom sensor were made available to support your own sensor source; it just requires a text file with an integer and it can be filled by any source.
This means you theoretically should be able to eg: read ambient light values from your smartphone to a text file and let Clightd gracefully handle the value.
Custom sensor behaviour depends upon "sysname" parameter:

  • if empty, it will use first file it finds into /etc/clightd/sensors.d/ folder, in alphabetical order
  • if absolute path, it will just use "sysname" as a path to be read from
  • if relative path, it will try to find "sysname" file into /etc/clightd/sensors.d/ folder

Note also that /etc/clightd/sensors.d/ is monitored for changes through inotify, thus you can runtime-add a new custom sensor to the folder and a dbus signal will be emitted, and clightd will start using it from subsequent calls.

To test it right away, issue:
busctl call org.clightd.clightd /org/clightd/clightd/Sensor/Custom org.clightd.clightd.Sensor Capture "sis" "" 5 ""

Settings String

Sensor settings string can be used to further customize your sensor capture parameters; it should be built as "A=b,C=d" string.

Camera

A and C are v4l2 operation ids, and b and d are their desired values. Operation ids are taken from <linux/v4l2-controls.h>. Example: "10094849=1,10094850=166" means "V4L2_CID_EXPOSURE_AUTO=V4L2_EXPOSURE_MANUAL,V4L2_CID_EXPOSURE_ABSOLUTE=166".

Moreover, since Clightd 5.5, users are able to specify a cropping area, using x=$startPct-$endPct,y=$startPct-$endPct, eg: x=0.4-0.6,y=0.2-0.8 to capture 30% of central width, and 70% of central height.
Note that [0,0] origin is top left corner.
Basically, Clightd tries to use v4l2 selection or crop APIs, if available; where those are not available, it will fallback at manually skipping pixels.

Pipewire

N/A

ALS/YoctoLight

Only one option is available: "i".

  • "i" -> interval used by Clightd for polling sensor. It defaults to 20ms and it is the time Clightd waits before each sequential sensor reading (eg: when capturing 5 frames, it will sleep 20ms between each captured frame).

Custom

Three options are made available: "i", "m", "M".

  • "i" -> interval used by Clightd for polling text file. It defaults to 20ms and it is the time Clightd waits before each sequential file reading (eg: when capturing 5 frames, it will sleep 20ms between each read).
  • "m" -> minimum value threshold for sensor readings: if sensor reading is below this threshold, it will be set to this value.
  • "M" -> maximum value threshold for sensor readings: if sensor reading is above this threshold, it will be set to this value.

Note that "m" and "M" affects returned percentages (valued as read_value / maximum, and read_value is bounded to minimum and maximum values).

Clone this wiki locally