Raspbian - bash - Problème avec if [ ] then if [ ] then
Bonjour, mes conditions secondaires avec "if" ne fonctionne pas. Dois-je passer par "elif" nécessairement où s'agit-il d'un problème de syntaxe ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| #!/bin/bash
clear
x=150
y=150
mouve="arrêt"
tourne="tout droit"
#robot à l'arrêt (pin12 bcm : 150), direction devant (pin 18 bcm: 150)
gpio -g mode 12 pwm;gpio pwm-ms;gpio pwmc 192;gpio pwmr 2000;gpio -g pwm 12 $x
gpio -g mode 18 pwm;gpio pwm-ms;gpio pwmc 192;gpio pwmr 2000;gpio -g pwm 18 $y
#lancement du streaming
tput cup 1 20;echo "... lancement du streaming ..."
tput cup 2 20;echo "lire avec : cvlc tcp/MJPEG://192.168.0.12:1234"
printf "$(raspivid -n -t 0 -w 640 -h 480 -vf -hf -cd MJPEG -l -o tcp://0.0.0.0:1234)" &
#lire coté client avec : "cvlc tcp/MJPEG://192.168.0.12:1234" (MJPEG en majuscule)
sleep 2
tput cup 3 20;printf "qqq ou Ctrl+c pour arréter"
tput cup 5 2;echo $mouve
tput cup 6 2;echo "position de la roue :" $tourne
while true
do
read -rsn3 -d '' TOUCHE
case ${TOUCHE:2} in
A) TOUCHE="↑" ;;
B) TOUCHE="↓" ;;
C) TOUCHE="→" ;;
D) TOUCHE="←" ;;
q) TOUCHE="q" ;;
esac
if [ $TOUCHE = "↑" ];then
if [ $y=50 ];then y=128;mouve=arrière lente;fi
if [ $y=128 ];then y=150;mouve=arrêt;fi
if [ $y=150 ];then y=170;mouve=avance lente;fi
if [ $y=170 ];then y=240;mouve=avance rapide;fi
gpio -g mode 18 in;gpio -g mode 12 pwm;gpio pwm-ms;gpio pwmc 192;gpio pwmr 2000;gpio -g pwm 12 $y
fi
if [ $TOUCHE = "↓" ];then
if [ $y=240 ];then y=170;mouve=avance lente;fi
if [ $y=170 ];then y=150;mouve=arrêt;fi
if [ $y=150 ];then y=128;mouve=arrière lente;fi
if [ $y=128 ];then y=50;mouve=arrière rapide;fi
gpio -g mode 18 in;gpio -g mode 12 pwm;gpio pwm-ms;gpio pwmc 192;gpio pwmr 2000;gpio -g pwm 12 $y
fi
if [ $TOUCHE = "→" ];then
if [ $x=52 ];then x=105;tourne=tout droit;fi
if [ $x=105 ];then x=220;tourne=à droite;fi
gpio -g mode 12 in;gpio -g mode 18 pwm;gpio pwm-ms;gpio pwmc 192;gpio pwmr 2000;gpio -g pwm 18 $x
fi
if [ $TOUCHE = "←" ];then
if [ x=220 ];then x=105;tourne=tout droit;fi
if [ x=105 ];then x=52;tourne=à gauche;fi
gpio -g mode 12 in;gpio -g mode 18 pwm;gpio pwm-ms;gpio pwmc 192;gpio pwmr 2000;gpio -g pwm 18 $x
fi
if [ $TOUCHE = "q" ];then killall raspivid;gpio -g mode 12 in; gpio -g mode 18 in;exit
fi
clear
tput cup 3 20;printf "qqq ou Ctrl+c pour arréter"
tput cup 5 2;echo $mouve
tput cup 6 2;echo "position de la roue :" $tourne
#tput cup 8 5
#echo "La flèche est \"${TOUCHE}\""
done |
Merci