Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions daemon/usr/bin/plasma
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import signal
import os
import sys
import threading
import re
from datetime import datetime
from optparse import OptionParser

# Application Defaults
PIPE_FILE = "/tmp/plasma"
PATTERNS = "/etc/plasma/"
FPS = 30
LIGHTS = 10
DEBUG = False

# Log & PID files
PID_FILE = "/var/run/plasma.pid"
LOG_FILE = "/var/log/plasma.log"
ERR_FILE = "/var/log/plasma.err"
# Log & PID files - we're moving these to main(), so they can reflect the fifo name
FIFO_FILE = ""
PID_FILE = ""
LOG_FILE = ""
ERR_FILE = ""



stopped = threading.Event()
Expand Down Expand Up @@ -58,8 +60,27 @@ class FIFO():


def main():
global FIFO_FILE
global PID_FILE
global LOG_FILE
global ERR_FILE
global pipename

opts = options()

pipename = re.sub(r'^.*/', '', opts.pipe)
if (pipename == "plasma"):
FIFO_FILE = "/tmp/plasma"
PID_FILE = "/var/run/plasma.pid"
LOG_FILE = "/var/log/plasma.log"
ERR_FILE = "/var/log/plasma.err"
else:
FIFO_FILE = "/tmp/plasma-{}".format(pipename)
PID_FILE = "/var/run/plasma-{}.pid".format(pipename)
LOG_FILE = "/var/log/plasma-{}.log".format(pipename)
ERR_FILE = "/var/log/plasma-{}.err".format(pipename)
log("Plasma input pipe: {}".format(FIFO_FILE))

if opts.daemonize:
fork()

Expand All @@ -71,12 +92,10 @@ def main():
daemon='background' if opts.daemonize else 'foreground',
fps=opts.fps))

log("Plasma input pipe: {}".format(PIPE_FILE))

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

with FIFO(PIPE_FILE) as fifo:
with FIFO(FIFO_FILE) as fifo:
r, g, b = 0, 0, 0
pattern, pattern_w, pattern_h, pattern_meta = load_pattern("default")
alpha = pattern_meta['alpha']
Expand Down Expand Up @@ -126,7 +145,13 @@ def main():


def load_pattern(pattern_name):
pattern_file = os.path.join(PATTERNS, "{}.png".format(pattern_name))
if (pattern_name == "default"):
pattern_file = os.path.join(PATTERNS, "default-{}.png".format(pipename))
if not os.path.isfile(pattern_file):
pattern_file = os.path.join(PATTERNS, "{}.png".format(pattern_name))
else:
pattern_file = os.path.join(PATTERNS, "{}.png".format(pattern_name))

if os.path.isfile(pattern_file):
r = png.Reader(file=open(pattern_file, 'rb'))
pattern_w, pattern_h, pattern, pattern_meta = r.read()
Expand All @@ -148,6 +173,8 @@ def options():
help="set number of lights in your plasma chain")
parser.add_option("-o", "--device", default="GPIO:15:14",
help="set output device, default is GPIO, BCM15 = Data, BCM14 = Clock")
parser.add_option("-p", "--pipe", default="plasma",
help="set pipe used for client process communication, default plasma to create pipe /tmp/plasma. Also sets logfile and pidfile names.")
return parser.parse_args()[0]


Expand Down
28 changes: 24 additions & 4 deletions daemon/usr/bin/plasmactl
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
#!/bin/bash

if [ "$1" == "--help" ] || [ "$1" == "" ]; then
echo -e "\nUsage:\n $0 <r> <g> <b> - Display an RGB colour (all values 0-255)\n $0 <image name> - Display an image-based animation from /etc/plasma\n $0 fps <fps> - Set the update framerate\n $0 --install <filename> - Install an animation file\n $0 --list - List available animations\n"
cat <<__EOF__

Usage:
$0 [-p|--pipe PATH] <r> <g> <b> - Display an RGB colour (all values 0-255)
$0 [-p|--pipe PATH] <image name> - Display an image-based animation
from /etc/plasma
$0 [-p|--pipe PATH] fps <fps> - Set the update framerate
$0 --install <filename> - Install an animation file
$0 --list - List available animations

FIFO specification:
$0 -p|--pipe /path/to/pipe <cmd>
- Communicate with plasma daemon via FIFO /path/to/pipe
__EOF__
exit 0
fi

pipe=/tmp/plasma
if [ "$1" == "-p" -o "$1" == "--pipe" ]; then
pipe="$2"
shift 2
echo "Set FIFO path to $pipe"
fi

if [ "$1" == "--list" ]; then
echo -e "\nAvailable patterns:"
for f in /etc/plasma/*.png; do
Expand All @@ -24,8 +44,8 @@ if [ "$1" == "--install" ]; then
fi
fi

if [ -p "/tmp/plasma" ]; then
echo "$@" > /tmp/plasma
if [ -p "$pipe" ]; then
echo "$@" > "$pipe"
else
echo -e "\n/tmp/plasma not found.\nPlasma daemon not running?\n"
echo -e "\n${pipe} not found.\nPlasma daemon not running?\n"
fi