Exemplo n.º 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
Exemplo n.º 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")
Exemplo n.º 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
Exemplo n.º 4
0
def healthcheck():
    blink1_serials = Blink1.list()
    print(blink1_serials)
    if blink1_serials:
        return Response(f"Healthy; device connected: {blink1_serials[0]}",
                        status=200)
    else:
        return Response("Not Ready", status=503)
Exemplo n.º 5
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')
Exemplo n.º 6
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()
Exemplo n.º 7
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)
Exemplo n.º 8
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'))
Exemplo n.º 9
0
    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()
Exemplo n.º 10
0
 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()
Exemplo n.º 11
0
from blink1.blink1 import Blink1

pattern_strs = [
    '3, #ff00ff,0.3,1, #00ff00,0.1,2,#ff00ff,0.3,2,#00ff00,0.1,1,#000000,0.5,0',
    '5, #FF0000,0.2,0,#000000,0.2,0',
    ' 10, #ff00ff,0.3,1, #00ff00,0.1,2,  #ff00ff,0.3,2, #00ff00,0.1,1',
    '  10, #ff00ff,0.3,1, #00ff00,0.1,2 ',
    '  7, #ff00ff,0.3,1, #00ff00,0.1,2, #ff3333  ',
    '  1, ',
    '  2, #ff99cc,,0.3',
    '  0, #ff00ff,0.3',
]

patt_str = pattern_strs[1]

(num_repeats, pattern_list) = Blink1.parse_pattern(patt_str)
print('num_repeats: ', num_repeats)
print('pattern_list: ', pattern_list)

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

play_on_blink1 = True
#play_on_blink1 = False

if (play_on_blink1):
    print("playing on blink1 device (thus not blocking)")
Exemplo n.º 12
0
 def __init__(self):
     blink1_serials = Blink1.list()
     self.serial = blink1_serials[0]
     self.blink1 = Blink1(serial_number=self.serial)
Exemplo n.º 13
0
import time
from blink1.blink1 import Blink1

blink1_serials = Blink1.list()
print("blink(1) devices found: " + ','.join(blink1_serials))

b1 = Blink1()
b1.fade_to_rgb(1000, 64, 64, 64)
time.sleep(3)
b1.fade_to_rgb(1000, 255, 255, 255)
blink1.close()
Exemplo n.º 14
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)
Exemplo n.º 15
0
 def setUpClass(cls):
     cls.b1 = Blink1()
Exemplo n.º 16
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
Exemplo n.º 17
0
def turn_led_off():
    b1 = Blink1()
    b1.fade_to_color(0, "black")
    b1.close()
Exemplo n.º 18
0
 def shutdown(self):
     b1 = Blink1()
     b1.off()
     b1.close()
Exemplo n.º 19
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")
Exemplo n.º 20
0
def blink(colour):
    b1 = Blink1()
    b1.play_pattern(colour)
    b1.close()
Exemplo n.º 21
0
def blink_set_state(blink1,fade_millis,rgbstr,ledn=0):
        rgb=Blink1.parse_color_string( rgbstr )
        blink1.fade_to_rgbn( fade_millis, rgb[0],rgb[1],rgb[2], ledn)
Exemplo n.º 22
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',
Exemplo n.º 23
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)
Exemplo n.º 24
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)
Exemplo n.º 25
0
 def testCannotFind(self):
     with mock.patch('blink1.blink1.PRODUCT_ID', '0101'):
         with self.assertRaises(BlinkConnectionFailed):
             b1 = Blink1()
Exemplo n.º 26
0
#!/usr/bin/env python
"""
demo2 -- demo of blink1 library, accessing multiple blink(1) devices

"""

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)
Exemplo n.º 27
0
import ast, json
from flask import Flask, Response, request
from flask_cors import CORS
from blink1.blink1 import Blink1

# Flask Setup
app = Flask(__name__)
CORS(app)

# Set the default state; we don't need no stinkin' database!
isrecording = {"recording": False}

# Print Blink Serial Information
blink1_serials = Blink1.list()
if blink1_serials:
    print(f"blink(1) devices found: {blink1_serials}")
else:
    print("blink(1) device not found! Connect it and try running this again.")
    quit()


# Startup function: turn the LED off
def turn_led_off():
    b1 = Blink1()
    b1.fade_to_color(0, "black")
    b1.close()


# Health Check Endpoint
@app.route("/api/health", methods=["GET", "HEAD"])
def healthcheck():