wluma icon indicating copy to clipboard operation
wluma copied to clipboard

[Bug]: ALS data not parsed/calculated correctly

Open RubenKelevra opened this issue 1 year ago • 1 comments

Steps for reproducing the issue

I've set up wluma on a system of a friend, which got an ambient light sensor. But it doesn't seem to calculate the data provided correctly.

I've looked at the src/als/iio.rs and the values which seems to be read by wluma are the following on the system:

$ LANG=en_US.UTF-8 grep "" /sys/bus/iio/devices/iio\:device1/*
grep: /sys/bus/iio/devices/iio:device1/buffer: Is a directory
grep: /sys/bus/iio/devices/iio:device1/buffer0: Is a directory
/sys/bus/iio/devices/iio:device1/current_timestamp_clock:realtime
/sys/bus/iio/devices/iio:device1/dev:238:1
grep: /sys/bus/iio/devices/iio:device1/in_illuminance_hysteresis: Invalid argument
/sys/bus/iio/devices/iio:device1/in_illuminance_hysteresis_relative:0.010000
/sys/bus/iio/devices/iio:device1/in_illuminance_offset:0
/sys/bus/iio/devices/iio:device1/in_illuminance_raw:7056
/sys/bus/iio/devices/iio:device1/in_illuminance_sampling_frequency:10.000000
/sys/bus/iio/devices/iio:device1/in_illuminance_scale:0.001000000
/sys/bus/iio/devices/iio:device1/in_intensity_both_raw:7056
grep: /sys/bus/iio/devices/iio:device1/in_intensity_hysteresis: Invalid argument
/sys/bus/iio/devices/iio:device1/in_intensity_hysteresis_relative:0.010000
/sys/bus/iio/devices/iio:device1/in_intensity_offset:0
/sys/bus/iio/devices/iio:device1/in_intensity_sampling_frequency:10.000000
/sys/bus/iio/devices/iio:device1/in_intensity_scale:0.001000000
/sys/bus/iio/devices/iio:device1/name:als
grep: /sys/bus/iio/devices/iio:device1/power: Is a directory
grep: /sys/bus/iio/devices/iio:device1/scan_elements: Is a directory
grep: /sys/bus/iio/devices/iio:device1/subsystem: Is a directory
grep: /sys/bus/iio/devices/iio:device1/trigger: Is a directory
/sys/bus/iio/devices/iio:device1/uevent:MAJOR=238
/sys/bus/iio/devices/iio:device1/uevent:MINOR=1
/sys/bus/iio/devices/iio:device1/uevent:DEVNAME=iio:device1
/sys/bus/iio/devices/iio:device1/uevent:DEVTYPE=iio_device

As far as I can tell, the sensor itself works correctly:

# darkly lit room
$ cat /sys/bus/iio/devices/iio\:device1/in_illuminance_raw 
672
# brightly lit room
$ cat /sys/bus/iio/devices/iio\:device1/in_illuminance_raw 
39648
# normal lit room
$ cat /sys/bus/iio/devices/iio\:device1/in_illuminance_raw 
11088
# lights off (night time)
$ cat /sys/bus/iio/devices/iio\:device1/in_illuminance_raw 
0

Settings:

[als.iio]
path = "/sys/bus/iio/devices/"
thresholds = { 0 = "night", 20 = "dark", 80 = "dim", 250 = "normal", 500 = "bright", 800 = "outdoors" }

[[output.backlight]]
name = "eDP-1"
path = "/sys/class/backlight/intel_backlight"
capturer = "none"

What is the buggy behavior?

wluma does nothing when started, except setting the brightness once.

$ RUST_LOG=trace wluma
[2024-03-07T19:49:00Z DEBUG wluma] Using Config {
        als: Iio {
            path: "/sys/bus/iio/devices/",
            thresholds: {
                500: "bright",
                800: "outdoors",
                250: "normal",
                0: "night",
                20: "dark",
                80: "dim",
            },
        },
        output: [
            Backlight(
                BacklightOutput {
                    name: "eDP-1",
                    path: "/sys/class/backlight/intel_backlight",
                    capturer: None,
                    min_brightness: 1,
                },
            ),
        ],
    }
[2024-03-07T19:49:00Z INFO  wluma] Continue adjusting brightness and wluma will learn your preference over time.
[2024-03-07T19:49:00Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:00Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)
[2024-03-07T19:49:00Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:00Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)
[2024-03-07T19:49:00Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:00Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)
[2024-03-07T19:49:01Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:01Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)
[2024-03-07T19:49:01Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:01Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)
[2024-03-07T19:49:01Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:01Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)
[2024-03-07T19:49:01Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:01Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)
[2024-03-07T19:49:01Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:01Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)
[2024-03-07T19:49:02Z TRACE wluma::als::iio] ALS (iio): night (6)
[2024-03-07T19:49:02Z TRACE wluma::predictor::controller] Prediction: 750 (lux: night, luma: 0)

From my interpretation wluma seems to read a constant 0 from the sensor, right?

What is the expected behavior?

Reading different values from the sensor and reacting to it.

Logs

Debug log looks uneventful:

$ RUST_LOG=debug wluma
[2024-03-07T19:51:02Z DEBUG wluma] Using Config {
        als: Iio {
            path: "/sys/bus/iio/devices/",
            thresholds: {
                0: "night",
                500: "bright",
                800: "outdoors",
                20: "dark",
                250: "normal",
                80: "dim",
            },
        },
        output: [
            Backlight(
                BacklightOutput {
                    name: "eDP-1",
                    path: "/sys/class/backlight/intel_backlight",
                    capturer: None,
                    min_brightness: 1,
                },
            ),
        ],
    }
[2024-03-07T19:51:02Z INFO  wluma] Continue adjusting brightness and wluma will learn your preference over time.

Version

4.3.0 from the AUR

Environment

LSB Version:    n/a
Distributor ID: EndeavourOS
Description:    EndeavourOS Linux
Release:        rolling
Codename:       rolling
Linux stylistic-r727 6.7.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Sun, 03 Mar 2024 00:30:36 +0000 x86_64 GNU/Linux
egrep: warning: egrep is obsolescent; using grep -E
vulkan-headers 1:1.3.279-1
vulkan-icd-loader 1.3.279-1
vulkan-tools 1.3.269-1
wlroots 0.17.1-1
bash: dpkg: command not found
egrep: warning: egrep is obsolescent; using grep -E

RubenKelevra avatar Mar 07 '24 19:03 RubenKelevra

Hello!

Just to confirm something first, have you actually tried to train wluma a bit? Going in a dark place, adjusting the screen brightness by hand, going to a bright environment and increasing the brightness again by hand? It does nothing when it doesn't know your preferences :)

From my interpretation wluma seems to read a constant 0 from the sensor, right?

luma is the screen contents actually, and lux is the mapping from the value of ALS sensor to the threshold in your config, as it reports night, it reads the value as something between 0 and 20. A line below shows that it actually reads the value of 6.

To reproduce how wluma reads the value, you need to repeat this line by hand:

https://github.com/maximbaz/wluma/blob/27624132a862af36e7d51c8ca215cf6f2dfbed1d/src/als/iio.rs#L58

cat /sys/bus/iio/devices/iio:device1/in_illuminance_raw

plus

cat /sys/bus/iio/devices/iio:device1/in_illuminance_offset

then all of that multiplied by:

cat /sys/bus/iio/devices/iio:device1/in_illuminance_scale

max-baz avatar Mar 07 '24 20:03 max-baz

Closing due to inactivity, if you have some updates, please share and let's reopen the thread :+1:

max-baz avatar Jun 16 '24 08:06 max-baz