s-light / ASUS-ZenBook-Pro-Duo-UX581GV

ASUS ZenBook Pro Duo UX581GV - infos & helper scripts for running Kubuntu
MIT License
69 stars 8 forks source link

Add Screen Brightness Helpers #14

Closed Natrinicle closed 3 years ago

Natrinicle commented 3 years ago

The script ux581_brightness.sh reads the currently requested brightness and the maximum brightness and generates a percent representation. There is a min/max percent brightness for both the OLED and Screenpad displays and the percentage is scaled accordingly. The Screenpad brightness is then scaled to 0-255 (0x00-0xFF) for the /proc/acpi/call request that Plippo documented in s-light#1

The path and service files have been included for SystemD to set up inotifywatch on the brightness file and an INSTALL text file has been included to show where to place the files and what to run to enable them on startup.

s-light commented 3 years ago

thanks for creating the script! if i understand it correctly: this one sets the brightness of both screens and watches the system brightness - so you do not have to setup any new keystrockes - if it is installed it just works -) i have read through the code and it looks good! maybe just add a readme.md with your commit text to the folder - so its easier for random visitors to know what it does.. than iam happy to merge it :-)

Natrinicle commented 3 years ago

Absolutely, it helps me and in the spirit of open source I hope it helps others as well.

You definitely understand it correctly, it sets the brightness based on the normal brightness keys, system power management, etc using the built in kernel proc filesystem so that you don't need to manually run something or set up hacks for each screen.

I'm not the best with stringing together long form documentation but I threw in a rough draft README. Let me know if there's something you'd like to see different and I'd be happy to modify it.

s-light commented 3 years ago

i think it is clear and easy to understand! thanks for adding!!

ilikerobots commented 3 years ago

Thank you @Natrinicle, this script & service work beautifully on a UX581LV w/ Ubuntu 20.10.

I did have to add XAUTHORITY=/run/user/1000/gdm/Xauthority to the script file to allow the xrandr cmd to affect the main oled.

Natrinicle commented 3 years ago

Ah, perhaps Gnome writes that file to a different location than KDE... I created another PR https://github.com/s-light/ASUS-ZenBook-Pro-Duo-UX581GV/pull/15 with a fix that should work for you. Can you try it out and let me know if it works @ilikerobots?

ilikerobots commented 3 years ago

@Natrinicle, yep, that works, thanks!

Though one thing I didn't mention, on my UX581LV the oled name is eDP-1-1. I'm not sure if there's any way to obtain this programatically. I just replaced the eDP-1 in the script.

And I've found that the OLED is so bright relative to the screenpad, that I like to have the OLED dim initially by some level before the screenpad dims. I've accomplished this by adding

screenpad_brightness_scalar=1.5
screenpad_percent=$(echo "${screenpad_percent} * ${screenpad_brightness_scalar}" | bc -l)

This keeps the screenpad at full brightness until the OLED goes < 67%. The effect can be tweaked by adjusting the scalar value.

Natrinicle commented 3 years ago

How about polynomial curve fitting? Basically you provide an array of value:value and the equation fits the incoming value along the scale. So at 0% requested brightness we'd like 10 (on a scale of 0-255) out, at 5% we'd like 13, at 50 we'd like 128 (50=50%), etc. That should be a bit more configurable for matching perceived brightnesses.

I also added a regex to the eDP monitor detection so you can configure a pattern to look for to find the correct OLED monitor. By default I put in "eDP[0-9-]+" or eDP plus any number of numbers or dashes. Since that should still only match one, it should work for both your and my use cases.

I pushed the changes to PR 15.

ilikerobots commented 3 years ago

@Natrinicle I tested out the changes and they are working well. Thanks again.

The curve fitting approach is great, but it seems to poop out around 10-20% blanking the screenpad instead of staying at minimum. I haven't looked too much into it yet but will hopefully try out some different values soon.