コード例 #1
0
ファイル: puzzled.py プロジェクト: emm-ess/puzzled
def main():

    try:
        mote = None
        try:
            mote = Mote()
            mote.configure_channel(1, 16, False)
            mote.configure_channel(2, 16, False)
            mote.configure_channel(3, 16, False)
            mote.configure_channel(4, 16, False)
            mote.clear()
        except:
            pass

        puzzled = Puzzled(mote)
        puzzled.start()

        if mote != None:
            for channel in range(1, 5):
                for pixel in range(16):
                    mote.set_pixel(channel, pixel, 0, 0, 0)
            mote.show()

        curses.nocbreak()
        screen.keypad(False)
        curses.echo()
        curses.endwin()
        quit()
    except:
        curses.nocbreak()
        screen.keypad(False)
        curses.echo()
        curses.endwin()
        print(sys.exc_info())
コード例 #2
0
def connectToMote(moteId="", led=(1, 0, 0, 0), changeOnly=False):
    """
    cache = MoteCache()
    cache.read()

    # print "GetMotes:", cache.getMotes()
    allDevs = detectAllPossible()

    selectedMoteId = None
    for d in allDevs:
        if d in cache.getMotes():
            selectedMoteId = d
            break

    if selectedMoteId == None:
        print "No motes found.  Device ids:", allDevs, "cacheMoteIds:", cache.getMotes().keys()
        sys.exit()

    # mote = cache.getMotes().values()[0]
    mote = cache.getMotes()[selectedMoteId]
    """

    #if moteId == "":
    #    moteId = "00:17:AB:32:BF:EF"
    #mote = Mote(id="00:19:1D:79:93:E0")
    #mote = Mote(id="00:17:AB:32:BF:EF")
    mote = Mote(id=moteId)
    mote.connect()

    #mote.setLeds(1,0,0,0)
    if mote.connected:
        mote.setLeds(led[0], led[1], led[2], led[3])
        mote.startReadThread()
        mote.irBasicModeOn(changeOnly=changeOnly)
    return mote
コード例 #3
0
def open_mote():
    m = Mote()

    for channel in range(1, 5):
        m.configure_channel(channel, 16, False)

    return m
コード例 #4
0
def run():
    """let's goooo"""
    mote = Mote()

    mote.configure_channel(1, 16, False)
    mote.configure_channel(2, 16, False)
    mote.configure_channel(3, 16, False)
    mote.configure_channel(4, 16, False)

    rand_cols = ColorRandom()

    patterns = [
        pattern_floodfill,
        pattern_scatter,
        pattern_race,
        pattern_horizflood,
        pattern_horizsnakeflood,
        pattern_snakeflood,
    ]
    black = lambda: ColorConstant([0, 0, 0])
    colors = [
        ColorRandom,
        lambda: ColorConstant(rand_cols.get(None)),
        lambda: ColorChannelConstant(rand_cols),
        lambda: ColorChannelFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorGlobalFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorPixelFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorHorizCenterFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorRadialFade(rand_cols.get(None), rand_cols.get(None)),
        lambda: ColorChequerboard(rand_cols),
    ]
    last_col_template = None
    last_pattern_template = None

    while True:
        pattern_template = choice(patterns)
        if pattern_template == last_pattern_template:
            continue
        pattern = pattern_template() if random() < 0.5 else pattern_reverse(
            pattern_template())

        color_template = black if (random() < 0.33 and last_col_template is not None) \
            else choice(colors)
        if color_template == last_col_template:
            continue
        color = color_template()

        for update in pattern:
            c = color.get(update)
            prev_c = mote.get_pixel(update[0], update[1])
            for step in range(8):
                step_c = lerp_cols(step / 7.0, prev_c, c)
                mote.set_pixel(update[0], update[1], step_c[0], step_c[1],
                               step_c[2])
                mote.show()
                time.sleep(0.03)

        last_col_template = color_template
        last_pattern_template = pattern_template
コード例 #5
0
 def read(self, filename="mote.cache"):
     if os.path.exists("mote.cache"):
         cache = open("mote.cache", "r")
         cachedDevs = eval(cache.read())
         print "cachedDevs:", cachedDevs
         for device in cachedDevs:
             self.cachedDevs[device[0]] = Mote(device[0], device[1])
         cache.close()
コード例 #6
0
    def __init__(self):
        self.mote = Mote()

        gammaCorrection = False
        self.mote.configure_channel(1, 16, gammaCorrection)
        self.mote.configure_channel(2, 16, gammaCorrection)
        self.mote.configure_channel(3, 16, gammaCorrection)
        self.mote.configure_channel(4, 16, gammaCorrection)
コード例 #7
0
    def addMotes(self, moteTupleList):
        if type(moteTupleList) == type(list()):
            for m in moteTupleList:
                self.cachedDevs[m[0]] = Mote(m[0], m[1])

            #if len(moteList) > 0:
            #    if type(moteList[0]) == type(mote.Mote())
            #        for m in moteList:
            #            self.cachedDevs[m.id] = m
        else:
            raise Exception("addMotes expected a list")
コード例 #8
0
def setstick(s, r, g, b):
    mote = Mote()  # new instance of the Mote class, will do all the USB init
    state = getmotestate()
    for m in range(1, 4 + 1):
        mote.configure_channel(m, 16,
                               False)  # configure for use the Mote sticks
        setpixels(m, state[m - 1][0], state[m - 1][1], state[m - 1][2], mote)
    if s == 0:
        for st in range(1, 4 + 1):
            setpixels(st, r, g, b, mote)
            setmotestate(state, st, r, g, b)
    else:
        setpixels(s, r, g, b, mote)
        setmotestate(state, s, r, g, b)
    mote.show()
コード例 #9
0
def init_motes(colour, brightness):
    print("initialising Motes")
    #set
    mote = Mote()  # new instance of the Mote class, will do all the USB init
    for m in range(1, 4 + 1):
        mote.configure_channel(m, 16,
                               False)  # configure for use the Mote sticks
    #calculate colour for brightness
    # just first stick at the moment
    h, s, v = colorsys.rgb_to_hsv(colour[0][0], colour[0][1], colour[0][2])
    colour_new = [[0] * 3 for i in range(4)]
    colour_new[0][0], colour_new[0][1], colour_new[0][2] = rgb_to_decimal(
        colorsys.hsv_to_rgb(h, s, brightness))
    set_mote_sticks(mote, colour_new)
    return mote
コード例 #10
0
def connectmote():
    try:
        mote = Mote()
        retdata = {'MoteReply': {'status': '1'}}
    except IOError:
        mote = None
        retdata = {
            'MoteReply': {
                'status':
                '0',
                'error':
                'Mote device failed to connect. Check device is physically connected and try again.'
            }
        }
        return json.jsonify(retdata)
コード例 #11
0
def setstick(s, b, i):
    mote = Mote()  # new instance of the Mote class, will do all the USB init
    state = getmotestate()
    if i != 0:
        b = getbrightness(state, s) + i
        if b < 0:
            b = 0
        elif b > 9:
            b = 9
    state = setbrightness(state, s, b, i)
    for m in range(1, 4 + 1):
        mote.configure_channel(m, 16,
                               False)  # configure for use the Mote sticks
        setpixels(m, state[m - 1][0], state[m - 1][1], state[m - 1][2], mote)
    mote.show()
    setmotestate(state, s, state[s - 1][0], state[s - 1][1], state[s - 1][2])
コード例 #12
0
ファイル: mote.py プロジェクト: jtc42/unicornpi-server
    def __init__(self, channels=4, correction=[1., 1., 1.]):

        self.mote = Mote()

        for c in range(channels):
            self.mote.configure_channel(c + 1, 16, False)

        BaseLamp.__init__(self, correction=correction)

        self.channels = channels
        self.pixels = 16

        for channel in range(self.channels):
            self.mote.configure_channel(channel + 1, self.pixels, False)

        self.width = self.channels
        self.height = self.pixels
コード例 #13
0
    def connectToMote(self):
        self.showMessage("Connecting")
        try:
            from mote import Mote
            self.mote = Mote()
            self.simulate = False
            self.showMessage("Connected")
            if not self.simulate:
                self.mote.clear()
                self.mote.show()
        except IOError:
            self.simulate = True
            self.showMessage("Simulating")

        self.yToStick = []
        self.addStick(1)
        self.addStick(2)
        self.addStick(3)
        self.addStick(4)
コード例 #14
0
from time import sleep

from mote import Mote
from bluezero import constants
from bluezero import tools
from bluezero import adapter
from bluezero import device
from bluezero.GATT import Characteristic

display_on = False
lights = Mote()

mote_pixels = 16
lights.configure_channel(1, mote_pixels, False)


def on_accel_change(iface, changed_props, invalidated_props):
    print('Accel!')
    global display_on
    if iface != constants.GATT_CHRC_IFACE:
        return

    if not len(changed_props):
        return

    accel_val = changed_props.get('Value', None)
    if not accel_val:
        return

    # Read button value
    x = abs(int.from_bytes(accel_val[0:1], byteorder='little', signed=True))
コード例 #15
0
from mote import Mote
import sys
motes = Mote()
motes.configure_channel(1, 16, False)

r = int(sys.argv[1])
g = int(sys.argv[2])
b = int(sys.argv[3])

motes.clear()
motes.set_pixel(1, 0, r, g, b)
motes.set_pixel(1, 1, r, g, b)
motes.set_pixel(1, 2, r, g, b)
motes.set_pixel(1, 3, r, g, b)
motes.set_pixel(1, 4, r, g, b)
motes.set_pixel(1, 5, r, g, b)
motes.set_pixel(1, 6, r, g, b)
motes.set_pixel(1, 7, r, g, b)
motes.set_pixel(1, 8, r, g, b)
motes.set_pixel(1, 9, r, g, b)
motes.set_pixel(1, 10, r, g, b)
motes.set_pixel(1, 11, r, g, b)
motes.set_pixel(1, 12, r, g, b)
motes.set_pixel(1, 13, r, g, b)
motes.set_pixel(1, 14, r, g, b)
motes.set_pixel(1, 15, r, g, b)
motes.show()
コード例 #16
0
try:
    import requests
except ImportError:
    exit(
        "This script requires the requests module\nInstall with: sudo pip install requests"
    )

import serial.tools.list_ports
list = serial.tools.list_ports.comports()

#Find the MOTE Hubs!   This machine has 2 installed
var1 = 1
for element in list:
    if 'Mote' in element.description:
        if var1 == 1:
            mote1 = Mote(port_name=element.device)
            var1 = 2
        elif var1 == 2:
            mote2 = Mote(port_name=element.device)

#Configure the 16 LED's, clear channels on both hubs
mote1.configure_channel(1, 16, False)
mote1.configure_channel(2, 16, False)
mote1.configure_channel(3, 16, False)
mote1.configure_channel(4, 16, False)

