Using xdotool to control the webgui

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
image

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

1 Like

Very interesting! :face_with_monocle: Thanks for sharing.

1 Like

Yeah came across this when doing research for another player. Only downside is that it fully depends on the GUI. With the resizing Manifest it will never make it to a plugin.
But now I can use the buttons to navigate, no need to connect a mouse.
Or even use the logic and use the IR-Controller.

And off coarse, your plugin node /data/plugins/user_interface/randomizer/randomTracks is under one of the buttons :grinning:

There is a beta version of randomizer which appears on the UI sources menu now so maybe you can access it that way….