|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- import subprocess
- import sys, inspect, os
-
- import wiringpi
- import time
- from time import sleep
-
- import lirc
-
- import mpd
-
- from pyudmx import pyudmx
-
- # GPIO
- pin_kugel = 2
- pin_sun = 4
- pin_pir = 0
-
- dmxScenes = {
- "fadecolors":[255,255,255,255,255,192],
- "plain-red":[255,255,0,0,0,0],
- "strobe":[190,255,255,255,0,0],
- "nini":[120,0,255,255,0,224],
- "black":[0,0,0,0,0,0]
- }
-
- dmxUserScenes = [
- [255,255,255,255,255,192],
- [255,255,0,0,0,0],
- [255,0,255,0,0,0],
- [255,0,0,255,0,0],
- [255,0,180,180,0,0],
- [190,255,255,255,0,0],
- [120,0,255,255,0,224]
- ]
-
- def setDmxScene(scene):
- cv = [0 for v in range(0, 512)]
- errorcode = [240,255,0,0,0,0]
- for index, val in enumerate(dmxScenes.get(scene,errorcode)):
- cv[index] = val
- dev.send_multi_value(1, cv)
-
-
- def setUserDmxScene(scene):
- cv = [0 for v in range(0, 512)]
- for index, val in enumerate(dmxUserScenes[scene]):
- cv[index] = val
- dev.send_multi_value(1, cv)
-
-
-
- def setKugel(state):
- if state == 'on':
- wiringpi.digitalWrite(pin_kugel, 0)
- if state == 'off':
- wiringpi.digitalWrite(pin_kugel, 1)
-
- def setSun(state):
- if state == 'off':
- wiringpi.digitalWrite(pin_sun, 0)
- if state == 'on':
- wiringpi.digitalWrite(pin_sun, 1)
-
-
-
- def startMusic(playlist):
- client.clear() # clear playlist
- client.add(playlist) # add file/directory to playlist
- client.shuffle() # shuffle playlist
- client.repeat(1) # set playback mode repeat
- client.setvol(80)# set volume
- client.play() # play
-
- def stopMusic():
- client.stop()
-
-
- def setDiscoMode():
- setSun('off')
- sleep(0.3)
- setKugel('on')
- setDmxScene('fadecolors')
-
- def setWorkingMode():
- setSun('on')
- sleep(0.3)
- setKugel('off')
- setDmxScene('black')
-
- def setOff():
- setSun('off')
- sleep(0.3)
- setKugel('off')
- setDmxScene('black')
-
-
-
- def bootstrap():
- wiringpi.wiringPiSetup()
- wiringpi.pinMode(pin_kugel, 1) # set Relay Disokugel mode to OUTPUT
- wiringpi.pinMode(pin_sun, 1) # set Relay Sun mode to OUTPUT # TODO: Set pin!
- wiringpi.pinMode(pin_pir, 0) # set PIR Sensor mode to INPUT
-
-
-
-
-
- bootstrap()
- dev = pyudmx.uDMXDevice()
- dev.open()
-
- #connect to MPD
- client = mpd.MPDClient()
- client.connect("localhost", 6600)
-
-
-
- pirstate = wiringpi.digitalRead(6)
-
- defaultscene = 1
-
- lastUsed = time.time()
- inUse = True
- inUseBefore = False
- timeout = 2 * 60
-
- dmxScene = 0
-
-
- lirc.init("disco", "./lircrc", blocking=False)
-
-
- # Main event loop ...
- while True:
- sleep(0.2)
- pirstate = wiringpi.digitalRead(pin_pir)
- #print('pirstate: ', pirstate)
- if pirstate == 1:
- lastUsed = time.time()
- inUse = True
- else:
- if(time.time() > lastUsed + timeout):
- inUse = False
-
- remotesignal = lirc.nextcode()
- if remotesignal:
- lastUsed = time.time() # user is active!
- for code in remotesignal:
- print('received code:', code)
- if(code == "mode_disco"):
- setDiscoMode()
- if(code == "mode_work"):
- setWorkingMode()
- if(code == "mode_off"):
- setOff()
- if(code == "mode_dmx_next"):
- print("dmxScene", dmxScene)
- setUserDmxScene(dmxScene)
- if dmxScene < len(dmxUserScenes)-1:
- dmxScene += 1
- else:
- dmxScene = 0
- if(code == "mode_music_play_1"):
- startMusic('1')
- if(code == "mode_music_play_2"):
- startMusic('2')
- if(code == "mode_music_play_3"):
- startMusic('3')
- if(code == "mode_music_play_4"):
- startMusic('4')
- if(code == "mode_music_play_5"):
- startMusic('5')
- if(code == "mode_play_fm4"):
- startMusic('http://185.85.28.144:8000/')
- if(code == "mode_music_stop"):
- stopMusic()
-
-
- if(inUseBefore != inUse):
- print("State change inUse:", inUseBefore, inUse)
- if (inUse):
- setDiscoMode()
- else:
- setOff()
-
-
- inUseBefore = inUse
-
-
- lirc.deinit() # Clean up lirc
-
- dev.close()
|