diff --git a/README.md b/README.md index eb972f9..a2b3703 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The Setup is pretty custom. It includes: Use Debian, install apt dependencies ``` -sudo apt install git samba mpd libttspico-utils python3-pip python3-lirc python3-rpi.gpio +sudo apt install git samba mpd libttspico-utils python3-pip python3-lirc python3-rpi.gpio nginx ``` maybe also: `wiringpi espeak mpc` diff --git a/discobert.py b/discobert.py index 5a2a326..02d1797 100644 --- a/discobert.py +++ b/discobert.py @@ -14,6 +14,22 @@ from pyudmx import pyudmx import talkey +# HTTP Server +from twisted.web import server, resource +from twisted.internet import reactor + +class Simple(resource.Resource): + isLeaf = True + def render_GET(self, request): + statustext = "" + if inUse: + statustext = "Disco in use!" + else: + statustext = "Ready to Disco!" + html = '
%s
' % statustext + return html.encode('utf-8') + + # GPIO pin_kugel = 2 pin_sun = 4 @@ -323,6 +339,10 @@ tts = talkey.Talkey( ) +site = server.Site(Simple()) +reactor.listenTCP(8080, site) +reactor.startRunning(False) + lirc.init("disco", "~/discobert/lircrc", blocking=False) @@ -341,8 +361,6 @@ setSun('off') print(timestamp(), "Ready!") - - # Main event loop ... while True: sleep(0.25) @@ -420,6 +438,9 @@ while True: startTimeoutCountdown() inUseBefore = inUse + # Webserver + reactor.iterate() + lirc.deinit() # Clean up lirc diff --git a/dmxtest.py b/dmxtest.py deleted file mode 100644 index 5b2c027..0000000 --- a/dmxtest.py +++ /dev/null @@ -1,104 +0,0 @@ -# -# 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") diff --git a/mpd-test.py b/mpd-test.py deleted file mode 100755 index 8dc067b..0000000 --- a/mpd-test.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 - -import mpd -import os - -client = mpd.MPDClient() -client.connect("localhost", 6600) - -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()) diff --git a/playmusic.py b/playmusic.py deleted file mode 100644 index aed6a69..0000000 --- a/playmusic.py +++ /dev/null @@ -1,13 +0,0 @@ -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]) diff --git a/webtest.py b/webtest.py new file mode 100644 index 0000000..b5dff85 --- /dev/null +++ b/webtest.py @@ -0,0 +1,12 @@ +from twisted.web import server, resource +from twisted.internet import reactor + +class Simple(resource.Resource): + isLeaf = True + def render_GET(self, request): + request.setHeader("Content-Type", "text/html; charset=utf-8") + return "Hello, world!".encode('utf-8') + +site = server.Site(Simple()) +reactor.listenTCP(8081, site) +reactor.run()