class Renderer(object):
    def __init__(self):
        self.client = Client(settings.FC_SERVER + ':' + str(settings.FC_PORT))
        self.brightness = 0.5
        self.pixels = [
            [1, 1, 1],
            [1, 1, 1],
            [1, 1, 1],
            [1, 1, 1]
        ]
        self.render_pixels = self.calculate_pixels()
        self.render_thread = Thread(target=self.render)
        self.render_thread.daemon = True
        self.render_thread.start()

    def calculate_pixels(self):
        ret_val = []
        for pixel in self.pixels:
            px = [(
                int(pixel[0] * self.brightness * settings.RGB_MAX),
                int(pixel[1] * self.brightness * settings.RGB_MAX),
                int(pixel[2] * self.brightness * settings.RGB_MAX)
             )] * settings.PIXEL_COUNT

            ret_val.extend(px)
        return ret_val

    def update(self):
        self.render_pixels = self.calculate_pixels()

    def render(self):
        while True:
            self.client.put_pixels(self.render_pixels)
            sleep(1.0 / settings.FRAMES)
Beispiel #2
0
    def __init__(self):
        print 'Initializing Driver'
        session = Session()
        self.modules = session.query(LightModule).all()
        self.strips = {s.name: s for s in session.query(Strip).all()}
        session.close()
        print 'starting engine'

        self.engine = LightEngine(self.modules)
        print 'engine running'
        self.sp = Spotify()
        print 'spotify loaded'
        if SIM:
            self.sim = Client('127.0.0.1:7890')
Beispiel #3
0
class Flash:
    def __init__(self, hostname):
        self.hostname = hostname
        self.client = Client('{}.local:{}'.format(self.hostname, OPC_PORT))

    def _flash_thread(self, x):
        i = 0.5 * (1.0 + cos(x - pi)) * 255
        pixels = [(i, 0, 0)] * 124
        self.client.put_pixels(pixels)
        x += pi / 60.0
        if x <= 4.0 * pi:
            threading.Timer(1 / 60.0, self._flash_thread, args=(x, )).start()
        else:
            self.client.put_pixels([(0, 0, 0)] * 124)

    def start(self):
        print 'flashing module {}'.format(self.hostname)
        threading.Thread(target=self._flash_thread, args=(0.0, )).start()
Beispiel #4
0
 def __init__(self, modules, refresh_rate=REFRESH_RATE, debug=False):
     self.hosts = Hosts()
     self.refresh_rate = refresh_rate
     self.debug = debug
     self.modules = [(m, Client('{}.local:{}'.format(m.hostname, OPC_PORT)))
                     for m in modules]
     self.active = True
     self.time_taken = 0.0
     self.i = 0
     self.update()
Beispiel #5
0
def main():
    client = Client('localhost:7890')

    while True:
        print('Updating... ', end="")
        positions = get_vehicle_positions()
        print("done")
        print("inbound... ")
        update(client, positions, "Inbound", 10)
        print("outbound... ")
        update(client, positions, "Outbound", 10)
Beispiel #6
0
 def __init__(self):
     self._client = Client('localhost:7890')
     self._scenes = [
         SpritesScene(),
         MandelScene(),
         FunctionScene(),
         FunctionScene2(),
         SquaresScene(),
     ]
     self._timer = Timer(self._switch)
     self._timer.set_period(10.0)
     self._switch()
 def __init__(self):
     self.client = Client(settings.FC_SERVER + ':' + str(settings.FC_PORT))
     self.brightness = 0.5
     self.pixels = [
         [1, 1, 1],
         [1, 1, 1],
         [1, 1, 1],
         [1, 1, 1]
     ]
     self.render_pixels = self.calculate_pixels()
     self.render_thread = Thread(target=self.render)
     self.render_thread.daemon = True
     self.render_thread.start()
Beispiel #8
0
#!/usr/bin/env python

# Open Pixel Control client: All lights to solid white

import time
from opc import Client

numLEDs = 47
client = Client('192.168.1.73:7890')

black = [(0, 0, 0, 0)] * numLEDs
white = [(255, 0, 0, 0)] * numLEDs

