Skip to content

Commit

Permalink
Merge 84cedf1 into b5acdd8
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Mar 27, 2020
2 parents b5acdd8 + 84cedf1 commit bfa9cb0
Show file tree
Hide file tree
Showing 31 changed files with 722 additions and 355 deletions.
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ git:

matrix:
include:
- python: "2.7"
env: TOXENV=py27
- python: "3.5"
env: TOXENV=py35
- python: "2.7"
env: TOXENV=py27
- python: "3.7"
env: TOXENV=py37

install:
- pip install --ignore-installed --upgrade setuptools pip tox coveralls
Expand All @@ -21,4 +17,4 @@ script:
- cd library
- tox -vv

after_success: if [ "$TOXENV" == "py35" ]; then coveralls; fi
after_success: if [ "$TOXENV" == "py37" ]; then coveralls; fi
25 changes: 0 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,10 @@ If you choose to download examples you'll find them in `/home/pi/Pimoroni/plasma

### Manual install:

#### Library install for Python 3:

on Raspbian:

```bash
sudo apt-get install python3-plasmalights
```

other environments:

```bash
sudo pip3 install plasmalights
```

#### Library install for Python 2:

on Raspbian:

```bash
sudo apt-get install python-plasmalights
```

other environments:

```bash
sudo pip2 install plasmalights
```

### Using Plasma Daemon

To install the Plasma daemon you should clone this repository, navigate to the "daemon" directory and run the installer:
Expand Down Expand Up @@ -102,7 +78,6 @@ If you want to contribute, or like living on the edge of your seat by having the
```bash
sudo python3 setup.py install
```
(or `sudo python setup.py install` whichever your primary Python environment may be)

## Documentation & Support

Expand Down
3 changes: 2 additions & 1 deletion daemon/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ if [ -d "/etc/plasma" ]; then
fi

printf "Installing requirements\n"
sudo pip install pypng plasmalights
sudo apt install python3 python3-pip
sudo pip3 install pypng plasmalights

printf "Installing plasma\n"
mkdir /etc/plasma
Expand Down
24 changes: 16 additions & 8 deletions daemon/usr/bin/plasma
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import png
import time
Expand Down Expand Up @@ -38,15 +38,23 @@ class FIFO():

def readline(self, timeout=1):
t_start = time.time()
buf = os.read(self.fifo, 1)
try:
buf = os.read(self.fifo, 1)
except BlockingIOError:
return None

if len(buf) == 0:
return None

while time.time() - t_start < timeout:
c = os.read(self.fifo, 1)
if c == "\n":
return buf
if len(c) == 1:
buf += c
try:
c = os.read(self.fifo, 1)
if c == b"\n":
return buf
if len(c) == 1:
buf += c
except BlockingIOError as err:
continue
return None

def __enter__(self):
Expand Down Expand Up @@ -86,7 +94,7 @@ def main():
delta = time.time() * 60
command = fifo.readline()
if command is not None:
command = command.strip()
command = command.decode('utf-8').strip()

if command == "stop":
stopped.set()
Expand Down
93 changes: 62 additions & 31 deletions daemon/usr/bin/plasmactl
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
#!/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"
exit 0
fi

