Proximity / ambient light sensor
#1
Going off into my thoughts in the flashlight app thread I have been trying to see where the proximity /light sensor is being monitored to blank the screen if covered. I have not yet found where this is but suspect it is programmed within phosh/phoc. I was hoping to add a section to this where if the light level is above the threshold to blank the screen but below another threshold it would change the gtk theme to a dark variant.

After spending some time looking and not finding, I thought it might be done with an udev rule like:
Code:
# Set the theme based on light level
ACTION=="add|change", SUBSYSTEM=="iio", KERNEL=="iio:device1", ATTR{in_illuminance_raw}=="[0-9]|[0-9][0-9]", RUN+="/bin/su mobian -c /usr/local/bin/set-dark-theme"

Where set-dark-theme contains
Code:
#!/bin/sh
gsettings set org.gnome.desktop.interface gtk-theme Adwaita-dark

Of course doing only this would need a manual reset; but it should be good enough for testing...
Unfortunately the event does not trigger when the light level changes, only when the sensor is added as far as udev is concerned. This works by restarting udev which is nice, but does not really help anything.

Next I thought to hook into the lock screen unlock where a script would run to check the value in /sys/bus/iio/devices/iio\:device1/in_illuminance_raw and set the theme accordingly. (If you had an incorrect theme pressing the power button and unlocking would switch it) Tried a few spots that I thought might hook into the lock screen but without success.

It is probably not the best idea to constantly probe. However as a proof of concept, a simple bash script. (Most visible difference with gnome-clocks and the flashlight app)
Code:
#!/bin/sh
while : ; do
    reading=`cat /sys/bus/iio/devices/iio\:device1/in_illuminance_raw`
    if [ "$reading" -lt "100" ]; then
        gsettings set org.gnome.desktop.interface gtk-theme Adwaita-dark
        while : ; do
            reading=`cat /sys/bus/iio/devices/iio\:device1/in_illuminance_raw`
            if [ "$reading" -gt "100" ]; then
                gsettings set org.gnome.desktop.interface gtk-theme Adwaita
                break;
            fi
            sleep 10;
        done
    sleep 10;
    fi
done       

Any information/pointers to bring this past a looping bash script?


Messages In This Thread
Proximity / ambient light sensor - by antiX-Dave - 07-07-2020, 10:21 PM
Proximity / ambient light sensor - by e-minguez - 07-07-2020, 11:25 PM
RE: Proximity / ambient light sensor - by a-wai - 07-08-2020, 02:10 AM
RE: Proximity / ambient light sensor - by wibble - 07-08-2020, 03:32 AM
RE: Proximity / ambient light sensor - by vicky - 07-08-2020, 02:17 PM
RE: Proximity / ambient light sensor - by devrtz - 07-08-2020, 02:24 PM
RE: Proximity / ambient light sensor - by wibble - 07-08-2020, 04:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Proximity sensor is oversensitive (was "Screen blanks when making call") treebeard 5 2,809 08-02-2022, 03:16 PM
Last Post: treebeard
  Notification light when entering low power Barugon 5 3,475 11-22-2021, 06:20 AM
Last Post: beta-user
  Proximity sensor dims screen doidolinux 8 4,197 08-09-2021, 11:14 PM
Last Post: tllim
  Toggle light & dark themes with a launcher. MtnSk8 0 1,455 03-14-2021, 12:20 AM
Last Post: MtnSk8
  After update the green light comes on then the system hangs joz_mak 6 6,556 11-11-2020, 09:23 AM
Last Post: antiX-Dave
  Proximity sensor always active - screen turns off randomly? bitnick 10 10,208 09-12-2020, 03:58 AM
Last Post: a-wai
  led light jesica 27 30,139 09-11-2020, 11:01 AM
Last Post: ergo owl

Forum Jump:


Users browsing this thread: 1 Guest(s)