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
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")
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
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)
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')
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()
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)
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'))
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()
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)")
def __init__(self): blink1_serials = Blink1.list() self.serial = blink1_serials[0] self.blink1 = Blink1(serial_number=self.serial)
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()
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)
def setUpClass(cls): cls.b1 = Blink1()
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
def turn_led_off(): b1 = Blink1() b1.fade_to_color(0, "black") b1.close()
def shutdown(self): b1 = Blink1() b1.off() b1.close()
#!/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")
def blink(colour): b1 = Blink1() b1.play_pattern(colour) b1.close()
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)
# # # 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',
#!/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)
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)
def testCannotFind(self): with mock.patch('blink1.blink1.PRODUCT_ID', '0101'): with self.assertRaises(BlinkConnectionFailed): b1 = Blink1()
#!/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)
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():