Is it possible to call a script by "browsing"?
-
Yes, I could, but as I am talking about changing colors of LED buttons with Plasma, that would lead to no results that could help me for what I would like to. At least nothing, that I am aware of. Plasma is not returning any values. You throw a png at it, thats it. There seem to be ways of managing things with python but unfortunately, that s not my cup of tea.
Furthermore, calling plasmactl seems to be quiet ressource intensive. While browsing a gameslist with roms, a script in …/scripts/game-start calls it each time, hovering over (selecting) a game and becomes rather unresponsive.
No fun.I suspect, it is not a good idea, to call plasmactl from a shell script with the game-start-folder-method
-
I came up with a different solution with the help of a friend, that implements a daemon and three scripts.
1. Daemon Script
This script monitors the status file and triggers color changes based on the current menu (Systems Menu or Gamelist Menu).
Location: /home/pi/led_ram_daemon.sh#!/bin/bash # /home/pi/led_ram_daemon.sh # Path to the status file in RAM STATUS_FILE=“/dev/shm/led_ram_status.sh“ # Check if the status file exists. If not, create it. if [ ! -f "$STATUS_FILE“ ]; then echo "SYSTEMSLED=OFF“ > "$STATUS_FILE“ echo "GAMESLED=OFF“ >> "$STATUS_FILE“ fi # Function to read the status values and apply them to the LEDs apply_led_status() { # Load the current status source "$STATUS_FILE“ # Check if SYSTEMSLED should be turned ON if [ "$SYSTEMSLED“ == "ON“ ]; then # Set SYSTEMSLED to the ‚systemscolor‘ pattern (no output to console) plasmactl --pattern systemscolor > /dev/null 2>&1 fi # Check if GAMESLED should be turned ON if [ "$GAMESLED“ == "ON“ ]; then # Set GAMESLED to the ‚gamescolor‘ pattern (no output to console) plasmactl --pattern gamescolor > /dev/null 2>&1 fi } # Function to check for status changes check_status_change() { # Save the old status old_status=$(cat "$STATUS_FILE“) # Monitor status changes in a loop while true; do # If the status has changed, apply the new LED state new_status=$(cat "$STATUS_FILE“) if [ "$old_status“ != "$new_status“ ]; then apply_led_status # Apply changes to the LEDs old_status=$new_status # Set the new status as the old status fi sleep 0.1 # Wait 100 milliseconds before checking again done }
-
2. Systems-LED Script
Changes LED colors when in system-selection menu
Location:
/opt/retropie/configs/all/emulationstation/scripts/system-select/led_ram_systems.sh#!/bin/bash # /opt/retropie/configs/all/emulationstation/scripts/system-select/led_ram_systems.sh # Path to the status file in RAM STATUS_FILE=“/dev/shm/led_ram_status.sh“ # Set the System-LED status to „ON“ and the Game-LED status to „OFF“ echo "SYSTEMSLED=ON“ > "$STATUS_FILE“ echo "GAMESLED=OFF“ >> "$STATUS_FILE“
-
3. Games-LED Script
Changes LED colors when browsing roms / games
/opt/retropie/configs/all/emulationstation/scripts/game-select/led_ram_games.sh#!/bin/bash # /opt/retropie/configs/all/emulationstation/scripts/system-select/led_ram_systems.sh # Path to the status file in RAM STATUS_FILE=“/dev/shm/led_ram_status.sh“ # Set the System-LED status to „ON“ and the Game-LED status to „OFF“ echo "GAMESLED=ON" > "$STATUS_FILE" echo "SYSTEMSLED=OFF" >> "$STATUS_FILE"
-
Excursion: Using a status file under /dev/shm
Saving the status file in /dev/shm (temporary filesystem, stored in RAM) is improving performance and prevent wear on the SD card.
-
Speed: Reading from and writing to /dev/shm is faster than accessing files stored on the SD card, which is especially important if the script is running in a loop and frequently checking for status
changes. This improves the responsiveness of the LED color changes without putting excessive load on the system. -
Temporary Storage: The status file only needs to exist for the duration of the session. Once the system is rebooted, the /dev/shm directory is cleared automatically, so there is no need to manage or clean up the status file manually.
-
What is Stored in the Status File?: The status file stores the current state of the LEDs (whether the
system is in „Systems Menu“ or „Games Menu“).
Specifically, it holds two variables:
SYSTEMSLED: „ON“ or „OFF“ (indicates whether the system LED colorset should be on or off).
GAMESLED: „ON“ or „OFF“ (indicates whether the game LED colorset should be on or off).The file is written in a simple key-value format:
SYSTEMSLED=ON GAMESLED=OFF
Whenever the LED state changes, the script updates this file with the new values. The daemon then reads the file, and based on its contents, updates the LED colors accordingly.
-
-
Excursion: Tradeoff between performance and responsiveness
The daemon script uses a small delay (sleep 0.1) between each check of the status file to balance performance and responsiveness.
-
Why the Delay?
The delay ensures that the daemon does not overwhelm the system with constant checks, which could lead to excessive CPU usage and lagging while browsing roms / gameslists. By introducing a rather small delay of 100 milliseconds, the script remains quiet responsive enough to changes but does not use too many system resources. -
Adjusting the Delay:
One can customize the delay to fit personal preferences. To make the script more responsive (i.e., faster reaction to color changes), reduce the sleep time (e.g., sleep 0.05 for 50 milliseconds). Conversely, to improve system performance further, increase the sleep time (e.g., sleep 0.2 for 200 milliseconds). The delay is located in the check_status_change function of the daemon script (under 1.1)
-
-
4. Setting up the "LED RAM Daemon"
The daemon should runs automatically on system startup, with the help of systemd service. This service will start the led_ram_daemon.sh script in the background.Location of the systemd service file:
/etc/systemd/system/led_ram_daemon.service[Unit] Description=LED RAM Daemon Service After=network.target [Service] Type=simple ExecStart=/home/pi/led_ram_daemon.sh Restart=always User=pi Group=pi [Install] WantedBy=multi-user.target
Enabing the service:
sudo systemctl enable led_ram_daemon.service
Starting service manually:
sudo systemctl start led_ram_daemon.service
Logging
journalctl -u led_ram_daemon.service
-
5. Configuring autostart.sh for EmulationStation
In order to make sure that the system starts the daemon on boot and manages the LEDs when starting EmulationStation, there needs to be an addition in the autostart.sh file
Location: /opt/retropie/configs/all/autostart.sh
Include before everything else
cp /home/pi/led_ram_daemon.sh /dev/shm/ /dev/shm/led_ram_daemon.sh &
This setup copies the led_ram_daemon.sh script to /dev/shm/ (a temporary in-memory filesystem) each time the system starts. Running the script from /dev/shm/ can improve its responsiveness, as accessing files in RAM is generally faster than from disk. After copying, the daemon starts in the
background, and EmulationStation launches automatically. -
6. Pattern Images for Plasma
Plasma uses png files for LED patterns with plasmactl command
They need to be available in /etc/plasmagamespattern.png
systemspattern.pngFor further infos see the docs
-
7. Final Steps
Scripts need to be executable!
After placing the scripts in their respective directories, this can be done by running:chmod +x /home/pi/led_ram_daemon.sh chmod +x /opt/retropie/configs/all/emulationstation/scripts/system-select/led_ram_systems.sh chmod +x /opt/retropie/configs/all/emulationstation/scripts/game-select/led_ram_games.sh
Rebooting Pi to ensure the daemon starts properly and the LED color patterns are correctly applied.
## HAVE FUN AND ENJOY!
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.