0

I'm trying to make a init.d script

I got this so far:

while true
do
if dumpsys input | grep "Last Raw Touch: pointerCount=1"; then echo '1' > /storage/emulated/0/sleepstate
else
echo '0' > /storage/emulated/0/sleepstate
    fi
done

If I touch the Screen of my Android device the file sleepstate will have the number 1 written to it If I dont touch the screen 0 will be written

this would be file #1

file #2 would be

while true
do
if "reading the file sleepstate will show '1'"; then
    echo '1' > /sys/devices/soc/leds-qpnp-9/leds/button-backlight/brightness
sleep 5
    else
If "reading the file sleepstate will show '0'"; then
    echo '0' > /sys/devices/soc/leds-qpnp-9/leds/button-backlight/brightness
    fi
done

The lines of file #2 would turn the Key Lights of my phone on and off

enter image description here

In the Picture you can see the first Script i was using, the problem was If I touched the Screen exactly after the 5th second the Key Lights would turn off for a second, this can be noticed if i'm typing for example since there is no recheck done while sleep 5 is being processed.

What I want to do is after touching the Touchscreen the Key Lights should turn on for 5 Seconds and If the Display is not touched for 5 Seconds the Key Lights should turn off, for every Touch i make while the 5 sleep Seconds are processed the 5 Seconds timeout should be restarted not like in the Script in the Picture where the 5 Seconds are just processed and if i touched the Screen in the 3rd second the 5 second Timer will not be reset.

That's why I'm trying to use 2 files hoping that everytime I touch and 1 gets written to the sleepstate file the sleep 5 timer and turning key lights on will be executed again.

Bharata
  • 13,509
  • 6
  • 36
  • 50
Sergej
  • 1

0 Answers0