def handle_add_pattern(params, persist=True): print params if 'pattern' in params or 'beatpattern' in params \ or 'grapheqpattern' in params or 'folder' in params: p = None track_beat = params['beat'][0] == 'true' graph_eq = 'grapheq' in params if 'pattern' in params: pattern_name = params['pattern'][0] if pattern_name.startswith("Specials"): if "new_wave" in pattern_name: p = NewWavePattern(num_lights=config['num_lights']) elif "wave" in pattern_name: p = WavePattern(num_lights=config['num_lights']) else: pattern_path = os.path.join(config['pattern_dir'], pattern_name) if os.path.exists(pattern_path): p = Bemis100Pattern(pattern_path, config['num_lights']) elif 'folder' in params: folder = params['folder'][0] folder = re.sub(r'^/*', '', folder) pattern_path = os.path.join(config['pattern_dir'], folder) print "folder", folder print "pattern path", pattern_path pattern_name = folder p = MixPattern(pattern_path, config['num_lights']) if p is not None: if track_beat: p = BeatPattern(p) elif graph_eq: p = GraphEqPattern(p) if 'num_times' in params: n = int(params['num_times']) else: n = -1 controller.add_pattern(p, n, name=pattern_name) print "Added pattern:", pattern_name else: print "Invalid pattern name:", pattern_name print "done" if persist: with open("last_command.json", "w") as f: json.dump(params, f)
def get(self): params = self.request.arguments print params if 'pattern' in params or 'beatpattern' in params \ or 'grapheqpattern' in params or 'folder' in params: p = None track_beat = params['beat'][0] == 'true' graph_eq = 'grapheq' in params if 'pattern' in params: pattern_name = params['pattern'][0] if pattern_name.startswith("Specials"): if "new_wave" in pattern_name: p = NewWavePattern(num_lights=config['num_lights']) elif "wave" in pattern_name: p = WavePattern(num_lights=config['num_lights']) else: pattern_path = os.path.join(config['pattern_dir'], pattern_name) if os.path.exists(pattern_path): p = Bemis100Pattern(pattern_path, config['num_lights']) elif 'folder' in params: folder = params['folder'][0] folder = re.sub(r'^/*', '', folder) pattern_path = os.path.join(config['pattern_dir'], folder) print "folder", folder print "pattern path", pattern_path pattern_name = folder p = MixPattern(pattern_path, config['num_lights']) if p is not None: if track_beat: p = BeatPattern(p) elif graph_eq: p = GraphEqPattern(p) if 'num_times' in params: n = int(params['num_times']) else: n = -1 controller.add_pattern(p, n, name=pattern_name) print "Added pattern:", pattern_name else: print "Invalid pattern name:", pattern_name print "done" self.write(json.dumps(dict(success=True)))
(r'/next', Next), (r'/pattern_groups',PatternGroups), (r'/status',Status) ] application = tornado.web.Application(handlers=handlers, static_path='static') for d in config['devices']: writer_class = writer_types[d['type']]['class'] writer_params = writer_types[d['type']]['defaults'] path = d['path'] new_writer = writer_class(path, **writer_params) print "Adding writer", new_writer controller.add_writer(new_writer) pattern_name = '_off.png' pattern_path = os.path.join(config['pattern_dir'], pattern_name) p = Bemis100Pattern(pattern_path, config['num_lights']) n = -1 controller.add_pattern(p, n, name=pattern_name) try: application.listen(5000) tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: print 'Exiting...' # for c in controller.writers: # c.close_port() controller.quit() print 'controller exit' sys.exit()