-
Notifications
You must be signed in to change notification settings - Fork 0
/
testConcurrentAnimations.py
122 lines (106 loc) · 4.26 KB
/
testConcurrentAnimations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
"""
Use version of DriverSlave that has pixmap and pixheights
Runs a number of wave animations (threaded) so they are concurrent
"""
# import base classes and driver
from bibliopixel import LEDStrip, LEDMatrix
from bibliopixel.drivers.LPD8806 import DriverLPD8806, ChannelOrder
from bibliopixel.drivers.visualizer import DriverVisualizer, ChannelOrder
from bibliopixel.drivers.slave_driver import DriverSlave
# import colors
import bibliopixel.colors
from bibliopixel.animation import BaseStripAnim, BaseMatrixAnim, MasterAnimation
from logging import DEBUG, INFO, WARNING, CRITICAL, ERROR
from bibliopixel import log
log.setLogLevel(WARNING)
import re
import time
from operator import or_, ior, ixor
# import matplotlib.pyplot as plt
import BiblioPixelAnimations.matrix.bloom as BA
import BiblioPixelAnimations.strip.Wave as WA
import sys
from bibliopixel.wormanimclass import pathgen
# set up led with it's driver for the MasterAnimation
try: # to use visualizer but if fails
drivermaster = DriverVisualizer(160, pixelSize=62, stayTop=False, maxWindowWidth=1024)
ledmaster = LEDMatrix(drivermaster, width=16, height=10, threadedUpdate=False)
except:
# assume on my pi and connect to strip, however a process of visualizerUI.py will have
# been started and will fail
drivermaster = DriverLPD8806(160)
ledmaster = LEDMatrix(drivermaster, width=16, height=10, threadedUpdate=False)
# Set up animations that will run concurrently
# Wave arguments
waveblue = ((0,0,255), 1)
wavered = ((0, 255, 0), 1)
wavegreen = ((255, 0, 0), 1)
wavecyan = ((255, 0, 255), 1)
wavewhite = ((255, 255, 255), 1)
# Wave slave driver arguments
wavebluepixmap = pathgen(1, 15, 0, 9)
waveredpixmap = pathgen(1, 14, 1, 8)
wavegreenpixmap = pathgen(2, 13, 2, 7)
wavecyanpixmap = pathgen(3, 12, 3, 6)
wavewhitepixmap = pathgen(4, 11, 4, 5)
# List of triple (animation arguments, slavedriver argument, fps)
wavedatalist = [(waveblue, wavebluepixmap, 5),
(wavered, waveredpixmap, 6),
(wavegreen, wavegreenpixmap, 7),
(wavecyan, wavecyanpixmap, 8),
(wavewhite, wavewhitepixmap, 9)]
# dummy LED strips must each have their own slavedrivers
ledslaves = [LEDStrip(DriverSlave(len(sarg), pixmap=sarg, pixheights=-1), threadedUpdate=False) \
for aarg, sarg, fps in wavedatalist]
# Make the animation list
# Wave animations as list pairs (animation instances, fps) added
animationlist = [(WA.Wave(ledslaves[i], *wd[0]), wd[2]) for i, wd in enumerate(wavedatalist)]
# needed to run on pixelweb
def genParams():
return {"start":0, "end":-1, "animcopies": animationlist}
if __name__ == '__main__':
masteranimation = MasterAnimation(ledmaster, animationlist, runtime=2)
# Master launches all in animationlist at preRun
# Master steps when it gets a go ahdead signal from one of the
# concurrent annimations
masteranimation.run(fps=None, threaded = False) # if give fps for master will skip faster frames
masteranimation.stopThread()
#import threading
#print threading.enumerate()
# plot timing data collected from all the animations
# horizontal axis is time in ms
# vertical are the various animation and dot is when update sent to leds by master
try:
import matplotlib.pyplot as plt
plt.clf()
col = 'brgcwk'
[plt.plot(masteranimation.timedata[i], [i] * len(masteranimation.timedata[i]), col[i%6]+'o') for i in range(len(animationlist))]
ax = plt.axis()
delx = .01 * (ax[1] - ax[0])
plt.axis([ax[0]-delx, ax[1]+delx, ax[2]-1, ax[3]+1])
plt.title("Master Animation Step Count {}".format(masteranimation._step))
except ImportError:
print 'Wasnt able to plot as matplotlib not available'
pass
MANIFEST = [
{
"class": MasterAnimation,
"type": "preset",
"preset_type": "animation",
"controller": "matrix",
"desc": None,
"display": "Waves in Rings",
"id": "MMasterAnimation4",
"params": [
{
"default": 10,
"help": "",
"id": "runtime",
"label": "Runtime",
"type": "int"
}
],
"preconfig": genParams,
}
]