示例#1
0
def __alert(color, length=None, fade=0.5):
    try:
        if length:

            msg = termcolor.colored(
                '[blink(1)] flashing {} for {} s'.format(color, length), color
            )
            print(msg, file=sys.stderr)

            cycles = int(length // (2 * fade))

            for i in range(cycles):
                with blink1() as b1:
                    b1.fade_to_color(0, color)
                    time.sleep(fade)
                time.sleep(fade)
        else:
            with blink1() as b1:
                b1.fade_to_color(fade * 1000, color)
                msg = termcolor.colored((
                    '[blink(1)] flashing {}... '.format(color) +
                    'press enter to terminate.'
                ), color)
                print(msg, end=' ')
                input()
    except KeyboardInterrupt:
        with blink1() as b1:
            b1.fade_to_color(0, color)
示例#2
0
def __alert(color, length=None, fade=0.5):
    try:
        if length:

            msg = termcolor.colored(
                '[blink(1)] flashing {} for {} s'.format(color, length), color
            )
            print(msg, file=sys.stderr)

            cycles = int(length // (2 * fade))

            for i in range(cycles):
                with blink1() as b1:
                    b1.fade_to_color(0, color)
                    time.sleep(fade)
                time.sleep(fade)
        else:
            with blink1() as b1:
                b1.fade_to_color(fade * 1000, color)
                msg = termcolor.colored((
                    '[blink(1)] flashing {}... '.format(color) +
                    'press enter to terminate.'
                ), color)
                print(msg, end=' ')
                input()
    except KeyboardInterrupt:
        with blink1() as b1:
            b1.fade_to_color(0, color)
示例#3
0
 def post_run_cell(self, result):
     with blink1(switch_off=False) as b1:
         if result.success:
             # there was no exception
             b1.play(*self.complete_pattern)
         else:
             # something went wrong
             b1.play(*self.error_pattern)
示例#4
0
def alarm(alarm):
    "Plays  the alarm sound specified by alarm"
    #cmd = ["mpg123", alarm]
    #proc = subprocess.Popen(cmd, stdout = DEV_NULL, stderr = subprocess.PIPE)
    #proc.wait()
    with blink1() as b1:
        b1.fade_to_color(100, 'yellow')
        time.sleep(10)
示例#5
0
    def test_range(self):
        """Verify that it is possible to produce the entire color range"""

        for k in range(10, 12000, 400):
            r, g, b = kelvin_to_rgb(k)
            self.assertIsInstance(r, int)
            self.assertIsInstance(g, int)
            self.assertIsInstance(b, int)

            with blink1(white_point=(r, g, b)) as b1:
                b1.fade_to_color(0, "white")
                time.sleep(0.05)
示例#6
0
    def test_range(self):
        """Verify that it is possible to produce the entire color range"""

        for k in range(10, 12000, 400):
            r,g,b = kelvin_to_rgb(k)
            self.assertIsInstance(r, int)
            self.assertIsInstance(g, int)
            self.assertIsInstance(b, int)

            with blink1(white_point=(r,g,b)) as b1:
                b1.fade_to_color(0, 'white')
                time.sleep(0.05)
示例#7
0
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)
                b1.fade_to_color(100, 'black')
                time.sleep(.8)
    except Exception as err:
        print(type(err))
        raise
示例#8
0
def use_blink(color, minutes):
    """
    This function will change the color of the blink(1) device based upon
    where we're at in the pomodoro session.
    :param color: str
    :param minutes: int (or float)
    """
    try:
        with blink1() as b1:
            b1.fade_to_color(1000, color)
            time.sleep(minutes * 60)
    except KeyboardInterrupt:
        control_c(b1)
    except Exception as e:
        no_device_found(e)
示例#9
0
def flash_blink():
    """
    Flash the blink(1) between blue and red.
    """
    try:
        with blink1() as b1:
            b1.fade_to_rgb(.5, 0, 0, 0)
            for i in xrange(5):
                b1.fade_to_color(100, 'blue')
                time.sleep(.1)
                b1.fade_to_color(100, 'red')
                time.sleep(.1)
            b1.fade_to_rgb(.5, 0, 0, 0)
    except KeyboardInterrupt:
        control_c(b1)
    except Exception as e:
        no_device_found(e)
示例#10
0
def run(white_point):
    config = discover()
    downstream_url = config['downstream']

    socket = context.socket(zmq.SUB)
    socket.connect(config['downstream'])
    log.info("Connecting to %s" % downstream_url)

    socket.setsockopt_string(zmq.SUBSCRIBE, DEFAULT_CHANNEL)
    stream = ZMQStream(socket)

    loop = ioloop.IOLoop.instance()

    with blink1(white_point=white_point) as b1:
        reciever = Receiver(b1, loop)
        stream.on_recv(reciever.recieve)

        loop.add_callback(reciever.throbber)

        loop.start()
示例#11
0
def run(white_point):
    config = discover()
    downstream_url = config['downstream']

    socket = context.socket(zmq.SUB)
    socket.connect(config['downstream'])
    log.info("Connecting to %s" % downstream_url)

    socket.setsockopt_string(zmq.SUBSCRIBE, DEFAULT_CHANNEL)
    stream = ZMQStream(socket)

    loop = ioloop.IOLoop.instance()

    with blink1(white_point=white_point) as b1:
        reciever = Receiver(b1, loop)
        stream.on_recv(reciever.recieve)

        loop.add_callback(reciever.throbber)

        loop.start()
示例#12
0
    def __init__(self, ipython):
        self.ipython = ipython

        # send patterns to blink1, and store indices into pattern memory
        self.executing_pattern = (1, 2)
        with blink1(switch_off=False) as b1:
            b1.write_pattern_line(1000, "blue", 1)
            b1.write_pattern_line(1000, "darkblue", 2)

            self.error_pattern = (3, 6)
            # the fades to same color make the led blink - i.e. fades
            # have hard edges
            b1.write_pattern_line(0, "red", 3)
            b1.write_pattern_line(500, "red", 4)
            b1.write_pattern_line(0, "black", 5)
            b1.write_pattern_line(500, "black", 6)

            self.complete_pattern = (7, 7)
            b1.write_pattern_line(100, "green", 7)

        # set up event listeners
        ipython.events.register("pre_run_cell", self.pre_run_cell)
        ipython.events.register("post_run_cell", self.post_run_cell)
        atexit.register(self.shutdown)
示例#13
0
 def test_cm_closed(self):
     with blink1() as b1:
         b1.close()
         b1.fade_to_color(0, "teal")
示例#14
0
 def test_cm_with_gamma(self):
     with blink1(gamma=(.5, .5, .5)) as b1:
         b1.fade_to_color(0, "teal")
示例#15
0
 def test_cm_with_white_point(self):
     with blink1(white_point=COLOR_TEMPERATURES['candle']) as b1:
         b1.fade_to_color(0, "white")
         time.sleep(0.1)
示例#16
0
def blink():
    with blink1() as b1:
        b1.fade_to_color(100, 'navy')
        sleep(5)
    return "Light activated for 5 seconds"
示例#17
0
import time
from blink1.blink1 import blink1

with blink1() as b1:
    b1.fade_to_color(100, 'navy')
    time.sleep(10)
示例#18
0
def shine(color, white_point):
    with blink1(switch_off=False, white_point=white_point) as b1:
        b1.fade_to_color(100, color)
示例#19
0
 def pre_run_cell(self):
     with blink1(switch_off=False) as b1:
         b1.play(*self.executing_pattern)
示例#20
0
 def test_cm_with_white_point(self):
     with blink1(white_point='blue-sky') as b1:
         b1.fade_to_color(0, "white")
         time.sleep(0.1)
示例#21
0
文件: shine.py 项目: DerekK19/blink1
def shine(color, white_point):
    with blink1(switch_off=False, white_point=white_point) as b1:
        b1.fade_to_color(100, color)
示例#22
0
#!/usr/bin/env python
"""
demo_context -- simple context manager demo of blink1 library

"""

import time
from blink1.blink1 import blink1

with blink1() as b1:
    b1.fade_to_color(300, 'goldenrod')
    time.sleep(2)

time.sleep(1)

# notice how blink(1) is turned off and closed
# outside of the 'with' block
# you can override this this 'switch_off' flag

with blink1(switch_off=False) as b1:
    b1.fade_to_color(300, 'pink')
    time.sleep(2)

with blink1() as b1:
    b1.fade_to_color(300, 'aqua')
    time.sleep(2)
示例#23
0
def rest(duration):
    with blink1() as b1:
        b1.fade_to_color(100, 'green')
        time.sleep(duration)
示例#24
0
 def test_cm(self):
     with blink1() as b1:
         b1.fade_to_color(0, "teal")
示例#25
0
 def test_cm_with_white_point(self):
     with blink1(white_point='blue-sky') as b1:
         b1.fade_to_color(0, "white")
         time.sleep(0.1)
示例#26
0
 def test_cm_with_white_point(self):
     with blink1(white_point=(255, 255, 255)) as b1:
         b1.fade_to_color(0, "white")
         time.sleep(0.1)
示例#27
0
 def test_cm_with_gamma(self):
     with blink1(gamma=(.5, .5, .5)) as b1:
         b1.fade_to_color(0, "teal")
示例#28
0
 def test_cm_with_white_point(self):
     with blink1(white_point=COLOR_TEMPERATURES['candle']) as b1:
         b1.fade_to_color(0, "white")
         time.sleep(0.1)
示例#29
0
def shine(color, fade):
    with blink1(switch_off=False) as b1:
        b1.fade_to_color(fade * 1000.0, color)
示例#30
0
 def test_cm(self):
     with blink1() as b1:
         b1.fade_to_color(0, "teal")
示例#31
0
 def quit(self):
     with blink1() as b1:
         b1.fade_to_color(1000, 'black')
         time.sleep(1)
     root.destroy()
示例#32
0
 def test_cm_closed(self):
     with blink1() as b1:
         b1.close()
         b1.fade_to_color(0, "teal")
示例#33
0
文件: shine.py 项目: kazken3/blink1
def shine(color):
    with blink1(False) as b1:
        b1.fade_to_color(100, color)
示例#34
0
 def shutdown(self):
     with blink1(switch_off=False) as b1:
         b1.fade_to_color(0, "black")
         b1.close()
示例#35
0
 def test_cm_with_white_point(self):
     with blink1(white_point=(255, 255, 255)) as b1:
         b1.fade_to_color(0, "white")
         time.sleep(0.1)
示例#36
0
import time
from blink1.blink1 import blink1

with blink1() as b1:
    b1.fade_to_color(100, 'navy')
    time.sleep(10)
示例#37
0
 def set_color(self, color):
     with blink1(switch_off=False) as b1:
         b1.fade_to_color(1000, color)
         time.sleep(1)