Command line - return data / feedback
Posted: Tue May 02, 2017 2:51 pm
Are there any commands that return data or anything from a PS3 that we can use to confirm the PS3 received and processed the command?
Code: Select all
#!/bin/bash
default_delayT=0.007
delayT=${default_delayT}
afterPause=0.15
dstAddr="127.0.0.1:51000"
ps3IP="192.168.1.199"
ps3Addr="08:A9:5A:xx:xx:xx"
ctlrAddr="64:D4:BD:xx:xx:xx"
reconn=false
ps3Ping=true
if [ $# -gt 1 ]; then
delayT=$2
fi
pingPS3() {
ping -c 1 -W 1 ${ps3IP}>/dev/null
if [ $? -eq 0 ]; then
ps3Ping=true
else
ps3Ping=false
fi
}
stat() {
jobs
ps ax|grep "[g]imx -t Sixaxis -s ${dstAddr}"
pingPS3
echo "ps3Ping: $ps3Ping"
}
sendCMD() {
#startGIMX
gimx -e "$1(255)" -d ${dstAddr} > /dev/null
sleep ${delayT}
gimx -e "$1(0)" -d ${dstAddr} > /dev/null
sleep ${afterPause}
}
setBDAddr() {
bdaddr -i hci0|grep ${ctlrAddr} >/dev/null || bdaddr -r -i hci0 ${ctlrAddr} >/dev/null
}
startGIMX() {
reconn=false
gStat=`ps ax -o pid,stat,command|grep "[g]imx -t Sixaxis -s ${dstAddr}" | awk {'print$2'}`
#echo ${gStat}
if [ "${gStat}" != "S" ]; then
reconn=true
pingPS3
if [ "${gStat}" != "" ]; then
stopGIMX
sleep 4
fi
echo "no GIMX instance running. starting."
setBDAddr
gimx -t Sixaxis -s ${dstAddr} -b ${ps3Addr} >/dev/null &
#sleep 17
if [ "${1}" != "on" ] && [ "$ps3Ping" == "false" ]; then
echo "PS3 was powered down. Waiting until fully powered on."
sleep 34
elif [ "${1}" != "gimx_start" ]; then
sleep 0.1
fi
fi
}
stopGIMX() {
gpid=`pgrep -f "gimx -t Sixaxis -s ${dstAddr}"`
if [ "$gpid" != '' ]; then
echo "gimx pid $gpid found. killing."
kill -9 $gpid
fi
}
catTV() {
for i in {1..9}
do
sendCMD "right"
done
for i in {1..4}
do
sendCMD "left"
done
for i in {1..9}
do
sendCMD "up"
done
}
if [ "${1}" == "stat" ]; then
stat
return
fi
if [ "${1}" != "on" ] && [ "${1}" != "off" ] && [ "${1}" != "gimx_start" ] && [ "${1}" != "gimx_stop" ]; then
startGIMX
fi
if [ "${1}" == "gimx_start" ]; then
startGIMX
elif [ "${1}" == "gimx_stop" ]; then
stopGIMX
elif [ "${1}" == "on" ]; then
#startGIMX "on"
startGIMX
elif [ "${1}" == "off" ]; then
pingPS3
if ! $ps3Ping
then
echo "PS3 already powered down. nothing to do."
return
fi
startGIMX
if $reconn
then
echo "had to reconnect to PS3. waiting on new gimx instance."
sleep 8
fi
for i in {1..5}
do
sendCMD circle
done
delayT=3.5
sendCMD "PS"
delayT=${default_delayT}
for i in {1..5}
do
sendCMD "down"
done
sleep 0.5
sendCMD "up"
sendCMD "cross"
sendCMD "left"
sleep 0.5
sendCMD "cross"
sleep 2
stopGIMX
sleep 5
elif [ "${1}" == "exit" ]; then
delayT=1.2
sendCMD "PS"
delayT=${default_delayT}
for i in {1..5}
do
sendCMD "up"
done
sendCMD "cross"
sleep 0.5
sendCMD "left"
sleep 0.5
sendCMD "cross"
elif [ "${1}" == "netflix" ]; then
catTV
sendCMD "down"
sendCMD "cross"
sleep 33
sendCMD "cross"
elif [ "${1}" == "youtube" ]; then
catTV
for i in {1..4}
do
sendCMD "down"
done
sendCMD "cross"
elif [ "${1}" == "hulu" ]; then
catTV
for i in {1..3}
do
sendCMD "down"
done
sendCMD "cross"
else
sendCMD $1
fi
Code: Select all
pi@storagepi:~/gimx $ cat gimx_out
controller #1: option -t with value `Sixaxis'
controller #1: option -s with value `127.0.0.1:51000'
controller #1: option -b with value `08:A9:5A:xx:xx:xx'
now reading arguments for controller #2
using default refresh period: 10.00ms
controller #1: option -e with value `down(255)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(0)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(255)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(0)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(255)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(0)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(255)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(0)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(255)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
controller #1: option -e with value `down(0)'
controller #1: option -d with value `127.0.0.1:51000'
now reading arguments for controller #2
Remote GIMX detected, controller type is: Sixaxis.
using default refresh period: 10.00ms
Code: Select all
gimx --status -t Sixaxis -s ${dstAddr} -b ${ps3Addr} >>${server_out} &
Code: Select all
connUp=`tail -n 2 ${server_out}|head -n 1|awk '{print $1}'`
while [ $connUp != "0" ]
do
gimx -e "circle(0)" -d ${dstAddr} >>${cmd_out}
connUp=`tail -n 2 ${server_out}|head -n 1|awk '{print $1}'`
sleep 0.2
#connUp="0"
done
Code: Select all
pi@storagepi:~/gimx $ cat output
no GIMX instance running. starting.
controller #1: option -t with value `Sixaxis'
controller #1: option -s with value `127.0.0.1:51000'
controller #1: option -b with value `08:A9:5A:xx:xx:xx'
now reading arguments for controller #2
status flag is set
using default refresh period: 10.00ms
Warning: can't open macro directory /home/pi//.gimx//macros/
connecting with hci0 = 64:D4:BD:xx:xx:xx to 08:A9:5A:xx:xx:xx psm 0x0011
connecting with hci0 = 64:D4:BD:xx:xx:xx to 08:A9:5A:xx:xx:xx psm 0x0013
connected with hci0 = 64:D4:BD:xx:xx:xx to 08:A9:5A:xx:xx:xx
0 1494911333.562464
0 1494911338.552722
0 1494911338.742662
0 1494911339.001443, up (255)
0 1494911339.046428