Пример #1
0
def sendout(args, targets, protocol, matrixsim):
    # sendout function that sends out data to the networked devices and
    # also to the matrix screen simulator if enabled.
    # or only to the matrix simulator if no pattern is selected.
    try:
        for t in targets:
            pattern = targets[t]
            # generate the next set of images to send.
            pattern.generate()
            if matrixsim:
                matrixsim.handleinput()
                matrixsim.process(pattern)
            if args.sendOnChange:
                changed = (Surface(pattern) != Surface(sendout.previous))
                sendout.previous = Surface(pattern)
            else:
                changed = True
            if changed and protocol:
                protocol.send(pattern, t)
    except KeyboardInterrupt:
        cleanup(9)
    except Exception as e:
        traceback.print_exc()
        print("\r\ndest: %s" % (t))
        print(pattern.__repr__)
        cleanup(8)
Пример #2
0
    def __init__(self, **kwargs):
        Surface.__init__(self, **kwargs)
        args = get_args()

        self.location = kwargs.get('location', None)
        center = kwargs.get('center', True)
        if self.location == None:
            return

        # load in a image with ffmpeg and apply fps
        ffmpeg = "ffmpeg"
        fmtstr = "-vf \"scale=%d:%d\""
        fmt = (self.width, self.height)
        filteropts = fmtstr % (fmt)
        command = [ffmpeg,
                   '-loglevel', 'panic',
                   '-i', self.location,
                   filteropts,
                   '-f', 'image2pipe',
                   '-pix_fmt', 'rgb24',
                   '-vcodec', 'rawvideo',
                   '-']

        command = ' '.join(command)
        if args.debug:
            print("\ncommand: %s" % (command))
        self.pipe = sp.Popen(shlex.split(command), stdout=sp.PIPE)
Пример #3
0
 def __init__(self, **kwargs):
     """ create a surface and a buffer to keep changes in."""
     Surface.__init__(self, **kwargs)
     self.buffer = Surface(surface=self)
     self.bottom_points = range(0, self.width)
     # self.bottom_points = [random.randint(0, self.width) for x in range(0, self.width)]
     self.randomize_bottom()
     self.timer = Timer(0.4)
Пример #4
0
    def __init__(self, **kwargs):
        Surface.__init__(self, **kwargs)
        screen_resolution = kwargs.get('screen_resolution', None)
        fullscreen = kwargs.get('fullscreen', False)
        fps = kwargs.get('fps', None)
        center = kwargs.get('center', True)

        args = get_args()
        if screen_resolution is None:
            pm = pymouse.PyMouse()
            screen_resolution = pm.screen_size()
            if args.debug:
                print("selected resolution: " + str(screen_resolution))
        ffmpeg = "ffmpeg"
        display = os.getenv("DISPLAY")
        if fps == None:
            fps = get_args().fps
        if fullscreen:
            fmt = screen_resolution
            fmtstr = "%dx%d"
            screensize = fmtstr % fmt
            scale = "scale=%d:%d" % (self.width, self.height)
            command = [ffmpeg,
                       '-loglevel', 'panic',
                       '-video_size', screensize,
                       '-r', '30',
                       '-f', 'x11grab',
                       '-i', display,
                       '-f', 'image2pipe',
                       '-pix_fmt', 'rgb24',
                       '-vcodec', 'rawvideo',
                       '-preset', 'ultrafast',
                       '-crf', '0',
                       '-vf', scale,
                       '-an', '-']
        else:
            fmt = (self.width, self.height)
            fmtstr = "%dx%d"
            screensize = fmtstr % fmt
            command = [ffmpeg,
                       '-loglevel', 'panic',
                       '-video_size', screensize,
                       '-r', '30',
                       '-follow_mouse', 'centered',
                       '-draw_mouse', '0',
                       '-f', 'x11grab',
                       '-i', display,
                       '-f', 'image2pipe',
                       '-pix_fmt', 'rgb24',
                       '-vcodec', 'rawvideo',
                       '-preset', 'ultrafast',
                       '-crf', '0',
                       '-an', '-']

        command = ' '.join(command)
        if args.debug:
            print("\ncommand: %s" % (command))
        self.pipe = sp.Popen(shlex.split(command), stdout=sp.PIPE)
Пример #5
0
def convert_snake_layout(data):
    ndata = Surface(data)
    points = ndata.get_points()
    for point in points:
        x, y = point
        if not ((y + 1) % 2):
            for x in range(0, data.width):
                xi = data.width - 1 - x
                pos = xi, y
                ndata[(x, y)] = data[pos]
    return ndata
Пример #6
0
def convert_dim_layout(data):
    ndata = Surface(width=data.height, height=data.width)
    points = data.get_points()
    for point in points:
        x, y = point
        npoint = (y, x)
        ndata[npoint] = data[point]
    return ndata
Пример #7
0
    def __init__(self, **kwargs):
        Surface.__init__(self, **kwargs)
        dev = kwargs.get('dev', '/dev/video0')
        args = get_args()

        ffmpeg = 'ffmpeg'
        scale = "scale=%d:%d" % (self.width, self.height)

        command = [ffmpeg,
                   '-loglevel', 'panic',
                   '-f', 'v4l2',
                   '-r', '30',
                   '-video_size', '160x120',
                   '-i', dev,
                   '-vf', scale,
                   '-f', 'image2pipe',
                   '-pix_fmt', 'rgb24',
                   '-vcodec', 'rawvideo',
                   '-']

        command = ' '.join(command)
        if args.debug:
            print("\ncommand: %s" % command)
        self.pipe = sp.Popen(shlex.split(command), stdout=sp.PIPE)
Пример #8
0
    def __init__(self, dims=matrix(0, 0, 1, 1), pixelsize=10, fullscreen=False,
                 interface=Interface):
        x, y, width, height = dims
        self.interface = interface(width, height, pixelsize, fullscreen)
        self.width = width
        self.height = height
        self.pixelSize = pixelsize

        self.window_width = width * pixelsize
        self.window_height = height * pixelsize

        self.interface.setcaption("Matrix Simulator.")
        self.psurface = Surface(dims=dims)

        self.interval = 1. / 30.
        self.current = 0
        self.previous = 0
Пример #9
0
 def __init__(self, **kwargs):
     Surface.__init__(self, **kwargs)
     self.fire = MiniFire(dims=matrix(0, 0, self.width * 2, self.height * 2))
Пример #10
0
 def __init__(self, **kwargs):
     """ create a surface and a buffer to keep changes in."""
     Surface.__init__(self, **kwargs)
     self.buffer = Surface(surface=self)
     self.bottom_points = [x for x in range(0, self.width)]
Пример #11
0
 def __init__(self, **kwargs):
     Surface.__init__(self)
     self.effect = WeirdPlasmaLike(dims=matrix(0, 0, self.width * 2, self.height * 2))
Пример #12
0
                changed = (Surface(pattern) != Surface(sendout.previous))
                sendout.previous = Surface(pattern)
            else:
                changed = True
            if changed and protocol:
                protocol.send(pattern, t)
    except KeyboardInterrupt:
        cleanup(9)
    except Exception as e:
        traceback.print_exc()
        print("\r\ndest: %s" % (t))
        print(pattern.__repr__)
        cleanup(8)


sendout.previous = Surface(width=10, height=10)


# cleanup exits calls close and leaves tty in sane state.
def cleanup(d):
    print("\nExiting(%d) closing connections." % d)
    # make tty be sane so that if the tty/terminal screws up.
    # this will make it workable again.
    os.system('stty sane; echo ""')
    sys.exit(0)


# generate no byte code
sys.dont_write_bytecode = True