Browse Source

a lot

master
Andreas Demmelbauer 5 years ago
parent
commit
0b749d82b0
2 changed files with 133 additions and 72 deletions
  1. +122
    -57
      discobert.py
  2. +11
    -15
      mpd-test.py

+ 122
- 57
discobert.py View File

@@ -2,49 +2,54 @@ import subprocess
import sys, inspect, os

import wiringpi
import time
from time import sleep
#from multiprocessing import Process

#import lirc

from pyudmx import pyudmx
import lirc

import mpd

# def send_dmx(dev, red, green, blue, dimmer):
# """
# Send a set of RGB values to the light
# """
# cv = [0 for v in range(0, 512)]
# cv[0] = dimmer
# cv[1] = red
# cv[2] = green
# cv[3] = blue
# sent = dev.send_multi_value(1, cv)
# return sent
#
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)]
scenes = {
"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]
}
errorcode = [240,255,0,0,0,0]

for index, val in enumerate(scenes.get(scene,errorcode)):
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)
@@ -59,23 +64,35 @@ def setSun(state):



def setMusic(action, scene):
if action == "play":
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

if not scene:
scene = defaulscene
def stopMusic():
client.stop()

musicdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/music/" + scene

for (path, dirnames, filenames) in os.walk(musicdir):
#folders.extend(os.path.join(path, name) for name in dirnames)
for name in filenames:
file = os.path.join(path, name)
#os.system("mpg123 " + "'" + file + "'")
#os.system("")
subprocess.run(["mpg123", file])
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')



@@ -84,8 +101,6 @@ def bootstrap():
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
setSun('off')
setKugel('off')



@@ -95,34 +110,84 @@ 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:
# if PIR-State changes
if wiringpi.digitalRead(pin_pir) != pirstate:
pirstate = wiringpi.digitalRead(pin_pir)
print('pirstate: ', pirstate)
if pirstate == 1:
setSun('off')
setKugel('on')
setDmxScene('fadecolors')
sleep(1)
sleep(1)
# setMusic('play', '1')
sleep(20)
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:
setSun('on')
setDmxScene('black')
sleep(1)
setKugel('off')
sleep(1)
setOff()

dev.close()

inUseBefore = inUse


lirc.deinit() # Clean up lirc

dev.close()

+ 11
- 15
mpd-test.py View File

@@ -2,27 +2,23 @@

import mpd
import os
from urllib.parse import urlparse
import getpass

# get current user
print(getpass.getuser())

client = mpd.MPDClient()
client.connect("localhost", 6600)

for entry in client.lsinfo("/"):
client.clear() # clear playlist
client.add('1') # add file/directory to playlist
client.shuffle() # shuffle playlist

client.repeat(1) # set playback mode repeat
client.random(1) # set playback mode random
client.setvol(80)# set volume
client.play() # play
#client.stop() # stop

for entry in client.lsinfo("1"):
print("%s" % entry)
for key, value in client.status().items():
print("%s: %s" % (key, value))

print(client.currentsong())
# print(client.config())

# p = urlparse('file:///home/pi/discobert/music/1/')
p = urlparse('1/')
finalPath = os.path.abspath(os.path.join(p.netloc, p.path))

client.lsinfo('file:///var/local/music/')
# client.add(p)
client.play(0)

Loading…
Cancel
Save