示例#1
0
def recording():
    if request.method == "OPTIONS":
        response = Response(
            status=204,
            headers={
                "Access-Control-Allow-Origin":
                "*",
                "Access-Control-Allow-Methods": ["GET", "POST", "OPTIONS"],
                "Access-Control-Allow-Headers": [
                    "Charset",
                    "Content-Type",
                    "Access-Control-Allow-Origin",
                    "Access-Control-Allow-Methods",
                ],
            },
        )
        return response
    elif request.method == "GET":
        response = Response(
            json.dumps(isrecording),
            status=200,
            mimetype="application/json",
            headers={"Access-Control-Allow-Origin": ["*"]},
        )
        return response
    elif request.method == "POST":
        incoming_data = request.get_data().decode("utf-8")

        try:
            parsed_data = json.loads(incoming_data)
        except:
            parsed_data = ast.literal_eval(incoming_data)

        # Update if Bonnie's recording or not
        isrecording.update(parsed_data)

        # If recording True, turn Purple
        if isrecording["recording"] is True:
            b1 = Blink1()
            b1.fade_to_color(500, "purple")
            b1.close()

        elif isrecording["recording"] is False:
            b1 = Blink1()
            b1.fade_to_color(500, "black")
            b1.close()

        response = Response(
            json.dumps(isrecording),
            status=200,
            headers={
                "Access-Control-Allow-Origin": "*",
                "Content-Type": "application/json",
            },
        )

        return response
示例#2
0
def blink1_color(msec, r, g, b):
    try:
        blink1 = Blink1()
        blink1.fade_to_rgb(msec, r, g, b)
        blink1.close()
    except:
        print("no blink1 found")
示例#3
0
 def transition(self, target_state, transition_time=0):
     std_transition = 1000
     b1 = Blink1()
     if target_state == self.current_state:
         b1.close()
         return
     b1.fade_to_color(std_transition, 'black')
     if target_state.blink_cluster == 0:
         b1.fade_to_color(std_transition, target_state.colour)
         b1.close()
         return
     elif target_state.blink_cluster > 8:
         target_state.blink_cluster = 8
         target_state.long_gap = target_state.short_gap
     b1.writePatternLine(target_state.long_gap,
                         target_state.secondary_colour, 0)
     for line in range(1, target_state.blink_cluster * 2):
         if line % 2:
             b1.writePatternLine(target_state.short_gap,
                                 target_state.colour, line)
         else:
             b1.writePatternLine(target_state.short_gap,
                                 target_state.secondary_colour, line)
     b1.play(0, target_state.blink_cluster * 2 - 1)
     b1.close()
     self.current_state = target_state
示例#4
0
def Light():
    b1 = Blink1()
    b1.writePatternLine(100, 'red', 3)
    b1.writePatternLine(100, 'black', 4)
    b1.writePatternLine(100, 'blue', 5)
    b1.play(3, 5, 15)
    time.sleep(3)
    b1.fade_to_color(100, 'black')
示例#5
0
 def blink(self):
     try:
         blink1 = Blink1()
     except Blink1ConnectionFailed as e:
         logging.error('Blink1 error: %s', e)
         return
     blink1.fade_to_color(300, self.color)
     time.sleep(0.3)
     blink1.fade_to_color(300, '#000000')
     blink1.close()
示例#6
0
def flash(on, off, duration, repeat, fade):
    blink1 = Blink1()

    for i in range(0, repeat):
        blink1.fade_to_color(fade * 1000, on)
        time.sleep(duration / 2.0)
        blink1.fade_to_color(fade * 1000, off)
        time.sleep(duration / 2.0)

    blink1.fade_to_rgb(fade * 1000, 0, 0, 0)
示例#7
0
def api_factory() -> Any:
    api = None

    try:
        from blink1.blink1 import Blink1, Blink1ConnectionFailed

        try:
            api = Blink1()
        except Blink1ConnectionFailed:
            exit(
                wording.get('connection_no').format('THINGM BLINK') +
                wording.get('exclamation_mark'))
        return api
    except ImportError:
        exit(
            wording.get('package_no').format('THINGM BLINK') +
            wording.get('exclamation_mark'))
示例#8
0
文件: thingm.py 项目: iamsrp/dexter
    def __init__(self):
        """
        @see ByComponentNotifier.__init__()
        """
        super(Blink1Notifier, self).__init__()

        # The time, since epoch, when each component type stopped being active
        self._input_time = 0
        self._service_time = 0
        self._output_time = 0

        # The currently non-idle components
        self._inputs = set()
        self._services = set()
        self._outputs = set()

        # The actual dongle handle
        self._b1 = Blink1()
 def blink1_reacts_to_call(self):
     try:
         self.blinker = Blink1()
     except Blink1ConnectionFailed:
         print(
             "There appeared to be an error connecting to 'blink(1)' USB stick."
         )
     while True:
         if self.call_status == "RINGING":
             self.blinker.fade_to_color(100, 'blue')
             sleep(0.1)
             self.blinker.fade_to_color(100, 'black')
             sleep(0.1)
         elif self.call_status == "IN_CALL":
             self.blinker.fade_to_color(1000, 'red')
             sleep(0.5)
         else:
             self.blinker.fade_to_color(500, 'black')
             sleep(0.5)
     self.blinker.close()
