Using an existing cabinet with a small touch display 480*640, which is impossible to control by hand I was looking for a way to control it using GPIO. Since Volumio doesn’t provide any alternative to control the GUI, by commands or API, I decided to use xdotool.
sudo apt-get install xdotool
.
with xdotool you can simulate keystrokes and mouse movements.
Locate the mouse on the screen item, like menu and run from shell
XAUTHORITY=~volumio/.Xauthority DISPLAY=:0 xdotool getmouselocation --shell
this will give you the coordinates for the top menu. Now you use these coordinates to place a the mouse on the menu and click it.
XAUTHORITY=~volumio/.Xauthority DISPLAY=:0 xdotool mousemove 39 48 mousedown 1 click 1
You can repeat this for other menu items your interested in.
Now I am able to control the GUI via GPIO and Rotary encoders.
Example script:
#!/bin/bash
# select
# pin GND - D0
GPIO0=25 # GUI => GUI
# Print debug lines => 1 is print
debug=1
# Common path for all GPIO access
BASE_GPIO_PATH=/sys/class/gpio
# Utility function to export a pin if not already exported
exportPin()
{
if [ ! -e $BASE_GPIO_PATH/gpio$1 ]; then
echo "$1" > $BASE_GPIO_PATH/export
fi
}
# Utility function to set a pin as an output
setInput()
{
echo "out" > $BASE_GPIO_PATH/gpio$1/direction
echo "1" > $BASE_GPIO_PATH/gpio$1/value
}
function cleanup()
{
if [ ! -e $BASE_GPIO_PATH/gpio$1 ]; then
echo "$1" > $BASE_GPIO_PATH/unexport
fi
}
cleanup $GPIO0
exportPin $GPIO0
setInput $GPIO0
if [ $debug == 1 ]; then
echo "---------------------------------------------------"
printf "GPIO 0: %s\n" "${GPIO0}"
printf "STATUS 0: %s\n" "${STATUS0}"
fi
# continuously monitor current value
while true; do
sleep 0.1
STATUS0=$(cat $BASE_GPIO_PATH/gpio${GPIO0}/value)
if [ $debug == 1 ]; then
echo "---------------------------------------------------"
printf "STATUS 0: %s\n" "${STATUS0}"
fi
if [ "$STATUS0" == 0 ]; then
XAUTHORITY=~volumio/.Xauthority DISPLAY=:0 xdotool mousemove 39 48 mousedown 1 click 1
sleep 0.2
fi
done