#!/bin/bash
#make by G.R.H

if [ ! -f /usr/bin/mpv ]; then
	echo "Error: The necessary playback files are missing and the program cannot run."
	exit 1
fi
. /mnt/mod/ctrl/configs/key_config &>/dev/null
progdir="$(cd $(dirname "$0"); pwd)"

pkill -f mpv
pkill -f evtest
mpv --really-quiet --image-display-duration=6000 "${progdir}/res/led.png" &

while true
do
	Test_Button_A
	if [ "$?" -eq "10" ]; then
		echo 0 > /sys/class/power_supply/axp2202-battery/work_led
		led_s=0
	fi
	Test_Button_Y
	if [ "$?" -eq "10" ]; then
		echo 1 > /sys/class/power_supply/axp2202-battery/work_led
		led_s=1
	fi
	Test_Button_FUNC
	if [ "$?" -eq "10" ]; then
		break
	fi
done
case $led_s in
	0)
		pkill -f mpv
		mpv --really-quiet --image-display-duration=3 "${progdir}/res/ledoff.png"
	;;
	1)
		pkill -f mpv
		mpv --really-quiet --image-display-duration=3 "${progdir}/res/ledon.png"
	;;
esac
pkill -f mpv
pkill -f evtest
exit 0
