You are not logged in.

#1 2017-05-12 12:28:24

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Clight, C daemon to turn your webcam into a light sensor

Hi everyone!
I'm here to present you all my latest project.
Clight is a C daemon that is able to set correct backlight level for current ambient brightness, by capturing frames from webcam and computing ambient brightness on them.
Moreover, it manages your screen temperature too (like redshift).
It has really lots of configuration settings and features.
A small peek of Clight features:
* auto-disable not supported modules on non-X environment (eg: gamma, dpms)
* if screen is in DPMS, it won't touch backlight
* geoclue2 support to retrieve user location (for gamma support)
* different timeouts between captures for DAY, NIGHT and even for AC/BATT states (through upower)

It ships a config file placed in /etc/default/clight.conf, have a look there!
Moreover, it ships an autostart desktop file (/etc/xdg/autostart/), as it aims to be a 0-conf software (it should work fine out of the box), and another desktop file to take a fast screen backlight recalibration (if anyone is willing to give clight a better icon, he is *really* welcome).
Head to project page for more informations: https://github.com/FedeDP/Clight .

It relies upon a bus interface i developed: Clightd (https://github.com/FedeDP/Clightd).
Clightd is responsible of taking frames from webcam, getting/setting backlight and gamma.
Its exposed methods require a "device" parameter (for frames capture and backlight get/set). If this parameter is empty or null, it will default to first subsystem matching device it can find.
Moreover, it supports polkit: only ACTIVE sessions can change gamma/backlight level and capture frames from webcam.
You can build your own software using it, in any language that has dbus bindings (eg: python, C...) or pure bash.

I hope someone finds this useful smile
Have a nice day!

EDIT: forgot this: both softwares are already on AUR: https://aur.archlinux.org/packages/clight-git/ , https://aur.archlinux.org/packages/clightd-git/

Last edited by nierro (2017-05-12 14:53:09)

Offline

#2 2017-05-12 19:46:49

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Clight, C daemon to turn your webcam into a light sensor

This seems very interesting, but unfortunately, it either hangs or segfaults for me. On the first start it hangs after "Upower module started" or it crashes/segfaults. On any consecutive start, clight does get a location, but then segfaults.

The dumps, together with the .log files, are available here: https://gist.github.com/7f082c6684fd2be … be598c23e5

EDIT: This is for an up to date Arch with i3 as the WM. The package versions are r182.955ca4f-1 for clight-git and r35.26ef418-1 for clightd-git. Both were built in a clean chroot.

Last edited by runical (2017-05-12 19:52:04)

Offline

#3 2017-05-12 19:56:58

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

Thank you very much for the report! It is weird, obviously i, and some other testers, did never encounter this issue.
Can you rebuild clight with debug enabled?(edit PKGBUILD and replace "make" with "make debug") and post back these logs/dumps?
Thanks again!

Offline

#4 2017-05-12 20:01:03

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Clight, C daemon to turn your webcam into a light sensor

Will do. Give me a moment :-)

Offline

#5 2017-05-12 20:14:25

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Clight, C daemon to turn your webcam into a light sensor

I have updated the original gist (https://gist.github.com/7f082c6684fd2be … be598c23e5). The files clight-dump3 and clight.log.3 contain the first start after a reboot, clight.log.4 is on a second start.

Offline

#6 2017-05-12 22:08:52

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

Ok, i was able to reproduce the issue, i'll report back as soon as issue is solved. Thanks for the discover! smile
BTW i see it cannot find an X environment: how did you enable clight? You just rely on /etc/xdg/autostart (i guess i3 does not support that) or did you enable clight user unit?

EDIT: moreover, can you paste me the output of
$ env | grep XDG_SESSION_TYPE
Thanks!

Last edited by nierro (2017-05-12 22:11:11)

Offline

#7 2017-05-12 22:19:11

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Clight, C daemon to turn your webcam into a light sensor

I started clight from the command line to make sure that everything works. If the program works, I add it to the config of the WM. I don't want programs just starting up willy nilly wink

XDG_SESSION_TYPE does not exist in my session. I use startx with a pmenu "frontend" to select the WM I want to use and no DM if that helps. A rather bare bones system so to say. There is a polkit session iirc for the gnome-keyring.

Offline

#8 2017-05-12 22:21:16

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

Oh that explains why clight is disabling gamma module; are you willing to paste me your
$ env
output?
I have to find a better env variable to understand whether we are inside an X session to also avoid this issue!

Offline

#9 2017-05-13 07:37:59

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Clight, C daemon to turn your webcam into a light sensor

No problem, here you go: https://gist.github.com/75c8e0c09fe3fc5 … 9ff5146be0

I have included both a version with X started and one without X. You might have to sort them before comparing though. As far as I can see, the session without X does not have the DISPLAY variable.

EDIT: SELSESSION is a variable I use to select the session I want to run btw, so please don't see that as a viable variable wink

Last edited by runical (2017-05-13 07:41:37)

Offline

#10 2017-05-13 09:03:36

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

@runical thank you very much for your help!
It should now be fixed in master, please rebuild and check!

@all: added a way to customize ambient_brightness -> screen_backlight curve from config file, have a look here: https://github.com/FedeDP/Clight#polynomial-fit.
TL;DR: inside configuration file you can find a "brightness_regression_points" array variable. This is dataset used to perform a polynomial fit to retrieve best-fit parameters to create a curve to match ambient brightness with screen backlight.
If you do not like default values, try to play a bit with that array smile

Last edited by nierro (2017-05-13 09:04:16)

Offline

#11 2017-05-13 09:53:12

runical
Member
From: The Netherlands
Registered: 2012-03-03
Posts: 896

Re: Clight, C daemon to turn your webcam into a light sensor

Yup, that works! Thanks for the update. Unfortunately, I won't be able to test it tonight as I'll be away from the computer, but I'll see later :-)

EDIT: I devised a way to test still, but I'll take it to github

Last edited by runical (2017-05-13 10:11:52)

Offline

#12 2017-07-01 08:20:57

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

Clight 1.0 has been released; some highlights:
* Ambient brightness to screen backlight fitting function is now customizable through conf file, and user can set different function for each ac state. Read here for more info: https://github.com/FedeDP/Clight#polynomial-fit
* Added a dimmer module, that will dim your screen to certain pct of max brightness (customizable), after a (customizable) timeout of user inactivity
* Added a dpms module that will switch off dpms after certain user inactivity time
* Clight will now avoid changing brightness (and dim screen) if selected backlight interface is not active (eg: you use your laptop connected to an external monitor, with internal screen switched off). This would be useless and a waste of power (no webcam captures are taken too)
* Lots of other improvements and fixes

Clightd has received some love too:
* Added getdpms, setdpms, getdpms_timeouts, setdpms_timeouts functions
* added support to retrieve user idle time
* added an isbacklightinterfaceenabled method to check whether given backlight interface is enabled
* improvements to code modularity

As always, feel free to drop a line with suggestions, or bug reports.
Have a nice day!

Offline

#13 2017-07-25 19:03:57

surfatwork
Member
Registered: 2012-01-05
Posts: 137

Re: Clight, C daemon to turn your webcam into a light sensor

Hi, nice work!!
The Brightness module works. But the Gamma module seems to be disabled.
here is what I got running

 $ clight -c --verbose
Config file /home/pradeep/.config/clight.conf not found.
Signal module started.
Bus module started.
Xorg module disabled.
Disabling module Gamma as its hard dep Xorg was disabled...
Gamma module disabled.
Trying to start Brightness module as its Gamma soft dep was disabled...
Disabling module GammaSmooth as its hard dep Gamma was disabled...
GammaSmooth module disabled.
Location module disabled.
Disabling module DimmerSmooth as its hard dep Xorg was disabled...
DimmerSmooth module disabled.
Trying to start Brightness module as its Bus dependency was loaded...
Trying to start Upower module as its Bus dependency was loaded...
Upower module disabled.
Trying to start Brightness module as its Upower soft dep was disabled...
0: y = -0.024825 + 0.191641x + -0.008928x^2
1: y = -0.010629 + 0.153844x + -0.007284x^2
Setted timeout of 0s 1ns on fd 6.
Brightness module started.
Callback added for module 0 on module 2 bus match.
Trying to start Dimmer module as its Upower soft dep was disabled...
Trying to start Dpms module as its Upower soft dep was disabled...
Trying to start Dimmer module as its Bus dependency was loaded...
Trying to start Dpms module as its Bus dependency was loaded...
Average frames brightness: 0.366244.
New brightness value: 522
Trying to start Dimmer module as its Brightness dependency was loaded...
Brightness module destroyed.
Bus module destroyed.
Signal module destroyed.
$

What am I missing?
Also, how often does this sample the ambient light conditions?

thanks

Last edited by surfatwork (2017-07-25 19:05:39)

Offline

#14 2017-07-26 09:46:27

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

You are running "clight -c", that means that clight will only do a single capture and leave.
Thus, every "module" not needed gets disabled.
Can you send me the output of a normal clight run with verbose flag?
By the way, by default clight makes webcam captures every 10 minutes during the day, 45minutes during the night and 5minutes during an "event" (sunrise/sunset), if laptop is connected to AC. These timeouts are doubled while on battery.

Offline

#15 2017-07-26 12:15:48

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: Clight, C daemon to turn your webcam into a light sensor

This is nice, thanks! Just replaced redshift with clight-git.

Offline

#16 2017-07-26 12:21:12

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

Glad to hear that smile

Offline

#17 2017-07-27 13:53:16

surfatwork
Member
Registered: 2012-01-05
Posts: 137

Re: Clight, C daemon to turn your webcam into a light sensor

nierro wrote:

You are running "clight -c", that means that clight will only do a single capture and leave.
Thus, every "module" not needed gets disabled.
Can you send me the output of a normal clight run with verbose flag?
By the way, by default clight makes webcam captures every 10 minutes during the day, 45minutes during the night and 5minutes during an "event" (sunrise/sunset), if laptop is connected to AC. These timeouts are doubled while on battery.

Got it. checked ~/.clight.log and it looks fine. Will check for the gamma change this evening.
thanks for a cool bit of kit.

PM

Offline

#18 2017-07-27 14:17:42

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

surfatwork wrote:

Got it. checked ~/.clight.log and it looks fine. Will check for the gamma change this evening.
thanks for a cool bit of kit.

You're welcome, hope you find it useful!

Offline

#19 2017-08-03 09:10:24

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

New version (1.1) is out with some new features, lots of improvements and some fixes:
* BRIGHTNESS module will now properly account for suspended time
* Debug mode (--verbose) is now runtime enabled
* Added support for dimmer smooth transitions (both entering dimmed state and leaving)
* Added a inhibit module that will monitor org.freedesktop.PowerManagement.Inhibit.HasInhibitChanged and will block dimming screen if a powermanagement inhibit is set (eg: by chrome while watching a video).
That bus interface is supported at least on KDE and xfce.

A new Clightd  version (1.4) is out too:
* improved camera frame capture code
* improved captureframes interface
* improved isbacklightinterfaceenabled interface (now returns boolean)
* setdpms will now disable dpsm if -1 is passed

Hope you enjoy it!
Have a nice day smile

Last edited by nierro (2017-08-03 21:23:23)

Offline

#20 2017-08-05 07:55:17

nierro
Member
From: Milan, Italy
Registered: 2011-09-02
Posts: 849

Re: Clight, C daemon to turn your webcam into a light sensor

I did release a quick 1.2 update as there were some bugs in the 1.1 version.
New: https://github.com/FedeDP/Clight/releases/tag/1.2.

Have a nice day everyone!

Offline

Board footer

Powered by FluxBB