[ARCHIVE] HOW TO CONFIGURE LEDS AND SHUTDOWN BUTTON WITH RECALBOX

Publié le : 15/04/2016 21:36:42
Catégories : Tutoriels

We wrote a little script for recalbox to make one led light up when emulation is running and the other to light up when in menu. Copy ths script at /recalbox/scripts/NuxiiIRLED.sh:

#!/bin/bash 
LED1=22
LED2=27
cd /sys/class/gpio
echo "$LED1" > export
echo out > gpio$LED1/direction
echo 0 > gpio$LED1/value
cd /sys/class/gpio
echo "$LED2" > export
echo out > gpio$LED2/direction
echo 1 > gpio$LED2/value
while true;
do retroarch=$(ps -ef | grep retroarch | grep -v "grep" | wc -l)
if [ $retroarch -eq 0 ]; # If retroarch is playing
then
echo 0 > gpio$LED1/value
echo 1 > gpio$LED2/value
else
echo 0 > gpio$LED2/value
echo 1 > gpio$LED1/value
fi
sleep 1
done
chmod +x /recalbox/scripts/NuxiiIRLED.sh

To make the button act as a shutdown/reset button in Recalbox, the easiest way would be to use a bash script to read GPIO button input. Copy this script to /recalbox/scripts/NuxiiShutdown.sh: 

#!/bin/bash 
SHUTDOWN=3
echo "$SHUTDOWN" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$SHUTDOWN/direction
#This loop continuously checks if the shutdown button was pressed
#It sleeps as long as that has not happened.
buttonstate1=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
while true; do
shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value)
if [ $shutdownSignal = $buttonstate1 ]; then
/bin/sleep 0.5 else shutdown -h now
fi
done
chmod +x /recalbox/scripts/NuxiiShutdown.sh
You need to tell the system to start those scripts at boot. In order to that, create this file /etc/init.d/S02NuxiiComponents: 
#!/bin/bash
case "$1" in
start)
(sh /recalbox/scripts/NuxiiIRLED.sh)&;
(sh /recalbox/scripts/NuxiiShutdown.sh)&;
;; stop)
;; restart|reload)
;; *)
esac
exit $?

Reboot Your button should work and one of your led light up. Recalbox has now integrated feature for pushbutton. See recalbox.conf
To configure your infrared receiver, see https://github.com/recalbox/recalbox-os/wiki/Infra-red-remote-control-on-the-Recalbox-%28EN%29 Rasberry Pi B+/2/3 GPIO Numbers
Rasberry Pi B+/2/3 GPIO Numbers

Partager ce contenu