Ejemplo n.º 1
0
def test_hist_init():
    """
    Tests the __init__ method and getters in ImageHistory
    """
    print('Testing history initializer')
    import a6image
    import a6history
    p = pixels.Pixels(6)

    p[0] = (255, 0, 0)
    p[1] = (0, 255, 0)
    p[2] = (0, 0, 255)
    p[3] = (0, 255, 255)
    p[4] = (255, 0, 255)
    p[5] = (255, 255, 0)

    image = a6image.Image(p, 2)
    hist = a6history.ImageHistory(image)
    cornell.assert_equals(id(image), id(hist.getOriginal()))
    cornell.assert_equals(type(image), type(hist.getCurrent()))
    cornell.assert_not_equals(id(image), id(hist.getCurrent()))

    current = hist.getCurrent()
    cornell.assert_not_equals(id(p), id(current.getPixels()))
    for pos in range(current.getLength()):
        cornell.assert_equals(p[pos], current.getPixels()[pos])

    cornell.assert_true(hasattr(hist, '_history'))
    cornell.assert_equals(list, type(hist._history))
    cornell.assert_equals(1, len(hist._history))
Ejemplo n.º 2
0
    def __init__(self, bor):
        # self.currnet_idx = 16
        self.currnet_idx = 19
        texte = text.Text(bor)
        texte.set_text(10, 1, "XD XD XD XD")

        self.effects = [
            texte,  # 0
            pixels.Pixels(bor),  # 1
            rainbow.Rainbow(bor),  # 2
            sinrainbow2.SinRainbow2(bor),  # 3
            sinrainbow.SinRainbow(bor),  # 4
            #            tetris.Tetris(10, 10),
            metaballs.Metaballs(bor),  # 5
            disco.Disco(),  # 6
            pulsingcolor.PulsingColor(Color.blue()),  # 7
            xdcolor.XDColor(Color.red()),  # 8
            xdcolor.XDColor(Color.green()),  # 9
            xdcolor.XDColor(Color.blue()),  # 10
            solidcolor.SolidColor(Color.black()),  # 11
            droplet.Droplet(bor),  # 12
            paint.Paint(bor),  # 13
            tennis.Tennis(bor),  # 14
            rays.Rays(bor),  # 15
            plasma.Plasma(bor),  # 16
            #GifPlayer('/home/pi/xD-Table-Py/effects/gifplayer/gifs/fireplace_smol.gif'),  # 17
            GifPlayer(
                '/home/pi/xD-Table-Py/effects/gifplayer/gifs/fireplace_doniel.gif'
            ),  # 17
            rainbow_slow.RainbowSlow(bor),  # 18
            kibana.Heatmap(),  # 19
        ]
Ejemplo n.º 3
0
def test_image_str():
    """
    Tests the __str__ method in class Image
    """
    print('Testing image __str__ method')
    import a6image
    p = pixels.Pixels(6)

    p[0] = (255, 64, 0)
    p[1] = (0, 255, 64)
    p[2] = (64, 0, 255)
    p[3] = (64, 255, 128)
    p[4] = (128, 64, 255)
    p[5] = (255, 128, 64)

    str0 = '[[' + str(p[0]) + ', ' + str(p[1]) + '],  [' + str(
        p[2]) + ', ' + str(p[3]) + ']]'
    str1 = '[[' + str(p[0]) + ', ' + str(p[1]) + '],  [' + str(
        p[2]) + ', ' + str(p[3]) + '],  [' + str(p[4]) + ', ' + str(
            p[5]) + ']]'
    str2 = '[[' + str(p[0]) + ', ' + str(p[1]) + ', ' + str(
        p[2]) + '],  [' + str(p[3]) + ', ' + str(p[4]) + ', ' + str(
            p[5]) + ']]'
    str3 = '[[' + str(p[0]) + ', ' + str(p[1]) + ', ' + str(p[2]) + ', ' + str(
        p[3]) + ', ' + str(p[4]) + ', ' + str(p[5]) + ']]'
    str4 = '[[' + str(p[0]) + '],  [' + str(p[1]) + '],  [' + str(
        p[2]) + '],  [' + str(p[3]) + '],  [' + str(p[4]) + '],  [' + str(
            p[5]) + ']]'

    image = a6image.Image(p[:4], 2)
    cornell.assert_equals(str0, str(image))

    image = a6image.Image(p, 2)
    cornell.assert_equals(str1, str(image))
    image.setWidth(3)
    cornell.assert_equals(str2, str(image))
    image.setWidth(6)
    cornell.assert_equals(str3, str(image))
    image.setWidth(1)
    cornell.assert_equals(str4, str(image))
