-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern_master.py
More file actions
89 lines (79 loc) · 3.44 KB
/
Copy pathpattern_master.py
File metadata and controls
89 lines (79 loc) · 3.44 KB
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
from __future__ import print_function
import sys
sys.path.insert(0, './src')
sys.path.insert(0, './src/patterns')
from functioning_patterns import *
from inprogress_patterns import *
from classes import Panel
import time
# LED strip configuration:
LED_COUNT = 30 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
#LED_PIN = 10 # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
# panel configuration
NUM_ROWS = 24
NUM_COLUMNS = 24
#these are the configs for the cardboard test panel
#NUM_ROWS = 5
#NUM_COLUMNS = 6
# note: frame rate set in pattern classes
#this is out lookup table that checks the run time input args and calls the appropriate pattern generator
#at the core of it, this function just calls another pattern function, which returns a pixel array object
def get_active_pattern( name):
if name == 'test':
active_pattern = TestPattern( my_panel.m , my_panel.n )
elif name == 'example':
active_pattern = ExamplePattern( my_panel.m , my_panel.n )
elif name == 'worm':
active_pattern = WormPattern( my_panel.m , my_panel.n )
else :
print('NO VALID VISUALIZER GIVEN, USING DEFAULT')
active_pattern = TestPattern( my_panel.m , my_panel.n )
return active_pattern
if __name__ == '__main__':
print('running panel_master')
script = sys.argv[1]
print('running script: ', script)
run_type = sys.argv[2]
if run_type != "pi":
run_type = "vis"
else:
#need to perform the import in here since we only do it if using the pi hardware
from neopixel import *
LED_STRIP = ws.WS2811_STRIP_GRB # Strip type and colour ordering
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,
LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL, LED_STRIP)
strip.begin()
print('run_typ is: ', run_type)
m = NUM_ROWS
n = NUM_COLUMNS
pix_num = m * n
my_panel_shapes = [ [1 for c in range(n)] for r in range(m) ]
print('Panel . M : ', len( my_panel_shapes ), " N: ",len( my_panel_shapes[0] ))
my_panel = Panel(m,n,pix_num,my_panel_shapes, run_type)
# initialize pattern
active_pattern = get_active_pattern( script )
if run_type == "vis":
from panel_visualizer import PanelVisualizer
visualizer = PanelVisualizer(m, n)
#run a loop forever that just gets new pixel arrays and visualizes them
while True:
# update and get pixel array
pixel_arr = active_pattern.update_and_get_pixel_arr()
if run_type == "vis":
#send our array over to the visualizer for the GUI
visualizer.display_visualizer_panel(pixel_arr)
#this is the refresh speed of our panel.
else:
#update the panel object's state
my_panel.update_panel(pixel_arr)
#update the actual LEDs
my_panel.update_led_panel(strip)
# refresh speed of our panel. We should be able to make this
# pretty fast for the raspi
time.sleep(active_pattern.frame_sleep_time)