if [ "$1" == "--list" ]; then
echo -e "\nAvailable patterns:"
for f in /etc/plasma/*.png; do
name=$(basename -- "$f")
name="${name%.*}"
echo -e " $name"
done
echo -e ""
exit 0
fi

if [ "$1" == "--install" ]; then
if [ -f "$2" ]; then
echo -e "\nInstalling $2 into /etc/plasma\n"
cp $2 /etc/plasma/
exit 0
fi
fi

if [ -p "/tmp/plasma" ]; then
echo "$@" > /tmp/plasma
else
echo -e "\n/tmp/plasma not found.\nPlasma daemon not running?\n"
fi
#!/usr/bin/env python3

import argparse
import pathlib
import sys

ROOT = pathlib.Path('/etc/plasma')
FIFO = pathlib.Path('/tmp/plasma')


def Color(value):
try:
return int(value)
except ValueError:
return int(value, 16)


def get_patterns():
return ROOT.glob('*.png')


def valid_patterns():
for pattern in get_patterns():
yield pattern.stem


def open_fifo(filename):
if filename.exists():
return open(filename, 'wb')
else:
raise RuntimeError(f"FIFO {filename} does not exit! Is plasma running?")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--install', type=pathlib.Path, help='Install an animation file')
parser.add_argument('--list', action='store_true', help='List available animations')
parser.add_argument('--colour', nargs=3, type=Color, help='Display an RGB colour (all values 0-255)')
parser.add_argument('--fps', type=int, help='Set the update framerate')
parser.add_argument('--pattern', type=str, help='Display an image-based aniamtion from /etc/plasma', choices=list(valid_patterns()))

args = parser.parse_args()

if args.list:
print("Available patterns:")
for pattern in get_patterns():
print(f"{pattern.stem:30} {pattern}")
sys.exit(0)

if args.pattern:
print(f"Setting pattern to {args.pattern}")
with open_fifo(FIFO) as fifo:
fifo.write(f"{args.pattern}\n".encode("utf-8"))
fifo.flush()

if args.colour:
r, g, b = args.colour
print(f"Setting colour to {r}, {g}, {b}")
with open_fifo(FIFO) as fifo:
fifo.write(f"{r} {g} {b}\n".encode("utf-8"))
fifo.flush()

18 changes: 18 additions & 0 deletions examples/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
strip:
pixels: 100
devices:
WS281X:
pixels: 30
offset: 0
gpio_pin: 1
strip_type: WS2812
APA102:
pixels: 30
offset: 30
gpio_data: 10
gpio_clock: 11
SERIAL:
pixels: 40
offset: 60
gpio_data: 10
gpio_clock: 11
2 changes: 1 addition & 1 deletion examples/larson_hue.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import math
import time
Expand Down
2 changes: 1 addition & 1 deletion examples/rainbow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import colorsys
import time
Expand Down
2 changes: 1 addition & 1 deletion library/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include CHANGELOG.txt
include LICENSE.txt
include README.rst
include README.md
include setup.py
recursive-include plasma *.py
100 changes: 100 additions & 0 deletions library/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Plasma: LED Sequencing

Plasma is an LED/Light sequencing suite written to harmonise a variety of LED strand/board types and interfaces into a standard API for write-once-run-anyway lighting code.

Plasma also includes plasmad, a system daemon for sequencing light strips using PNG images to provide animation frames.

[![Build Status](https://travis-ci.com/pimoroni/plasma.svg?branch=master)](https://travis-ci.com/pimoroni/plasma)
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/plasma/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/plasma?branch=master)
[![PyPi Package](https://img.shields.io/pypi/v/plasmalights.svg)](https://pypi.python.org/pypi/plasmalights)
[![Python Versions](https://img.shields.io/pypi/pyversions/plasmalights.svg)](https://pypi.python.org/pypi/plasmalights)

## Compatible Products

Plasma was originally written to provide an easy way to sequence lights and swap out patterns for the Pimoroni Plasma kit.

- https://shop.pimoroni.com/products/picade-plasma-kit-illuminated-arcade-buttons
- https://shop.pimoroni.com/products/player-x-usb-games-controller-pcb
- https://shop.pimoroni.com/products/blinkt
- https://shop.pimoroni.com/products/unicorn-hat
- https://shop.pimoroni.com/products/unicorn-phat

## Installing

### Full install (recommended):

We've created an easy installation script that will install all pre-requisites and get your Plasma Arcade Button Lights
up and running with minimal efforts. To run it, fire up Terminal which you'll find in Menu -> Accessories -> Terminal
on your Raspberry Pi desktop, as illustrated below:

![Finding the terminal](http://get.pimoroni.com/resources/github-repo-terminal.png)

In the new terminal window type the command exactly as it appears below (check for typos) and follow the on-screen instructions:

```bash
curl https://get.pimoroni.com/plasma | bash
```

If you choose to download examples you'll find them in `/home/pi/Pimoroni/plasma/`.

### Manual install:

```bash
sudo pip3 install plasmalights
```

### Using Plasma Daemon

To install the Plasma daemon you should clone this repository, navigate to the "daemon" directory and run the installer:

```
git clone https://github.com/pimoroni/plasma
cd plasma/daemon
sudo ./install
```

---

Note: If you're using Picade Player X you should edit daemon/etc/systemd/system/plasma.service and change the output device option from `-o GPIO:15:14` to `-o SERIAL:/dev/ttyACM0`. If you're using Unicorn HAT or pHAT you should use `-o WS281X:WS2812:18:0`.

If you're using GPIO on a Picade HAT you can adjust the pins accordingly using `-o GPIO:<data>:<clock>` where data and clock are valid BCM pins. If you're using the old Plasma/Hack header you may need to swap from `-o GPIO:15:14` to `-o GPIO:14:15` depending on how your connections are wired.

---

The Plasma daemon installer installs two programs onto your Raspberry Pi. `plasma` itself and a tool called `plasmactl` you can use to install and switch lighting effects. Plasma runs as a service on your system.

`plasmactl` commands:

* `plasmactl 255 0 0` - Set Plasma lights to R, G, B colour. Red in this case.
* `plasmactl <pattern>` - Set Plasma lights to pattern image
* `plasmactl fps <fps>` - Change plasma effect framerate (default is 30, lower FPS = less CPU)
* `plasmactl --list` - List all available patterns
* `sudo plasmactl --install <pattern>` - Install a new pattern, where `<pattern>` is the filename of a 24bit PNG image file

### Development:

If you want to contribute, or like living on the edge of your seat by having the latest code, you should clone this repository, `cd` to the library directory, and run:

```bash
sudo python3 setup.py install
```

## Documentation & Support

* Guides and tutorials - https://learn.pimoroni.com/plasma
* Function reference - http://docs.pimoroni.com/plasma/
* Get help - http://forums.pimoroni.com/c/support

## Changelog

1.0.0
-----

* API refactor, use plasma.legacy for old API
* USB support for Picade Player X

0.0.1
-----

* Initial Release

Loading

0 comments on commit bfa9cb0

Please sign in to comment.