Coder Social home page Coder Social logo

illuminanced's Introduction

Ambient Light Sensor Daemon For Linux

A user mode daemon for automatically changing brightness based on light sensor value designed for modern laptops. Not all devices might be supported.

How to test befor install

Run from a terminal sudo watch cat /sys/bus/acpi/devices/ACPI0008\:00/iio\:device0/in_illuminance_raw and check that number is changing (try close the sensor or add more light). If the number is still the same it means the sensor driver doesn't work. If you see file not found error try to find correct path for in_illuminance_raw inside /sys/bus/acpi/devices/.

For ZBook 15 G6, Framework laptops, and may be others, the sensor path is /sys/bus/iio/devices/iio:device0/in_illuminance_raw. So try sudo watch cat /sys/bus/iio/devices/iio:device0/in_illuminance_raw and change the config if it works for you.

Supported laptops

Works on ASUS Zenbooks with built-in driver acpi-als:

  • UX303UB
  • UX305LA
  • UX305FA
  • UX310UQ
  • UX330UA

Also works on Framework laptops:

  • Framework 13 AMD
  • Framework 16 AMD

On Dell Inspiron 13 7353, need to change driver path and brightness levels.

Some times works (base on responses)

  • UX303UA
  • UX305CA with als driver
  • UX430UQ Ubuntu with build in driver acpi-als, an extra ACPI call to enable the sensor (_SB.PCI1.LPCB.EC0.ALSC)
  • UX410UQ

Doesn't work on Zenbooks because of driver issue:

  • UX303LN
  • UX305UA
  • UX31A
  • UX32LN

Something wrong with Arch Linux may be related with syslog, a pull request is appreciated

Please fill a response form, it may helps other users

Keyboard back light is not adjust because my laptop doesn't have it. Want to help? Create an issue.

Install package (experimental)

Finally I found time to create deb package

To install and start run next commands after download:

sudo dpkg -i ~/Download/illuminanced_1.0-0.deb
sudo systemctl enable illuminanced.service
sudo systemctl start illuminanced.service

You can check status by running systemctl status illuminanced.service

Please open an issue if it doesn't work.

How to build & install

  • install Rust: curl https://sh.rustup.rs -sSf | sh
  • clone : git clone https://github.com/mikhail-m1/illuminanced.git
  • build: cd illuminanced; cargo build --release
  • install sudo ./install.sh

How to Adjust

  • open a config file /usr/local/etc/illuminanced.toml (Default)
  • choose how many light values do you need by [general].light_steps
  • set defined points count by [light].points_count
  • set each point by illuminance_<n> and light_<n> where illuminance from in_illuminance_raw (see below) and light in range [0..light_steps)

How it works

Reads illuminance from /sys/bus/acpi/devices/ACPI0008:00/iio:device0/in_illuminance_raw, apply Kalman like filter, set back light value base on defined points. Unfortunately I cannot find a way how get events from iio buffers, for acpi-als driver, so now it polls.

<Fn> + A

Switches three modes:

  • Auto adjust
  • Disabled
  • Max brightness (useful for movies, can be disabled by config file /usr/local/etc/illuminanced.toml)

Contribution

Any feedback are welcome

illuminanced's People

Contributors

brianclemens avatar mikhail-m1 avatar mkatychev avatar svenstaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

illuminanced's Issues

Default config does not work on Framework 16 and documentation is too lacking to help

Hi,
I just want to mention that the default config does not work on the Framework 16 because the backlight files are incorrect. While the info page provides the correct sensor to look for, I feel like some extra documentation would be appreciated by many.

I have made a thread on Framework forums about the correct config to be used with the 16 and potentially the AMD FW13 (cannot verify though as I do not own a 13).

The configuration needed for customization is also very vague and would need more clarification since as of right now, the only way to customize it is to do alot of trial and error. But that has already been mentionned I think in #12.

