Exemplo n.º 1
0
def mode_query_interpreter(queries):
    mode = None
    colours = None
    try:
        mode = find_mode(search_q(queries, 'mode'))

        colours = []
        colours_q = search_q(queries, "hexcolour", return_list=True)
        for colour in colours_q:
            colours.append(rbgLib.hex_to_colour(colour))
        print colours
    except Exception:
        print Exception

    if mode == led_modes.mode_breathe:
        md = led_modes.mode_breathe(
            colours,
            search_q(
                queries,
                "period",
                fallback=0.01))
        rgbLEDx.bind_mode(md)

    elif mode == led_modes.mode_alert:

        md = led_modes.mode_alert(colours[0])
        rgbLEDx.interruptMode(md, pause=True, resume_thread=True)

    elif mode == led_modes.mode_strobe:
        md = led_modes.mode_strobe(
            colours,
            search_q(
                queries,
                "period",
                fallback=0.02))
        rgbLEDx.bind_mode(md)
    #elif mode == led_modes.None:
        # TODO I'm working on a 'mode' that kills all modes and turns the LEDs

    elif mode == led_modes.mode_static:
            md = led_modes.mode_static(
                colours[0])
            rgbLEDx.bind_mode(md)
        #elif mode == led_modes.None:
            # TODO I'm working on a 'mode' that kills all modes and turns the LEDs



    elif mode == led_modes.mode_rainbow:
        md =led_modes.mode_rainbow(
            search_q(
                queries,
                "period",
                fallback=0.01))
        rgbLEDx.bind_mode(md)

    elif mode == led_modes.mode_fadeto:
         md =led_modes.mode_fadeto(
             colours[0],
            search_q(
                queries,
                "period",
                fallback=0.01))
         rgbLEDx.bind_mode(md)



    else:
        rgbLEDx.set_colour(rbgLib.orange)
Exemplo n.º 2
0
from BaseHTTPServer import BaseHTTPRequestHandler
import urlparse
import rbgLib
# import time
import led_modes
import voice_command_interpreter

__author__ = 'Rory'
rbgLib.init()
frequency = 1000
redLED = rbgLib.LED(18, True, frequency)
greenLED = rbgLib.LED(24, True, frequency)
blueLED = rbgLib.LED(23, True, frequency)
rgbLEDx = rbgLib.rbgLed(redLED, greenLED, blueLED)

md = led_modes.mode_alert(rbgLib.aqua)
rgbLEDx.bind_mode(md)


def find_mode(mode_string):
    return led_modes.modes[mode_string]


def search_q(queries, search_string, return_list=False, fallback=None):
    try:
        if return_list:
            return queries[search_string]
        else:
            return queries[search_string][0]

    except: