My approach was to make a script that would run at shutdown. Shutdown scripts are handled at /lib/systemd/system-shutdown/, so the steps here are (1) make a script that turns the TFT backlight off, (2) put that script in the system-shutdown folder.
Make the script by doing the following:
- CODE: SELECT ALL | TOGGLE FULL SIZE
- sudo nano /lib/systemd/system-shutdown/blanktft.sh
Paste in the following code:
- CODE: SELECT ALL | TOGGLE FULL SIZE
- #!/bin/bash
mount -oremount,rw /
sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
mount -oremount,ro /
The "mount -oremount" is for loading and unloading the filesystem. I wasn't having luck getting the script to execute without it, and I believe that's because necessary elements of the filesystem are already off when this script loads.
Save that file, then make it executable by:
- CODE: SELECT ALL | TOGGLE FULL SIZE
- chmod +x /lib/systemd/system-shutdown/blanktft.sh
Boom. That's it!
You can test it by running the script as so:
- CODE: SELECT ALL | TOGGLE FULL SIZE
- sudo /lib/systemd/system-shutdown/blanktft.sh
You should see the TFT turn off.
Turn it back on with:
- CODE: SELECT ALL | TOGGLE FULL SIZE
- sudo sh -c 'echo "1" > /sys/class/backlight/soc\:backlight/brightness'
Reboot or shutdown to see it in action!