FedeDP / Clightd

A linux bus interface that lets you change screen brightness, compute captured webcam frames brightness and change screen temperature.
GNU General Public License v3.0
83 stars 10 forks source link

Add brightness value limits for monitors with strange implementations of DDC/CI #73

Closed taprobane99 closed 3 years ago

taprobane99 commented 3 years ago

Is your feature request related to a problem? Please describe. My external monitor has a strange version of DDC/CI where sending 1...31 via ddcutil corresponds to 33...100 on the monitor. Sending values outside this range causes the monitor to switch off.

Describe the solution you'd like Limit possible values of the brightness parameter for people with unusual monitors. In my case I want to block values of 0, and >31 being sent.

Also sending contrast commands crashes my monitor even though ddcutil thinks that parameter is controllable. But not sure if you're using contrast?

FedeDP commented 3 years ago

Hi! Thanks for opening this bug! This is an extremely weird issue indeed. I will move the bug to Clightd btw ;) Did you already asked for help to ddcutil developer? Maybe he is able to find a better approach for solving this issue! Clightd just uses libddcutil to talk with external monitor, thus it would be advisable to correct the behavior there if possible. Otherwise, i will be happy to try some workarounds. Thank you!

taprobane99 commented 3 years ago

I did already talk to ddcutil developer, but it seems ddcutil just reads the values it is given from the monitor. there are no individual monitor .xml or config files with ddcutil so not sure what the developer can do for special cases like mine.

also, i noticed on the ddcutil issues that other people have similar issues with their monitors.

it seems it may be best for programs such as yours to provide extra config options or custom monitor configs. perhaps a "min" and "max" for brightness range would be possible?

also i guess clight should be aware, in my case, that 31 is full brightness and 1 is actually 33% brightness.

FedeDP commented 3 years ago

Thank you, that's great! As a quick workaround, you might be able to adjust Clight backlight curves to start from eg: 0.01 up to 0.31; Clight will honor the min/max values of the curves. This won't work though if you are using mutliple external monitors or internal + external ones, as backlight curves are global across all monitors.
For that, an issue is already tracking that: https://github.com/FedeDP/Clight/issues/43 ; note that it is quite old though; unfortunately it requires quite a bit of work and i always postponed that because i did not find it super urgent. Let me know, thank you!

FedeDP commented 3 years ago

Hi @taprobane99 ! I just want to let you know that i finally fixed https://github.com/FedeDP/Clight/issues/43, thus Clight users can now specify per-monitor adjustment curves; for more info read my last comment on the Clight issue or head to the new conf file section: https://github.com/FedeDP/Clight/blob/master/Extra/clight.conf#L116

Hopefully this will allow you to fix your issue! Let me know thanks!

taprobane99 commented 3 years ago

ok great! actually i don't have a webcam right now but looks like this solves the problem.

taprobane99 commented 3 years ago

@FedeDP , do you think you could test this on a "normal" monitor to see that if you reduce the brightness range clight always obeys this?

FedeDP commented 3 years ago

Yep, i will; i am pretty sure btw because of this code in clight: https://github.com/FedeDP/Clight/blob/master/src/modules/backlight.c#L370

taprobane99 commented 3 years ago

I am just testing it now using a "normal" external monitor i.e. brightness 1-100 and limiting it to 50-70.

Will this code in /.config/clight.conf always override the .conf in /etc/default/clight.conf?

I guess the GUI also needs updating as when I save changes there it deletes the entry I added manually below.

monitor_override : 
{
        monitor_id = "11080M0301929"
        ac_regression_points = [ 0.5, 0.52, 0.54, 0.56, 0.58, 0.60, 0.62, 0.64, 0.66, 0.68, 0.70 ];
        batt_regression_points =  [ 0.0, 0.15, 0.29, 0.45, 0.61, 0.74, 0.81, 0.88, 0.93, 0.97, 1.0 ];
};
FedeDP commented 3 years ago

Will this code in /.config/clight.conf always override the .conf in /etc/default/clight.conf?

Yes, config file are parsed in this order:

I guess the GUI also needs updating as when I save changes there it deletes the entry I added manually below.

That was an issue in Clight, thank you! Resolved in latest commit! Let me know :) In case of issues, please open a ticket on Clight so we can easily track it!

taprobane99 commented 3 years ago

So, just to remind you, my monitor has the following values to control brightness: 0-31 sending 32 - dangerous! - monitor goes black and can only be recovered by sending a value from 0-31 again (luckily I have my laptop monitor also, or this would be very difficult).

In my testing on a normal monitor I've noticed that with a custom range of 0.50 - 0.70, and shining a bright light on my sensor so it reads 99% ambient brightness, the monitor has a brightness of 69.

Are the custom limits set so the value is always < max, or always <= max?

FedeDP commented 3 years ago

Hi! Sorry i did not carefully checked your regression points values;

monitor_override : { monitor_id = "11080M0301929" ac_regression_points = [ 0.5, 0.52, 0.54, 0.56, 0.58, 0.60, 0.62, 0.64, 0.66, 0.68, 0.70 ]; batt_regression_points = [ 0.0, 0.15, 0.29, 0.45, 0.61, 0.74, 0.81, 0.88, 0.93, 0.97, 1.0 ]; };

For monitor override, regression points are "backlight to backlight mapping", ie: they map your reference monitor backlight level (that can be your internal laptop backlight/another external monitor) to monitor_id's monitor backlight level.

Reference monitor uses "sensor" group of settings and its regression points are "ambient-brightness to backlight level mapping".

Thus, in your case, you should want that "11080M0301929" monitor's regression points maximum is 0.31, eg:

[ 0.02, 0.09, 0.12, 0.17, 0.21, 0.24, 0.26, 0.28, 0.29, 0.30, 0.31 ]

Are the custom limits set so the value is always < max, or always <= max?

Clight does a polynomial regression on specified values, thus the resulting curve can reach values that are a little below your maximum. In case they're > of max or < min, they are limited to max-min.

taprobane99 commented 3 years ago

But does monitor override work with my laptop lid shut and laptop monitor off? i.e. I only have a single external monitor?

In that case, surely, I want backlight to ambient light mapping?

FedeDP commented 3 years ago

I don't understand your question, sorry!

taprobane99 commented 3 years ago

If I have my laptop connected to an external monitor with the laptop display switched off, then there is no reference monitor. I only have 1 monitor - the external one.

FedeDP commented 3 years ago

It shouldn't matter, i mean: Clight computes correct backlight level giving "sensor.{ac,batt}regression_points", then you enforce a specific setting for your external monitor that is thus applied.