Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/expect --
- set timeoff 5
- set server localhost
- set port 6600
- #set onplay [lindex $argv 2]
- set onplay /home/pi/gpio/poweron.sh
- #set noplay [lindex $argv 3]
- set noplay /home/pi/gpio/poweroff.sh
- #set onstop [lindex $argv 3]
- set timeout -1
- log_user 0
- trap {send "close\r"
- exit} {SIGINT SIGTERM}
- send_user "Starting connection to MPD [lrange $argv 0 1]\r\n"
- send_user "On play: $onplay\r\n"
- send_user "On no play: $noplay\r\n"
- #send_user "On stop: $onstop\r\n"
- #spawn -noecho telnet [lindex $argv 0] [lindex $argv 1]
- spawn -noecho telnet $server $port
- expect {
- "OK MPD" {
- send_user "Connected\r\n"
- }
- }
- send "status\r"
- expect {
- "state: play" {
- set currentState "play"
- }
- "state: pause" {
- set currentState "noplay"
- }
- "state: stop" {
- set currentState "noplay"
- }
- }
- send_user "Initial state $currentState\r\n"
- send "idle player\r"
- for {} 1 {} {
- expect {
- timeout {
- if { "$noplay" != "" } {
- exec "$noplay"
- }
- send_user "Timeout, off speakers\r\n"
- set timeout -1
- }
- "changed: player" {
- send_user "Changed status player\r\n"
- send "status\r"
- }
- "state: play" {
- send_user "Status: play\r\n"
- if { "$currentState" != "play" } {
- send_user "State changed to play\r\n"
- if { "$onplay" != "" } {
- exec $onplay
- }
- set timeout -1
- set currentState "play"
- }
- send "idle player\r"
- }
- "state: pause" {
- send_user "Status: pause\r\n"
- if { "$currentState" != "noplay" } {
- send_user "State changed to pause\r\n"
- set timeout $timeoff
- set currentState "stop"
- }
- send "idle player\r"
- }
- "state: stop" {
- send_user "Status: stop\r\n"
- if { "$currentState" != "noplay" } {
- send_user "State changed to stop\r\n"
- set timeout $timeoff
- set currentState "stop"
- }
- send "idle player\r"
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement