From c6fc72134f3e11bab508e6bc01517d4e6804bc01 Mon Sep 17 00:00:00 2001 From: lookshe Date: Sat, 20 Sep 2014 20:02:46 +0200 Subject: Update and rename rasp_starup.py to rasp_startup.py --- rasp_startup.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rasp_starup.py | 59 -------------------------------------------------------- 2 files changed, 60 insertions(+), 59 deletions(-) create mode 100644 rasp_startup.py delete mode 100644 rasp_starup.py diff --git a/rasp_startup.py b/rasp_startup.py new file mode 100644 index 0000000..1cedf8f --- /dev/null +++ b/rasp_startup.py @@ -0,0 +1,60 @@ +import RPi.GPIO as GPIO +import time +import thread +import subprocess + +# pin-setup +GPIO.setmode(GPIO.BOARD) +led_pin = 12 +blk_pin = 16 +red_pin = 18 + +# set volume +cmd_amixer1 = 'amixer -c 0 set PCM 98%' +cmd_amixer2 = 'amixer -c 0 set Speaker 98%' + +# the process we want to start and its argument +cmd_player = 'mplayer' +arg_player = 'http://192.168.1.33:8000/mpd.ogg' +process = 0 + +def playerThreadFunc(): + # we need in every thread, so it is a global + global process + # kill if running + if process != 0: + if process.poll() == None: + process.terminate() + subprocess.call(['killall', cmd_player], shell=True) + time.sleep(1) + # turn on led + GPIO.output(led_pin, True) + # start process and wait for termination + process = subprocess.Popen([cmd_player, arg_player]) + process.wait() + # turn off led + GPIO.output(led_pin, False) + +# callback function +def callBackFunc(channel=0): + thread.start_new_thread(playerThreadFunc, ()) + +# init +GPIO.setup(led_pin, GPIO.OUT) +GPIO.setup(blk_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(red_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + +# add event +GPIO.add_event_detect(blk_pin, GPIO.RISING, callback=callBackFunc, bouncetime=300) + +while True: + subprocess.call(cmd_amixer1, shell=True) + subprocess.call(cmd_amixer2, shell=True) + thread.start_new_thread(playerThreadFunc, ()) + GPIO.wait_for_edge(red_pin, GPIO.FALLING) + break + +# clean +GPIO.cleanup() + +subprocess.call('shutdown -h now', shell=True) diff --git a/rasp_starup.py b/rasp_starup.py deleted file mode 100644 index 37856b9..0000000 --- a/rasp_starup.py +++ /dev/null @@ -1,59 +0,0 @@ -import RPi.GPIO as GPIO -import time -import thread -import subprocess - -# pin-setup -GPIO.setmode(GPIO.BOARD) -led_pin = 12 -blk_pin = 16 -red_pin = 18 - -# set volume -cmd_amixer1 = 'amixer -c 0 set PCM 98%' -cmd_amixer2 = 'amixer -c 0 set Speaker 98%' - -# the process we want to start and its argument -cmd_player = 'mplayer' -arg_player = 'http://192.168.1.33:8000/mpd.ogg' -process = 0 - -def playerThreadFunc(): - # we need in every thread, so it is a global - global process - # kill if running - if process != 0: - if process.poll() == None: - process.terminate() - time.sleep(1) - # turn on led - GPIO.output(led_pin, True) - # start process and wait for termination - process = subprocess.Popen([cmd_player, arg_player]) - process.wait() - # turn off led - GPIO.output(led_pin, False) - -# callback function -def callBackFunc(channel=0): - thread.start_new_thread(playerThreadFunc, ()) - -# init -GPIO.setup(led_pin, GPIO.OUT) -GPIO.setup(blk_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) -GPIO.setup(red_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) - -# add event -GPIO.add_event_detect(blk_pin, GPIO.RISING, callback=callBackFunc, bouncetime=300) - -while True: - subprocess.call(cmd_amixer1, shell=True) - subprocess.call(cmd_amixer2, shell=True) - thread.start_new_thread(playerThreadFunc, ()) - GPIO.wait_for_edge(red_pin, GPIO.FALLING) - break - -# clean -GPIO.cleanup() - -subprocess.call('shutdown -h now', shell=True) -- cgit v1.2.3