mote2.configure_channel(1, 16, False)
mote2.configure_channel(2, 16, False)
mote2.configure_channel(3, 16, False)
mote2.configure_channel(4, 16, False)
コード例 #17
0
ファイル: buttons.py プロジェクト: rpwagner/tiled-display
    selectedMoteId = None
    for d in allDevs:
        if d in cache.getMotes():
            selectedMoteId = d
            break

    if selectedMoteId == None:
        print "No motes found.  Device ids:", allDevs, "cacheMoteIds:", cache.getMotes().keys()
        sys.exit()

    # mote = cache.getMotes().values()[0]
    mote = cache.getMotes()[selectedMoteId]
    mote.connect()
    """
    mote = Mote(id="00:19:1D:79:93:E0")
    mote.connect()

    mote.setLeds(1,0,0,0)

    mote.startReadThread()
    mote.irBasicModeOn()

    while(1):
        time.sleep(0.1)
        events =  mote.extractButtonEvents()
        if len(events) != 0:
            print events

    mote.disconnect()
import keybow

# On user input, this program mutates red, gree, and blue values in rgblist and sends them to the buffer (ie. outputs the light colours to the mote LED sticks). The light remains on until another selection is made of the program ends.

# start keybow mini
keybow.setup(keybow.MINI)

# Default RGB definitions (ie. off)
R = 0
G = 0
B = 0
rgblist = [R, G, B]
brightlist = [R, G, B]

#mote definitions: this script allows for multiple Mote controllers. ls /dev/ to determine the names of your more serial ports and plug them in below.
mote = Mote(port_name='/dev/ttyACM0')
mote2 = Mote(port_name='/dev/ttyACM1')
mote.configure_channel(1, 16, False)
mote.configure_channel(2, 16, False)
mote.configure_channel(3, 16, False)
mote.configure_channel(4, 16, False)
mote2.configure_channel(1, 16, False)
mote2.configure_channel(2, 16, False)
mote2.configure_channel(3, 16, False)
mote2.configure_channel(4, 16, False)
mote.clear()
mote2.clear()

# Light mode name and RGB code for each (2000, 2700, 3000, 3700, 5000 Kelvin)
candle = [255, 138, 18]
fortyw = [255, 169, 87]
コード例 #19
0
ファイル: __init__.py プロジェクト: topshed/OctoPrintMote
    def moteUSB(self):

        if moteType == 'USB':
            global mote
            mote = Mote()
コード例 #20
0
#!/usr/bin/env python

import colorsys
import math
import signal
import time
from random import randint, sample
import argparse
import sys

if sys.platform == 'darwin':
    from mote import Mote
    motephat = Mote()
    motephat.configure_channel(1, 16, False)
    motephat.configure_channel(2, 16, False)
else:
    import motephat
    motephat.set_brightness(1)

parser = argparse.ArgumentParser()
parser.add_argument("sequence",
                    choices=['sparkle', 'flash'],
                    help="Type of mote sequence to play.")
parser.add_argument("-i",
                    "--interval",
                    default=0.1,
                    type=float,
                    help="Interval between sparkles in seconds (default=0.1).")
parser.add_argument(
    "-d",
    "--density",
コード例 #21
0
ファイル: random-pattern.py プロジェクト: Dibble/mote-scripts
from mote import Mote
import random
import time

m = Mote()
m.set_clear_on_exit(True)
m.configure_channel(1, 16, False)
m.configure_channel(2, 16, False)
m.configure_channel(3, 16, False)
m.configure_channel(4, 16, False)
m.clear()

try:
    while True:
        clear = random.randint(0, 9)
        if clear == 0:
            m.clear()

        for channel in range(1, 5):
            pixel = random.randint(0, 15)
            red = random.randint(0, 255)
            green = random.randint(0, 255)
            blue = random.randint(0, 255)
            delay = random.randint(2, 20)

            m.set_pixel(channel, pixel, red, green, blue, 0.5)

        m.show()

        time.sleep(delay / 1000)
コード例 #22
0
ファイル: motemeter.py プロジェクト: clivemjeffery/soundlevel
import time
from mote import Mote

mote = Mote()
mote.configure_channel(1, 16, False)
mote.configure_channel(2, 16, False)
mote.configure_channel(3, 16, False)
mote.configure_channel(4, 16, False)
mote.clear()


def clamp16(n):
    return max(min(16, n), 0)


def moteset(n, r, g, b):
    # strip 1 (increasing pixels)
    r1 = clamp16(n)  # values between 1 and 16
    for pixel in range(r1):
        mote.set_pixel(1, pixel, r, g, b)
    # strip 2 (inc.)
    r2 = clamp16(n - 16)  # values between 17 and 32
    for pixel in range(r2):
        mote.set_pixel(2, pixel, r, g, b)
    # strip 3 (decreasing pixels)
    r3 = clamp16(n - 32)  # values between 33 and 48
    for pixel in range(15, 15 - r3, -1):
        mote.set_pixel(3, pixel, r, g, b)
    # strip 4 (dec.)
    r4 = clamp16(n - 48)  # values betwene 47 and 64
    for pixel in range(15, 15 - r4, -1):
コード例 #23
0
import serial
# import struct
# import requests
# import traceback
import sys
import json

from mote import Mote

serial_connection = serial.Serial('/dev/ttyACM0', 115200, timeout=None)
mote = Mote(serial_connection)
i = 0
while True:
    data = mote.readline()
    print("Read from serial:", data)
    data = data + 1
    print("Enviando to serial:", data)
    mote.put(data)
    # make_request(data)