Browse Source

initial commit

master
Andreas Demmelbauer 5 years ago
commit
be2a46328f
5 changed files with 283 additions and 0 deletions
  1. +128
    -0
      discobert.py
  2. +104
    -0
      dmxtest.py
  3. +28
    -0
      mpd-test.py
  4. +10
    -0
      notes.md
  5. +13
    -0
      playmusic.py

+ 128
- 0
discobert.py View File

@@ -0,0 +1,128 @@
import subprocess
import sys, inspect, os

import wiringpi
from time import sleep
#from multiprocessing import Process

#import lirc

from pyudmx import pyudmx


# 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
#

# GPIO
pin_kugel = 2
pin_sun = 4
pin_pir = 0

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

if not scene:
scene = defaulscene

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 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
setSun('off')
setKugel('off')





bootstrap()
dev = pyudmx.uDMXDevice()
dev.open()



pirstate = wiringpi.digitalRead(6)

defaultscene = 1




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)
else:
setSun('on')
setDmxScene('black')
sleep(1)
setKugel('off')
sleep(1)

dev.close()


+ 104
- 0
dmxtest.py View File

@@ -0,0 +1,104 @@
#
# example.py
# Copyright 2018 by Dave Hocker
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# See the LICENSE file for more details.
#
# Example of how to use pyudmx with a Thinpar 64 light
# http://venuelightingeffects.com/wp-content/uploads/manuals/Venue_Thinpar_64_Manual_HR.pdf
# 7 channel mode
# Channels 1-3 are RGB
# Channel 7 is the dimmer
#
# Requirements
# A virtual environment meeting the requirements defined in requirements.txt works best.
# Specifically the pyusb module must be installed.
#

from pyudmx import pyudmx
from time import sleep


def send_rgb(dev, dimmer, red, green, blue, effect):
"""
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
cv[4] = effect
print(cv)
print(type(cv))
sent = dev.send_multi_value(1, cv)
return sent


def main():
"""
How to control a DMX light through an Anyma USB controller
"""

# Channel value list for channels 1-512
cv = [0 for v in range(0, 512)]

# Create an instance of the DMX controller and open it
print("Opening DMX controller...")
dev = pyudmx.uDMXDevice()
# This will automagically find a single Anyma-type USB DMX controller
dev.open()
# For informational purpose, display what we know about the DMX controller
print(dev.Device)

# Send messages to the light changing it to red, then green, then blue
# This is the "hard way" to do it, but illustrates how it's done

print("Setting to red...")
cv[0] = 255 # dimmer to half value
cv[1] = 255 # red
sent = dev.send_multi_value(1, cv)
print("Set to red")
sleep(3.0)

print("Setting to green...")
cv[0] = 255 # dimmer to half value
cv[1] = 0 # red
cv[2] = 255 # green
sent = dev.send_multi_value(1, cv)
print("Set to green")
sleep(3.0)

print("Setting to blue...")
cv[0] = 255 # dimmer to half value
cv[1] = 0 # red
cv[2] = 0 # green
cv[3] = 255 # blue
sent = dev.send_multi_value(1, cv)
print("Set to blue")
sleep(3.0)

# Here's an easier way to do it

print("And, again the easier way")
send_rgb(dev, 255, 255, 0, 0, 0)
sleep(3.0)
send_rgb(dev, 255, 0, 255, 0, 0)
sleep(3.0)
send_rgb(dev, 255, 0, 0, 255, 0)
sleep(3.0)

print("Reset all channels and close..")
# Turns the light off
cv = [0 for v in range(0, 512)]
dev.send_multi_value(1, cv)
dev.close()


if __name__ == "__main__":
main()
print("Done")

+ 28
- 0
mpd-test.py View File

@@ -0,0 +1,28 @@
#!/usr/bin/env python3

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("/"):
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)

+ 10
- 0
notes.md View File

@@ -0,0 +1,10 @@
https://github.com/dhocker/udmx-pyusb

add user permissions for udmx device
sudo cp 98-uDMX-usb.rules /etc/udev/rules.d


capture USB

tshark -D
tshark -i 6

+ 13
- 0
playmusic.py View File

@@ -0,0 +1,13 @@
import os, inspect
import subprocess

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


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])

Loading…
Cancel
Save