while True:
    client.put_pixels(white)
    time.sleep(3.05)
    client.put_pixels(black)
    time.sleep(3.05)
Beispiel #9
0
'''
example patter
'''

from bits import Bit
from color import hsv_to_rgb, HSV, rgb_to_hsv, RGB, Color
from grid import Grid
from projector import Projector
from random import randint, sample, choice
from itertools import count
from time import sleep
from opc import Client
client = Client('localhost:7890')
__all__ = [
    'RGB_CODES', 'HUES_primaries', 'create_random', 'spreaders', 'rainbow_test'
]

numLEDs = 40
RGB_CODES = dict(black=(0, 0, 0),
                 red=(255, 0, 0),
                 orange=(255, 128, 0),
                 yellow=(255, 255, 0),
                 pink=(255, 0, 128),
                 purple=(255, 0, 255),
                 lavendar=(128, 0, 255),
                 green=(0, 255, 0),
                 lime=(128, 255, 0),
                 emerald=(0, 255, 128),
                 turq=(128, 255, 128),
                 blue=(0, 0, 255),
                 cyan=(0, 255, 255),
Beispiel #10
0
class Driver:
    def __init__(self):
        print 'Initializing Driver'
        session = Session()
        self.modules = session.query(LightModule).all()
        self.strips = {s.name: s for s in session.query(Strip).all()}
        session.close()
        print 'starting engine'

        self.engine = LightEngine(self.modules)
        print 'engine running'
        self.sp = Spotify()
        print 'spotify loaded'
        if SIM:
            self.sim = Client('127.0.0.1:7890')

    def act_on_kf(self, kf, strip):
        for ctrl in kf.controls:
            ctrl = ctrl.create()
            if ctrl.type == 'intensity':
                strip.add_intensity_control(ctrl, clear=kf.clear)
            if ctrl.type == 'color':
                strip.add_color_control(ctrl, clear=kf.clear)
                print strip.color_controls
            if ctrl.type == 'combo':
                strip.add_combo_control(ctrl, clear=kf.clear)

    def run(self, track_id):
        with open(join(CDP, track_id)) as f:
            data = json.load(f)
            print data
        show = Show()
        show.load(data)
        self.show = show
        #self.visited_kfs = set()
        self.idxs = {str(o): 0 for o in show.__dict__}
        self.start_pos = self.sp.get_player_pos()
        self.start_time = time.time() - self.start_pos
        self.update()

    def update_strip(self, strip, time):
        curr_idx = self.idxs[strip.name]
        kfs = getattr(self.show, strip.name)
        if len(kfs) == 0:
            return
        for kf in kfs[curr_idx:]:
            if kf.time <= time:
                self.act_on_kf(kf, strip)
                #self.visited_kfs.add(kf)
                curr_idx += 1
        self.idxs[strip.name] = curr_idx

    def update(self):
        curr_time = time.time() - self.start_time
        if SIM:
            pixels = []
        for o in self.show.__dict__:
            strip = self.strips[o]
            self.update_strip(strip, curr_time)
            if SIM:
                strip.compile(curr_time)
                pixels += strip.compiled_rgb
        if SIM:
            self.sim.put_pixels(pixels)
        t = threading.Timer(1.0 / REFRESH_RATE, self.update)
        t.setDaemon(True)
        t.start()
Beispiel #11
0
 def __init__(self, hostname):
     self.hostname = hostname
     self.client = Client('{}.local:{}'.format(self.hostname, OPC_PORT))
import json

import time

from opc import Client

with open("stop_configuration.json") as config:
    stops = json.load(config)

current_led = 0
total_leds = 64 * 8
client = Client('localhost:7890')

while True:
    for stop_id, stop_config in stops.items():
        print("%s: %s (%s)" %
              (stop_config['led'], stop_id, stop_config['name']))
        pixels = [(0, 0, 0)] * total_leds
        pixels[stop_config['led']] = (255, 255, 255)
        client.put_pixels(pixels)
        client.put_pixels(pixels)
        time.sleep(0.1)
Beispiel #13
0
def main():
    client = Client('localhost:7890')
    while True:
        loop(client)