summaryrefslogtreecommitdiffstats
path: root/brige.py
blob: 314f9db0b8ce7872f93e3fa074f0267b0857d644 (plain) (blame)
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
#!/usr/bin/python2
from __future__ import division, print_function
import color
import constants
import curses
import fish_render
import time
import random
try:
    import lumiversepython
except ImportError:
    have_lumiversepython = False
    from DummyRig import DummyRig
else:
    have_lumiversepython = True

def get_all_lights(rig):
    """Return a list of all panels."""
    return [
        [
            fish_render.Light(
                x, int(y == 'top'),
                rig.select('$side={y}[$sequence={x}]'.format(y=y, x=x))
            ) for y in ('top', 'bot')
        ] for x in xrange(1, 200)
    ]


def colorSection(lights, color, *ranges):
    for start, end in ranges:
        map(lambda l: map(lambda x: x.light.setRGBRaw(*color), l), lights[start:end])

def onSection(lights, *ranges):
    colorSection(lights, (1, 1, 1), *ranges)

def offSection(lights, *ranges):
    colorSection(lights, (0, 0, 0), *ranges)

def mapKey(key):
    if key == ord('a'):
        return (0, 20)
    if key == ord('o'):
        return (20, 40)
    if key == ord('e'):
        return (40, 60)
    if key == ord('u'):
        return (60, 80)
    if key == ord('i'):
        return (80, 100)
    if key == ord('d'):
        return (100, 120)
    if key == ord('h'):
        return (120, 140)
    if key == ord('t'):
        return (140, 160)
    if key == ord('n'):
        return (160, 180)
    if key == ord('s'):
        return (180, 200)
    return (0, 0)

def demo(lights, rig, screen):
    """Do some light things."""
    sections = []
    while True:
        k = screen.getch()
        offSection(lights, *sections)
        r = mapKey(k)
        try:
            i = sections.index(r)
        except ValueError:
            sections.append(r)
        else:
            del sections[i]
        onSection(lights, *sections)
        rig.updateOnce()

def main():
    """Run show."""
    if have_lumiversepython:
        rig = lumiversepython.Rig('/home/teacher/Lumiverse/PBridge.rig.json')
    else:
        rig = DummyRig(200, 2)
    rig.init()
    stdscr = curses.initscr()
    stdscr.keypad(1)
    curses.noecho()
    
    lights = get_all_lights(rig)
    try:
        demo(lights, rig, stdscr)
    except BaseException:
        curses.nocbreak()
        stdscr.keypad(0)
        curses.echo()
        curses.endwin()
        raise

if __name__ == '__main__':
    main()