HP ZBook 17 G5 (4QH25EA#BCM) service does not load

output from systemcl service

● illuminanced.service - Ambient light monitoring Service
Loaded: loaded (/etc/systemd/system/illuminanced.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2019-04-03 13:43:14 CEST; 5min ago
Docs: https://github.com/mikhail-m1/illuminanced
Process: 21951 ExecStart=/usr/local/sbin/illuminanced (code=exited, status=5)

dub 03 13:43:14 daniel-HP-ZBook-17-G5 systemd[1]: illuminanced.service: Service RestartSec=100ms expire
dub 03 13:43:14 daniel-HP-ZBook-17-G5 systemd[1]: illuminanced.service: Scheduled restart job, restart
dub 03 13:43:14 daniel-HP-ZBook-17-G5 systemd[1]: Stopped Ambient light monitoring Service.
dub 03 13:43:14 daniel-HP-ZBook-17-G5 systemd[1]: illuminanced.service: Start request repeated too quic
dub 03 13:43:14 daniel-HP-ZBook-17-G5 systemd[1]: illuminanced.service: Failed with result 'exit-code'.
dub 03 13:43:14 daniel-HP-ZBook-17-G5 systemd[1]: Failed to start Ambient light monitoring Service.

output from jurnalctl e

--
-- Unit illuminanced.service has failed.

-- The result is RESULT.
dub 03 13:50:53 daniel-HP-ZBook-17-G5 systemd[1]: illuminanced.service: Service RestartSec=100ms expire
dub 03 13:50:53 daniel-HP-ZBook-17-G5 systemd[1]: illuminanced.service: Scheduled restart job, restart
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support

-- Automatic restarting of the unit illuminanced.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
dub 03 13:50:53 daniel-HP-ZBook-17-G5 systemd[1]: Stopped Ambient light monitoring Service.
-- Subject: Unit illuminanced.service has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support

-- Unit illuminanced.service has finished shutting down.
dub 03 13:50:53 daniel-HP-ZBook-17-G5 systemd[1]: illuminanced.service: Start request repeated too quic
dub 03 13:50:53 daniel-HP-ZBook-17-G5 systemd[1]: illuminanced.service: Failed with result 'exit-code'.
dub 03 13:50:53 daniel-HP-ZBook-17-G5 systemd[1]: Failed to start Ambient light monitoring Service.
-- Subject: Unit illuminanced.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support

-- Unit illuminanced.service has failed.

-- The result is RESULT.

raw value not changing

Hello!
Thank you for your work, everything installed smoothly and is running.
However I have a problem with raw sensor readings.
I noticed that auto-mode is always switching to one particular state. I checked the raw values you are reading and they seem to be not changing, always being at 400.

/sys/bus/acpi/devices/ACPI0008:00/iio:device0$ cat in_illuminance_raw 
400

The sensor itself is working, I have stock windows installed on the other partition - auto-adjustment works as intended there.

Hardware: Asus Zenbook UX410U
Software: Ubuntu 17.04 - 0x64

I would be glad to help a project and give all necessary info or even dig into a code.

Works in debug, but systemd service fails to start

Works when running RUST_LOG=debug /usr/local/sbin/illuminanced -d, but the systemd service shows this:

Aug 08 15:56:43 cayucos systemd[1]: Dependency failed for Ambient light monitoring Service.
░░ Subject: A start job for unit illuminanced.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit illuminanced.service has finished with a failure.
░░
░░ The job identifier is 5830 and the job result is dependency.
Aug 08 15:56:43 cayucos systemd[1]: illuminanced.service: Job illuminanced.service/start failed with result 'dependency'.
~

Tested on UX303LN / keyboard backlight

Hi,

This is great! It is working on my laptop running Fedora 25/KDE.

There are two thing I would like to comment:

  1. It is not clear to me how to change the number of steps. I would like something smoother.
  2. Is it possible to control the keyboard backlight as well?

Thanks!
Felipe

Needs feedback on toggle

Hello! Not sure if this is already implemented and not working for my machine, but here...

I have an Asus Zenbook UX410UQ, Ubuntu 17.10, 4.13.0-37-generic.

To enable the ambient light sensor, I first tried the first answer here but ran into some issues (I could enable, but not disable the service), so I decided to use your (amazingly done) daemon.

Only issue I have is I don't seem to have a way of seeing which option is active at any time aside from using FN+A to toggle between options and guessing which is which. It would be amazing if there was a system notification every time the service is toggled, saying something like "Ambient Light Sensor Enabled/Disabled". I would also like to be able to turn off the Max brightness option.

Editable Toggle Keybinding

As KEY_ALS_TOGGLE is neither available by default nor possible to set on most keyboards (including my Framework Laptop), there should be a way to change what keybind toggles between modes. KEY_ALS_TOGGLE is a sane default, but without options I am locked into ambient light sensing mode always, which is inconvenient in some situations (like watching a movie). This could be an option in the illuminaced.toml file.

Does not change brightness

Hello,
I am on my FW16 and I installed the service via paru from AUR. It was installed correctly, my config was edited but it does not do anything. My brightness stays at the same level. However, the reading from the ambient light sensor changes.
My desktop environment is KDE with wayland.

Here is my config:


[daemonize]
# log_to = "syslog" or /file/path
log_to = "/var/log/illuminanced.log"
pid_file = "/run/illuminanced.pid"
# log_level = "OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"
log_level = "ERROR"

[general]
check_period_in_seconds = 5
light_steps = 10
min_backlight = 70
step_barrier = 0.1
max_backlight_file = "/sys/class/backlight/amdgpu_bl1/max_brightness"
backlight_file = "/sys/class/backlight/amdgpu_bl1/brightness"
illuminance_file = "/sys/bus/iio/devices/iio:device0/in_illuminance_raw"
event_device_mask = "/dev/input/event*"
event_device_name = "Asus WMI hotkeys"
enable_max_brightness_mode = true
filename_for_sensor_activation = ""

[kalman]
q = 1
r = 20
covariance = 10

[light]
points_count = 6

illuminance_0 = 0
light_0 = 0

illuminance_1 = 20
light_1 = 1

illuminance_2 = 300
light_2 = 3

illuminance_3 = 700
light_3 = 4

illuminance_4 = 1100
light_4 = 5

illuminance_5 = 7100
light_5 = 10

I have installed it and started the service. Am I supposed to somehow enable it further? I saw there are 3 modes but I do not understand how am I supposed to alter between them.

My laptop config is FW16 with ryzen 7 and no dGPU. Service seems to be running correctly. Only in journal I have:

Jun 12 14:01:41 Samo-PCFW kernel: i2c_hid_acpi i2c-FRMW0003:00: failed to set a report to device: -121
Jun 12 14:02:23 Samo-PCFW kernel: i2c_hid_acpi i2c-FRMW0003:00: failed to set a report to device: -121
Jun 12 14:02:37 Samo-PCFW kernel: i2c_hid_acpi i2c-FRMW0003:00: failed to set a report to device: -121
Jun 12 14:07:26 Samo-PCFW kernel: i2c_hid_acpi i2c-FRMW0003:00: failed to set a report to device: -121
Jun 12 14:07:39 Samo-PCFW kernel: i2c_hid_acpi i2c-FRMW0003:00: failed to set a report to device: -121

This does not happen when the service is disabled.

Fails to start on Arch Linux

Unexpected Behavior

I alter the illuminanced.toml file to match my os and machine settings. Logs shows that no such file exists, but they do.

Specs

OS: Arch Linux
Host: Laptop 16
Kernel: 6.9.3
DE: Plasma 6.0.5
CPU: AMD Ryzen 9 7940HS
GPU: AMD ATI Radeon RX 7700S
Memory: 62092MiB

Settings

/etc/illuminanced.toml

/etc/illuminanced.toml
[daemonize]
log_to = "/var/log/illuminanced.log"
pid_file = "/run/illuminanced.pid"
log_level = "DEBUG"

[general]
check_period_in_seconds = 5
light_steps = 10
min_backlight = 70
step_barrier = 0.1
max_backlight_file = "/sys/class/backlight/amdgpu_bl2/max_backlight"
backlight_file = "/sys/class/backlight/amdgpu_bl2/brightness"
illuminance_file = "/sys/bus/iio/devices/iio:device0/in_illuminance_raw"
event_device_mask = "/dev/input/event*"
event_device_name = "Asus WMI hotkeys"
enable_max_brightness_mode = true
filename_for_sensor_activation = ""

Logs

/var/log/illuminanced.log

06:55:25 [DEBUG] (1) illuminanced: Points: [LightPoint { illuminance: 0, light: 0 }, LightPoint { illuminance: 20, light: 1 }, LightPoint { illuminance: 300, light: 3 }, LightPoint { illuminance: 700, light: 4 }, LightPoint { illuminance: 1100, light: 5 }, LightPoint { illuminance: 7100, light: 10 }]
06:55:25 [ERROR] Cannot read file `/sys/class/backlight/amdgpu_bl2/max_backlight`: No such file or directory (os error 2)

Asus zenbook ux305LA need help

Hi,
I tried run command:
sudo watch cat /sys/bus/acpi/devices/ACPI0008\:00/iio\:device0/in_illuminance_raw
but get:
cat: '/sys/bus/acpi/devices/ACPI0008:00/iio:device0/in_illuminance_raw': No such file or directory

Tried to install als driver but still no success

I am using ubuntu 20.04

My laptop has a different file for the illuminance sensor (`/sys/bus/iio/devices/iio\:device1/in_illuminance_input`)

The section "How to test befor install"

Run from a terminal sudo watch cat /sys/bus/acpi/devices/ACPI0008:00/iio:device0/in_illuminance_raw and check that number is changing (try close the sensor or add more light). If the number is still the same it means the sensor driver doesn't work. If you see file not found error try to find correct path for in_illuminance_raw inside /sys/bus/acpi/devices/.
For ZBook 15 G6, and may be others, sensor path is /sys/bus/iio/devices/iio:device0/in_illuminance_raw. So try sudo watch cat /sys/bus/iio/devices/iio:device0/in_illuminance_raw and change the config if it works for you.

doesn't work for my laptop (HP Elite Dragonfly Chromebook, code name redrix), even though it does have an ambient light sensor which I can read with cat /sys/bus/iio/devices/iio\:device1/in_illuminance_input

Should the README be updated?

configuration file needs a bit more explanation

Hi there, and thanks for this nice utility!

I couldn't easily understand some things from the README.md:

  • I see that points_count refers to the number of points in the [light] section, and that each light_n should be in the range [0..light_steps) but it's not at all obvious how these are connected. I think I figured it out by reading the source code and looking at the example config file illuminance.toml, but please let me know if my understanding is correct:
    • [0..light_steps] is a more user-friendly re-mapping of the backlight brightness scale from [min_backlight..max_brightness]
    • The illuminance_n values relate to values from the in_illuminance_raw device, which are mapped to the brightness scale via linear interpolation. So with the example values given, if the illuminance device reads a raw value of 400, that is 25% of the way between point 2 (with value 300) and point 3 (with value 700), so it gets mapped to a value of 2.25, i.e. 22.5% of the range between min_backlight and max_brightness.
    • step_barrier prevents changes of brightness if the mapped illuminance value changes less than the barrier amount, i.e. a change from 2 to 2.05 wouldn't change the backlight, but a change from 2 to 2.25 would, in which case it's effectively a noise reduction technique. But then why is the Kalman filter needed?
    • What are the parameters in the [kalman] section?
    • I think the range should be [0..light_steps] not [0..light_steps) because the example config file has light_5 = 10 implying that the maximum value of 10 is permitted.
  • <Fn> + A is supposed to switch modes, but I don't see how this is possible on my keyboard where <Fn> + A doesn't register any event? The example config has event_device_name = "Asus WMI hotkeys" which clearly won't work except for some Asus machines. How can the rest of us determine the right value?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.