Ejemplo n.º 4
0
def test_image_setters():
    """
    Tests the setters for class Image
    """
    print('Testing image setters')
    import a6image
    p = pixels.Pixels(6)

    image = a6image.Image(p, 3)
    cornell.assert_equals(3, image.getWidth())
    cornell.assert_equals(2, image.getHeight())

    image.setWidth(2)
    cornell.assert_equals(2, image.getWidth())
    cornell.assert_equals(3, image.getHeight())

    image.setHeight(1)
    cornell.assert_equals(6, image.getWidth())
    cornell.assert_equals(1, image.getHeight())

    image.setWidth(1)
    cornell.assert_equals(1, image.getWidth())
    cornell.assert_equals(6, image.getHeight())

    # Test enforcement
    good = test_assert(image.setWidth, ['a'],
                       'You are not enforcing the precondition on width type')
    good = good and test_assert(
        image.setWidth, [5],
        'You are not enforcing the precondition on width validity')
    good = good and test_assert(
        image.setHeight, ['a'],
        'You are not enforcing the precondition on height type')
    good = good and test_assert(
        image.setHeight, [5],
        'You are not enforcing the precondition on height validity')
    if not good:
        exit()
Ejemplo n.º 5
0
def test_image_init():
    """
    Tests the __init__ method and getters for class Image
    """
    print('Testing image initializer')
    import a6image
    p = pixels.Pixels(6)

    image = a6image.Image(p, 3)
    cornell.assert_equals(id(p), id(image.getPixels()))
    cornell.assert_equals(6, image.getLength())
    cornell.assert_equals(3, image.getWidth())
    cornell.assert_equals(2, image.getHeight())

    image = a6image.Image(p, 2)
    cornell.assert_equals(id(p), id(image.getPixels()))
    cornell.assert_equals(6, image.getLength())
    cornell.assert_equals(2, image.getWidth())
    cornell.assert_equals(3, image.getHeight())

    image = a6image.Image(p, 1)
    cornell.assert_equals(id(p), id(image.getPixels()))
    cornell.assert_equals(6, image.getLength())
    cornell.assert_equals(1, image.getWidth())
    cornell.assert_equals(6, image.getHeight())

    # Test enforcement
    good = test_assert(a6image.Image, ['aaa', 3],
                       'You are not enforcing the precondition on data')
    good = good and test_assert(
        a6image.Image, [p, 'a'],
        'You are not enforcing the precondition on width type')
    good = good and test_assert(
        a6image.Image, [p, 5],
        'You are not enforcing the precondition on width validity')
    if not good:
        exit()
Ejemplo n.º 6
0
def test_hist_edit():
    """
    Tests the edit (increment/undo/clear) methods in ImageHistory
    """
    print('Testing history edit methods')
    import a6image
    import a6history
    p = pixels.Pixels(6)

    p[0] = (255, 0, 0)
    p[1] = (0, 255, 0)
    p[2] = (0, 0, 255)
    p[3] = (0, 255, 255)
    p[4] = (255, 0, 255)
    p[5] = (255, 255, 0)

    image = a6image.Image(p, 2)
    hist = a6history.ImageHistory(image)

    bottom = hist.getCurrent()
    bottom.setPixel(0, 0, (64, 128, 192))
    hist.increment()

    current = hist.getCurrent()
    cornell.assert_equals(bottom.getLength(), current.getLength())
    cornell.assert_equals(bottom.getWidth(), current.getWidth())
    cornell.assert_not_equals(id(bottom), id(current))
    cornell.assert_not_equals(id(bottom.getPixels()), id(current.getPixels()))
    for pos in range(current.getLength()):
        cornell.assert_equals(bottom.getPixels()[pos],
                              current.getPixels()[pos])

    hist.undo()
    cornell.assert_equals(id(bottom), id(hist.getCurrent()))

    hist.increment()
    hist.increment()
    hist.increment()
    cornell.assert_equals(4, len(hist._history))
    current = hist.getCurrent()
    cornell.assert_equals(bottom.getLength(), current.getLength())
    cornell.assert_equals(bottom.getWidth(), current.getWidth())
    cornell.assert_not_equals(id(bottom), id(current))
    cornell.assert_not_equals(id(bottom.getPixels()), id(current.getPixels()))
    for pos in range(current.getLength()):
        cornell.assert_equals(bottom.getPixels()[pos],
                              current.getPixels()[pos])

    hist.clear()
    cornell.assert_not_equals(id(bottom), id(hist.getCurrent()))
    cornell.assert_equals(1, len(hist._history))

    original = hist.getOriginal()
    current = hist.getCurrent()
    cornell.assert_equals(original.getLength(), current.getLength())
    cornell.assert_equals(original.getWidth(), current.getWidth())
    cornell.assert_not_equals(id(original), id(current))
    cornell.assert_not_equals(id(original.getPixels()),
                              id(current.getPixels()))
    for pos in range(current.getLength()):
        cornell.assert_equals(original.getPixels()[pos],
                              current.getPixels()[pos])

    bottom = hist.getCurrent()
    bottom.setPixel(0, 0, (64, 128, 192))
    for step in range(hist.MAX_HISTORY + 1):
        hist.increment()

    cornell.assert_equals(hist.MAX_HISTORY, len(hist._history))
    cornell.assert_not_equals(id(bottom), id(hist._history[0]))
Ejemplo n.º 7
0
def test_image_other():
    """
    Tests the copy and swapPixel methods in class Image
    """
    print('Testing image extras')
    import a6image
    p = pixels.Pixels(6)

    p[0] = (255, 64, 0)
    p[1] = (0, 255, 64)
    p[2] = (64, 0, 255)
    p[3] = (64, 255, 128)
    p[4] = (128, 64, 255)
    p[5] = (255, 128, 64)
    q = p[:]  # Need to copy this

    # Test the copy
    image = a6image.Image(p, 2)
    copy = image.copy()
    cornell.assert_equals(image.getLength(), copy.getLength())
    cornell.assert_equals(image.getWidth(), copy.getWidth())
    cornell.assert_not_equals(id(image), id(copy))
    cornell.assert_not_equals(id(image.getPixels()), id(copy.getPixels()))
    for pos in range(copy.getLength()):
        cornell.assert_equals(image.getPixels()[pos], copy.getPixels()[pos])

    # Test swap pixels
    image.swapPixels(0, 0, 2, 1)
    cornell.assert_equals(q[5], image.getPixel(0, 0))
    cornell.assert_equals(q[0], image.getPixel(2, 1))
    image.swapPixels(0, 0, 2, 1)
    cornell.assert_equals(q[0], image.getPixel(0, 0))
    cornell.assert_equals(q[5], image.getPixel(2, 1))
    image.swapPixels(0, 1, 2, 0)
    cornell.assert_equals(q[4], image.getPixel(0, 1))
    cornell.assert_equals(q[1], image.getPixel(2, 0))
    image.swapPixels(0, 1, 2, 0)
    cornell.assert_equals(q[1], image.getPixel(0, 1))
    cornell.assert_equals(q[4], image.getPixel(2, 0))
    image.swapPixels(0, 0, 0, 0)
    cornell.assert_equals(q[0], image.getPixel(0, 0))

    # Test enforcement
    good = test_assert(image.swapPixels, ['a', 1, 0, 0],
                       'You are not enforcing the precondition on row type')
    good = good and test_assert(
        image.swapPixels, [8, 1, 0, 0],
        'You are not enforcing the precondition on row value')
    good = good and test_assert(
        image.swapPixels, [0, 1, 'a', 0],
        'You are not enforcing the precondition on row type')
    good = good and test_assert(
        image.swapPixels, [0, 1, 8, 0],
        'You are not enforcing the precondition on row value')
    good = good and test_assert(
        image.swapPixels, [0, 'a', 0, 0],
        'You are not enforcing the precondition on column type')
    good = good and test_assert(
        image.swapPixels, [0, 8, 0, 0],
        'You are not enforcing the precondition on column value')
    good = good and test_assert(
        image.swapPixels, [0, 1, 0, 'a'],
        'You are not enforcing the precondition on column type')
    good = good and test_assert(
        image.swapPixels, [0, 1, 0, 8],
        'You are not enforcing the precondition on column value')
    if not good:
        exit()
Ejemplo n.º 8
0
def test_image_access():
    """
    Tests the methods get/setPixel and get/setFlatPixel in class Image
    """
    print('Testing image pixel access')
    import a6image
    p = pixels.Pixels(6)

    p[0] = (255, 0, 0)
    p[1] = (0, 255, 0)
    p[2] = (0, 0, 255)
    p[3] = (0, 255, 255)
    p[4] = (255, 0, 255)
    p[5] = (255, 255, 0)
    rgb1 = (255, 255, 255)
    rgb2 = (64, 128, 192)

    image = a6image.Image(p, 2)
    for n in range(6):
        cornell.assert_equals(p[n], image.getFlatPixel(n))
        cornell.assert_equals(id(p[n]), id(image.getFlatPixel(n)))

    image.setFlatPixel(4, rgb1)
    cornell.assert_equals(rgb1, image.getFlatPixel(4))
    image.setFlatPixel(4, rgb2)
    cornell.assert_equals(rgb2, image.getFlatPixel(4))

    for n in range(6):
        cornell.assert_equals(p[n], image.getPixel(n // 2, n % 2))
        cornell.assert_equals(id(p[n]), id(image.getPixel(n // 2, n % 2)))

    image.setPixel(2, 1, rgb1)
    cornell.assert_equals(rgb1, image.getPixel(2, 1))

    image.setPixel(2, 1, rgb2)
    cornell.assert_equals(rgb2, image.getPixel(2, 1))

    # Test enforcement
    good = test_assert(image.getPixel, ['a', 1],
                       'You are not enforcing the precondition on row type')
    good = good and test_assert(
        image.getPixel, [8, 1],
        'You are not enforcing the precondition on row value')
    good = good and test_assert(
        image.getPixel, [2, 'a'],
        'You are not enforcing the precondition on col value')
    good = good and test_assert(
        image.getPixel, [2, 8],
        'You are not enforcing the precondition on col value')
    good = good and test_assert(
        image.setPixel, ['a', 1, p],
        'You are not enforcing the precondition on row type')
    good = good and test_assert(
        image.setPixel, [8, 1, p],
        'You are not enforcing the precondition on row value')
    good = good and test_assert(
        image.setPixel, [2, 'a', p],
        'You are not enforcing the precondition on col value')
    good = good and test_assert(
        image.setPixel, [2, 8, p],
        'You are not enforcing the precondition on col value')
    if not good:
        exit()
Ejemplo n.º 9
0
                                                 sr=sr).T,
                         axis=0)

    features = numpy.vstack([
        numpy.empty((0, 193)),
        numpy.hstack([mfccs, chroma, mel, contrast, tonnetz])
    ])

    # Get sample from features
    sample = [features[i].ravel() for i in range(features.shape[0])]

    print("MFCC features extracted !")

    #############################
    ''' Predict the sound event'''

    pred = SVM.predict(numpy.array(list(sample)))

    print()
    print("Detected: ", sound_class[pred[0]])

    # Do the LED thing
    if (pred[0] == TO_DETECT):
        led = pixels.Pixels()
        led.wakeup()
        led.think()
        time.sleep(3)
        led.off()
    else:
        time.sleep(3)
Ejemplo n.º 10
0
if "site_id" not in config or not config["site_id"]:
    logging.error("No site ID. Aborting")
    exit(1)
if "topics" not in config or not config["topics"]:
    logging.info("No topic list. Aborting")
    exit(2)

# Get and parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("--google_home",
                    action="store_true",
                    help="Use the Google Home LED pattern")
args = parser.parse_args()

# Initialize LED controller
leds = pixels.Pixels()  # defauts to Alexa LED pattern
if args.google_home:
    leds.pattern = pixels.GoogleHomeLedPattern(show=leds.show)

# Initialize client
client_id = config["client_id"] if "client_id" in config and config[
    "client_id"] else f"hermes-respeaker-leds_{getpid()}"
client = mqtt.Client(client_id=client_id)

# Attach callbacks
client.on_message = on_message
client.on_connect = on_connect
client.on_disconnect = on_disconnect

# Set will and reconnect delay
#client.will_set('clients/hermes-respeaker-leds', payload="unavailable", qos=0, retain=False)
Ejemplo n.º 11
0
leds = None
running = True
recipe = None
currentStep = 0
timers = {}
confirm = 0
lang = ''

logger = logging.getLogger('MyChef')
logger.addHandler(logging.StreamHandler())

if __name__ == '__main__':
    logger.info('...My Chef...')

    if settings.USE_LEDS:
        leds = pixels.Pixels()
        leds.off()

    try:
        file = codecs.open('./languages/{}.json'.format(settings.LANG),
                           'r',
                           encoding='utf-8')
        string = file.read()
        file.close()
        lang = json.loads(string)
    except:
        logger.error('Error loading language file, exiting')
        sys.exit(0)

    mqttClient = mqtt.Client()
    mqttClient.on_connect = onConnect
Ejemplo n.º 12
0
        pixels.run_party()
        time.sleep(wait * 2)
        print("sat 127")
        pixels.set_saturation(127)
        time.sleep(wait * 2)
        print("sat 63")
        pixels.set_saturation(63)
        time.sleep(wait * 2)
        print("sat 10")
        pixels.set_saturation(10)
        time.sleep(wait * 2)
    signal.pause()


# start the test
pixels = pixels.Pixels()
if len(sys.argv) != 2:
    test_party()
elif sys.argv[1] == "1":
    test_quadrant()
elif sys.argv[1] == "2":
    test_max_brightness()
elif sys.argv[1] == "3":
    test_bright_percent()
elif sys.argv[1] == "4":
    test_direction()
else:
    test_party()

print("off")
pixels.off()
Ejemplo n.º 13
0
#!/usr/bin/env python3

import pixels
import time

leds = pixels.Pixels()  # Alexa LED pattern by default
#leds.pattern = pixels.GoogleHomeLedPattern(show=leds.show)

while True:
    try:
        leds.wakeup()
        time.sleep(3)

        leds.think()
        time.sleep(3)

        leds.speak()
        time.sleep(6)

        leds.off()
        time.sleep(3)
    except KeyboardInterrupt:
        break

leds.off()