Thank you for your donation!


Touchscreen life
#3
After a lot of googling and adding a lot of pieces together I solved the problem for my situation. 
In stead of relying on the built-in screensaver I installed 'xprintidle'. This is a utility that keeps track of how long (in milliseconds) no interaction has taken place with the system. So when the screen is not touched for, let's say, ten seconds, xprintidle will return 10000. Then I wrote a shell script that loops and checks if the value from xprintidle is bigger than a preset value. If it is, a relay (that replaces the switch on the back of the screen's PCB) is triggered by a GPIO pin and the backlight from the screen is turned off. If its not, the relay will be off and the backlight on (I use the NO contact on the relay so the backlight will be on if something is wrong with the relay). I then set this script to start running at boot and voila, a home baked screen- backlight-saver for my touchscreen. 
For now I don't blank the screen in the script, although that should not be too difficult. But since that function is already available in Moode, simply setting that value a bit higher than the trigger value in the script will blank the screen (even though you wont see that anymore since the backlight is off).

Here is my script, mostly stolen from various websites. I'm not a programmer so this is most likely not the best code ever written. Most important flaw: there is no error checking at all. So if anything goes wrong the the script will either hang or continue doing the wrong thing, either way the Pi may crash. Maybe somebody with more experience in this field can help here.
Also I don't know how heavy the load on the CPU is, shouldn't be much but I have not been able to test this while playing some music yet. Hopefully I'll know more about that tomorrow. 

Code:
#!/bin/sh

#We start with 'defining' the display. Without this xprintidle will give an error.
export DISPLAY=:0

#To use a GPIO pin for the relay we have to first define it.
#I use pin GPIO24 because it is not in use by my DAC. Other DAC's might use this pin so check before use.
echo "24" >/sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio24/direction

# Wanted trigger timeout in milliseconds.
IDLE_TIME=$((10*1000))

#Bool to keep track of on or off
triggered=false

#Since the script is executed at startup, I wait a bit so other processes can start.
#can be left out, but you might not see the GUI screen come up before the backlight is turned off...
sleep 10

#loop forever
while true
do
   idle=$(xprintidle)
   if [ $idle -ge $IDLE_TIME ]; then
       if ! $triggered; then
           triggered=true

           #Make GPIO 24 high so the backlight will turn off
           echo "1" > /sys/class/gpio/gpio24/value
       fi
   else
       triggered=false
       #Make GPIO 24 low so the backlight will turn on again
       echo "0" > /sys/class/gpio/gpio24/value

   fi

#Pause the script for one second, this reduces the load. One second is fast enough for the screen to
#come back on without feeling it does not react to touch.
sleep 1

done

I named the script setStartOptions.sh, left it in /home/pi so when you add this line to etc/rc.local:

sudo sh /home/pi/setStartOptions.sh & > /home/pi/startLog.txt 2>&1

the script will start to run on startup. It will keep a logfile, but since there is no error checking in the script I doubt if that will be helpful at all.


PS: Since I don't have an 'official' RPI touchscreen I don't know if it can be applied there too. BTW, my TV goes black and turns the backlight off when no signal is present. Putting/uncommenting "Since I don't have an 'official' RPI touchscreen I don't know if it can be applied there too. BTW, my TV goes black and turns the backlight off when no signal is present. Putting/uncommenting 'hdmi_blanking=1' in '/boot/config.text' does that trick...
Reply


Messages In This Thread
Touchscreen life - by DRONE7 - 02-07-2019, 05:28 AM
RE: Touchscreen life - by arjena - 04-21-2019, 10:25 PM
RE: Touchscreen life - by arjena - 04-23-2019, 11:23 PM

Forum Jump: