Exemplo n.º 1
0
    def generator(self, leds, params):
        while True:
            pattern = self.patterns[randint(0, len(self.patterns) - 1)]
            pat = ledPatternFactory(pattern, self.cols, self.rows)

            iParams = Params(pat.editor)
            iParams.randomize(pat.editor)
            gen = pat.generator(leds, iParams)
            endTime = time() + params.minutes * 60.0
            try:
                while time() < endTime:
                    yield next(gen)
            except StopIteration:
                pass
Exemplo n.º 2
0
 def handle(self):
     req = self.rfile.readline().strip()
     cmd, pattern, p = json.loads(req)
     if cmd == 'pattern':
         params = Params()
         params.update(p)
         logging.info("Request: %s %s %s" % (cmd, pattern, params))
         pat = ledPatternFactory(pattern, LED_COLUMNS, LED_ROWS)
         self.ledThread.setPattern(pat, params)
     elif cmd == 'status':
         pass
     elif cmd == 'restart':
         self.server.stop()
     self.wfile.write(
         bytes(json.dumps(self.ledThread.status()) + '\n',
               encoding='utf-8'))
Exemplo n.º 3
0
def lightsPage():
    cstuff = cgistuff('Lights', jQuery=True)
    form = request.forms

    ledPattern = form.method if form.method in ledPatterns else ledPatterns[0]
    pattern = ledPatternFactory(ledPattern, LED_COLUMNS, LED_ROWS)
    d = Dialog(pattern.editor, form, None, autoSubmit=True)
    params = d.getParams()
    if form.method:
        with ledapi.ledapi() as led:
            led.setPattern(ledPattern, params)

    return [
        cstuff.standardTopStr(),
        template('lights-page',
                 pattern=ledPattern,
                 ledPatterns=ledPatterns,
                 editor=d.html()),
        cstuff.endBodyStr()
    ]
Exemplo n.º 4
0
 def _lightsOff(self):
     pattern = ledPatternFactory('Off', LED_COLUMNS, LED_ROWS)
     params = Params(pattern.editor)
     with ledapi.ledapi() as led:
         led.setPattern('Off', params)
Exemplo n.º 5
0
 def _lightsRandom(self):
     pattern = ledPatternFactory('RandomLights', LED_COLUMNS, LED_ROWS)
     params = Params(pattern.editor)
     params['minutes'] = 2.0
     with ledapi.ledapi() as led:
         led.setPattern('RandomLights', params)