示例#10
0
def blink(colour):
    b1 = Blink1()
    b1.play_pattern(colour)
    b1.close()
示例#11
0
#
#
# You could use this script to map the real time travel times of the past day (cron job, every minute)
# To plot grpahs you could use: http://plot.ly
#
#
import time
import simplejson
import urllib
import json
from datetime import datetime
from blink1.blink1 import Blink1
import requests

b1 = Blink1()
try:
    while True:
        date = datetime.now()
        date1 = date.strftime("%m/%d/%Y %H:%M")

        # Create the POST request
        data = {'starttime': date1}
        requests.packages.urllib3.disable_warnings()

        headers = {
            '$Host': 'mopac-fare.mroms.us',
            '$User-Agent':
            'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0',
            '$Accept': 'application/json, text/javascript, */*; q=0.01',
            '$Accept-Language': 'en-US,en;q=0.5',
示例#12
0
 def __init__(self):
     blink1_serials = Blink1.list()
     self.serial = blink1_serials[0]
     self.blink1 = Blink1(serial_number=self.serial)
示例#13
0
 def __init__(self):
     self.occupied = False
     self.blink = Blink1()
     self.blink.write_pattern_line(100, 'yellow', 1)
     self.blink.write_pattern_line(100, 'black', 2)
     self.set_occupied(False)
示例#14
0
#!/usr/bin/env python
"""
demo_pattern0 -- demo of blink1 library color pattern reading
"""
import sys
from blink1.blink1 import Blink1

try:
    blink1 = Blink1(gamma=(1, 1, 1))  # disable gamma
except:
    print("no blink1 found")
    sys.exit()

print("Reading full color pattern:")
pattern = blink1.read_pattern()
print(pattern)
示例#15
0
def turn_led_off():
    b1 = Blink1()
    b1.fade_to_color(0, "black")
    b1.close()
示例#16
0
 def shutdown(self):
     b1 = Blink1()
     b1.off()
     b1.close()
示例#17
0
#!/usr/bin/env python
"""
demo_serial -- demo of blink1 library showing serial number and versions

"""
from blink1.blink1 import Blink1

try:
    blink1 = Blink1()
except:
    print("no blink1 found")
    sys.exit()
print("blink(1) found")

print("  serial number: " + blink1.get_serial_number())
print("  firmware version: " + blink1.get_version())

print("closing connection to blink(1)")
blink1.close()

print("done")
示例#18
0
        cliOutput = True
        print("activating CLI output")
    elif argument == "-d" or argument == "--display":
        display = True
        print("activating output on extra LEDs")
    elif argument == "-m" or argument == "--multiLed":
        multiLed = True
        print("activating output on extra LEDs")
    elif argument[0:2] == "-d":
        blink1Id = argument[2:]

while run:
    """get Blink1 device handle"""
    try:
        if blink1Id == '':
            b1 = Blink1()
        else:
            b1 = Blink1(blink1Id)
        if cliOutput:
            serial = b1.get_serial_number()
            print("blink1({}) found".format(serial))
        blink1Found = True
        """init """
        setMyPattern(b1)
        nextRun = time.time() + interval
        disk_io_old = psutil.disk_io_counters()
        net_io_old = psutil.net_io_counters()

        b1.fade_to_rgb(0, 0, 0, 0, 0)
    except:
        blink1Found = False
示例#19
0
 def setUpClass(cls):
     cls.b1 = Blink1()
示例#20
0
 def testCannotFind(self):
     with mock.patch('blink1.blink1.PRODUCT_ID', '0101'):
         with self.assertRaises(BlinkConnectionFailed):
             b1 = Blink1()
示例#21
0
"""

import time, sys
from blink1.blink1 import Blink1

blink1_serials = Blink1.list()
if blink1_serials:
    print("blink(1) devices found: " + ','.join(blink1_serials))
else:
    print("no blink1 found")
    sys.exit()

# To open a particular blink(1), do:
# blink1 = Blink1(serial_number=u'20006487')
print("opening first blink(1)")
blink1 = Blink1(serial_number=blink1_serials[0])  # first blink1
print("  serial number: " + blink1.get_serial_number())
print("  firmware version: " + blink1.get_version())

print("  playing green, purple, off...")
blink1.fade_to_rgb(500, 0, 255, 0)
time.sleep(0.5)
blink1.fade_to_rgb(500, 255, 0, 255)
time.sleep(0.5)
blink1.fade_to_rgb(500, 0, 0, 0)
time.sleep(0.5)

print("closing.")
blink1.close()

print("opening last blink(1)")
示例#22
0
from blink1.blink1 import blink1
import time

from blink1.blink1 import Blink1
b2 = Blink1()


def busy():
    activate('purple')


def success():
    activate('cyan')


def failure():
    activate('red')


def unstable():
    activate('orange')


def activate(color):
    print("activate: " + color)
    try:
        # b2.fade_to_rgb(1000, 255, 255, 255)
        with blink1() as b1:
            for i in range(5):
                b1.fade_to_color(100, color)
                time.sleep(.8)