def lightsBlinkstick(response):

    if response == "success":
        try:
            # For BlinkStick
            for bstick in blinkstick.find_all():
                bstick.set_color(name="green")
                bstick.pulse(name="blue")
                time.sleep(3)
                bstick.turn_off()
                continue
            # End BlinkStick
        except:
            print('Blinkstick had some sort of error')

    elif response == "error":
        try:
            # For BlinkStick
            for bstick in blinkstick.find_all():
                bstick.set_color(name="red")
                time.sleep(3)
                print("Blinkstick lights command successful")
                bstick.turn_off()
            # End BlinkStick
        except:
            print("blinkstick had some sort of error")
示例#2
0
def update_bstick_nano(bgcolor, fgcolor, mode):
    # This function drives the BlinkStick Nano (two LEDs, one on each side)
    if mode == 'normal':
        try:
            for bstick in blinkstick.find_all():
                bstick.set_color(channel=0, index=1, name=bgcolor)
            time.sleep(0.1)
            bstickStatus = bgcolor
        except Exception as e:
            print('[ERROR] Failed to update Blinkstick color.\n', e)
            bstickStatus = 'unknown'
            traceback.print_exc()
            pass
    elif mode == 'flash':
        # print("BStick is in Flash mode")
        try:
            for bstick in blinkstick.find_all():
                bstick.set_color(channel=0, index=1, name=bgcolor)
                bstick.blink(channel=0, index=0, name=fgcolor, repeats=1, delay=500)
            time.sleep(0.1)
            bstickStatus = bgcolor
        except Exception as e:
            print('[ERROR] Failed to update Blinkstick color.\n', e)
            bstickStatus = 'unknown'
            traceback.print_exc()
            pass

    return bstickStatus
def change_led_color(colors):
    if blinkstick.find_all() > 0:
        print 'Changing colors to: ', colors[0:3]
        for ledstrip in blinkstick.find_all():
            for x in range(0, 32):
                ledstrip.set_color(0, x, int(colors[0]), int(colors[1]),
                                   int(colors[2]))
        return 'ok'
示例#4
0
 def detect(self, req):
     try:
         data = rospy.wait_for_message('/camera/rgb/image_color', Image,
                                       10.0)
         imgO = self.bridge.imgmsg_to_cv2(data, "bgr8")
     except CvBridgeError as er:
         print(er)
         result = PoiDetectResponse()
         result.detected = False
         result.color = 'Error'
         return result
     imgC = cv2.cvtColor(imgO, cv2.COLOR_BGR2RGB)
     # bild optimierungen
     imgC = cv2.erode(imgC, None, iterations=2)
     imgC = cv2.dilate(imgC, None, iterations=2)
     # red green maskierungen
     maskRed = cv2.inRange(imgC, self.redLow, self.redHigh)
     maskGreen = cv2.inRange(imgC, self.greenLow, self.greenHigh)
     # Konturen finden
     cntsGreen = cv2.findContours(maskGreen, cv2.RETR_EXTERNAL,
                                  cv2.CHAIN_APPROX_SIMPLE)[-2]
     cntsRed = cv2.findContours(maskRed, cv2.RETR_EXTERNAL,
                                cv2.CHAIN_APPROX_SIMPLE)[-2]
     detectedColor = "None"
     if len(cntsGreen) > 0:
         # die groeste kontur finden
         c = max(cntsGreen, key=cv2.contourArea)
         ((x, y), radius) = cv2.minEnclosingCircle(c)
         if radius > 70 and radius < 150:
             detectedColor = "Green"
             for bs in blinkstick.find_all():
                 bs.set_color(name='green')
     if len(cntsRed) > 0:
         c = max(cntsRed, key=cv2.contourArea)
         ((x, y), radius) = cv2.minEnclosingCircle(c)
         if radius > 70 and radius < 150:
             detectedColor = "Red"
             for bs in blinkstick.find_all():
                 bs.set_color(name='red')
     # wenn was erkannt wurde, merken
     if detectedColor != "None":
         posdata = self.mapServicePos()
         pi = PoiInfo()
         pi.position = posdata.position
         pi.color = detectedColor
         self.detections.append(pi)
     else:
         for bs in blinkstick.find_all():
             bs.turn_off()
     result = PoiDetectResponse()
     result.detected = detectedColor != "None"
     result.color = detectedColor
     print result
     return result
示例#5
0
def bstick_control(bgcolor, fgcolor, dot):
    try:
        # Setting background color first
        for bstick in blinkstick.find_all():
            for currentLED in range (0,32):
                bstick.set_color(channel=0, index=currentLED, name=bgcolor)
        # Then taking care of the foreground (one single dot)
        for bstick in blinkstick.find_all():
            bstick.set_color(channel=0, index=dot, name=fgcolor)
        bstickStatus = bgcolor
    except Exception as e:
        print("[ERROR] Failed to update Blinkstick color.\n", e)
        bstickStatus = "unknown"
    return bstickStatus
示例#6
0
def bstick_control(bgcolor, fgcolor, dot):
    # This function drives the BlinkStick Flex (32 LEDs)
    try:
        # Setting background color first
        for bstick in blinkstick.find_all():
            for currentLED in range (0,32):
                bstick.set_color(channel=0, index=currentLED, name=bgcolor)
        # Then taking care of the foreground (one single dot)
        for bstick in blinkstick.find_all():
            bstick.set_color(channel=0, index=dot, name=fgcolor)
        bstickStatus = bgcolor
    except Exception as e:
        print('[ERROR] Failed to update Blinkstick color.\n', e)
        bstickStatus = 'unknown'
        traceback.print_exc()
    return bstickStatus
示例#7
0
def turn_off(_, __):
    sticks = blinkstick.find_all()
    for stick in sticks:
        stick.set_led_data(0, [0, 0, 0] * stick.get_led_count())

    print("\nLater skater :)")
    exit(0)
示例#8
0
文件: blink.py 项目: wbajzek/blink
def main():
  global sticks
  global done


  sticks = blinkstick.find_all()
  # assume the first stick. change this if you want; I only have one.
  stick = sticks[0]

  command = sys.argv
  command.pop(0)
  command = ' '.join(command)

  try:
    done = False
    pulse = threading.Thread(target=heartbeat, args=(stick,))
    pulse.start()
    status = os.system(command)
    done = True
    if status == 0:
      stick.set_color(0,127,0)
    else:
      stick.set_color(127,0,0)
    print "Press enter to finish"
    raw_input()
    stick.set_color(0,0,0)

  except Exception as e:
    print e
    print "Unable to run heartbeat"

  return 0
示例#9
0
def turn_off():
    for led in blinkstick.find_all():
        try:
            led.turn_off()
        except Exception:
            print "Failed to communicate with led"

    return "Turend off"
示例#10
0
def blink_random():
    try:
        for led in blinkstick.find_all():
            time.sleep(0.020)
            led.set_random_color()
    except Exception as e:
        return jsonify(status="error", message=str(e))
    else:
        return blink_info()
示例#11
0
def update_bstick_color(bstickColor):
    try:
        for bstick in blinkstick.find_all():
            for currentLED in range (0,32):
                bstick.set_color(channel=0, index=currentLED, name=bstickColor)
                time.sleep(0.1)
        bstickStatus = bstickColor
        print("bstickStatus=" + bstickStatus)
    except Exception as e:
        print("[ERROR] Failed to update Blinkstick color.\n", e)
示例#12
0
    def scan():
        """
        returns (list of 2-tuple): name, kwargs
        Note: it's obviously not advised to call this function if a device is already under use
        """
        logging.info("Looking for blinksticks...")
        found = []  # (list of 2-tuple): name, kwargs
        for d in blinkstick.find_all():
            found.append(("Blinkstick led", {"sn": d.device.serial_number}))

        return found
示例#13
0
    def scan():
        """
        returns (list of 2-tuple): name, kwargs
        Note: it's obviously not advised to call this function if a device is already under use
        """
        logging.info("Looking for blinksticks...")
        found = []  # (list of 2-tuple): name, kwargs
        for d in blinkstick.find_all():
            found.append(("Blinkstick led", {"sn": d.device.serial_number}))

        return found
示例#14
0
def blink_blink():
    turn_off()
    leds = blinkstick.find_all()
    time.sleep(0.200)
    try:
        while blinkstick.find_all():
            try:
                leds[0].blink(name="red", delay=100, repeats=1)
                time.sleep(0.020)

                leds[1].blink(name="red", delay=100, repeats=1)
                time.sleep(0.020)

            except Exception as e:
                print str(e)

    except Exception as e:
        return jsonify(status="error", message=str(e))
    else:
        return jsonify(status="success",
                       message="all led's could be activated")
示例#15
0
def blink_info():
    serial_list, color_list = [], []

    for led in blinkstick.find_all():
        serial_list.append(led.get_serial())
        color_list.append(led.get_color(color_format="hex"))

    serial_colors = [{
        "serial": s,
        "color": c
    } for s, c in zip(serial_list, color_list)]

    return json.dumps(serial_colors)
示例#16
0
def update_bstick_color(bstickColor):
    # This function drives the BlinkStick Flex (32 LEDs)
    try:
        for bstick in blinkstick.find_all():
            for currentLED in range (0,32):
                bstick.set_color(channel=0, index=currentLED, name=bstickColor)
                time.sleep(0.1)
        bstickStatus = bstickColor
    except Exception as e:
        print('[ERROR] Failed to update Blinkstick color.\n', e)
        bstickStatus = 'unknown'
        traceback.print_exc()
        pass
    return bstickStatus
示例#17
0
def main():
    global colour_hex
    colour_hex = RED_HEX
    if sys.argv[1] == 'random':
        colour_hex = get_random_colour()
    else:
        if check_hex_arg(sys.argv[1]):
            colour_hex = sys.argv[1]
        else:
            raise ValueError('not valid colour hex, try again')

    for bstick in blinkstick.find_all():
        for i in range(8):
            bstick.set_color(index=i, hex=colour_hex)
            print bstick.get_serial() + " " + bstick.get_color(
                color_format="hex")
示例#18
0
    def attractMode(self):
 
        for b in blinkstick.find_all():
            if (self.attractModeState == 0):
                b.turn_off()
            elif (self.attractModeState == 1):
                b.set_color(0,0,255,0,0)
            elif (self.attractModeState == 2):
                b.turn_off()
            elif (self.attractModeState == 4):
                b.set_color(0,0,0,0,255)
            elif (self.attractModeState == 5):
                b.turn_off()

        self.attractModeState +=1;
        if (self.attractModeState == 6):
            self.attractModeState = 0
           
        self.root.after(100,self.attractMode);
示例#19
0
    def get_blinksticks(self):
        found_blinksticks = []
        led_counts = []
        blinksticks = blinkstick.find_all()  # Discover multiple Blinksticks.
        for stick in blinksticks:
            count = stick.get_led_count()
            led_counts.append(count)
            found_blinksticks.append(stick)

        # Verify we're addressing the same number of LEDs for both sticks.
        led_count = set(led_counts)  # Set will deduplicate.
        if len(led_count
               ) == 1:  # Should be left with one, if everything is equal.
            for count in led_count:
                self.led_count = int(count)
        else:
            print(
                'ERROR - LED Count is NOT equal between Blinksticks: {} - Values should match.'
                .format(led_count))
            sys.exit(1)
        return (found_blinksticks)
示例#20
0
def update_blinkstick(blinkstick_color, blinkstick_darkness_ratio):
    try:
        for stick in blinkstick.find_all():

            blink_red = int(blinkstick_color[0]) - (100 - blinkstick_darkness_ratio)
            blink_green = int(blinkstick_color[1]) - (100 - blinkstick_darkness_ratio)
            blink_blue = int(blinkstick_color[2]) - (100 - blinkstick_darkness_ratio)

            if blink_blue < 0:
                blink_blue = 0

            if blink_red < 0:
                blink_red = 0

            if blink_green < 0:
                blink_green = 0

            for x in range(7):
                stick.set_color(channel=0, red=blink_red, green=blink_green, blue=blink_blue, index=x)
    except:
        pass
示例#21
0
def set_blinkstick(vars):
    from blinkstick import blinkstick
    while True:
        for bs in blinkstick.find_all():
            if vars.status_initial or vars.status_error or vars.status_connected:
                if status_initial:
                    try:
                        bs.blink(name="Yellow", repeats=3, delay=1000)
                    except:
                        bs.turn_off()
                if vars.status_error:
                    try:
                        bs.blink(name="Red", repeats=3, delay=1000)
                    except:
                        bs.turn_off()
                if vars.status_connected:
                    try:
                        bs.blink(name="Blue", repeats=3, delay=1000)
                    except:
                        bs.turn_off()
            else:
                bs.set_color(name="Green")
def main():
    global sticks

    print "BlinkStick MQTT script"
    print ""

    sticks = blinkstick.find_all()
    if len(sticks) == 0:
        print "BlinkStick not found..."
        return 64

    mqttc = mosquitto.Mosquitto()
    mqttc.on_message = on_message
    mqttc.on_connect = on_connect
    mqttc.on_publish = on_publish
    mqttc.on_subscribe = on_subscribe
    mqttc.connect("test.mosquitto.org", 1883, 60)
    mqttc.subscribe("cheerlights", 0)

    rc = 0
    while rc == 0:
        rc = mqttc.loop()

    return 0
示例#23
0
from blinkstick import blinkstick

for bstick in blinkstick.find_all():
    print('Serial: {}'.format(bstick.get_serial()))
示例#24
0
 def light_yellow(self):
     bstick = blinkstick.find_first()
     for bstick in blinkstick.find_all():
         for x in range(1, 60):
             bstick.set_color(channel=0, index=x, name="yellow")
def main_blinkstick_util():
    global options
    global sticks

    parser = OptionParser(usage="usage: %prog [options] [color]",
                          formatter=IndentedHelpFormatterWithNL())

    parser.add_option("-i",
                      "--info",
                      action="store_true",
                      dest="info",
                      help="Display BlinkStick info")

    parser.add_option(
        "-s",
        "--serial",
        dest="serial",
        help=
        "Select device by serial number. If unspecified, action will be performed on all BlinkSticks."
    )

    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      help="Display debug output")

    group = OptionGroup(parser, "Change color",
                        "These options control the color of the device  ")

    group.add_option("--channel",
                     default=0,
                     dest="channel",
                     help="Select channel. Applies only to BlinkStick Pro.")

    group.add_option("--index",
                     default=0,
                     dest="index",
                     help="Select index. Applies only to BlinkStick Pro.")

    group.add_option("--brightness",
                     default=100,
                     dest="limit",
                     help="Limit the brightness of the color 0..100")

    group.add_option("--limit",
                     default=100,
                     dest="limit",
                     help="Alias to --brightness option")

    group.add_option(
        "--set-color",
        dest="color",
        help=
        "Set the color for the device. This can also be the last argument for the script. "
        "The value can either be a named color, hex value, 'random' or 'off'.\n\n"
        "CSS color names are defined http://www.w3.org/TR/css3-color/ e.g. red, green, blue. "
        "Specify color using hexadecimal color value e.g. 'FF3366'")
    group.add_option("--inverse",
                     action="store_true",
                     dest="inverse",
                     help="Control BlinkSticks in inverse mode")

    group.add_option(
        "--set-led-count",
        dest="led_count",
        help="Set the number of LEDs to control for supported devices.")

    parser.add_option_group(group)

    group = OptionGroup(
        parser, "Control animations",
        "These options will blink, morph or pulse selected color.  ")

    group.add_option(
        "--blink",
        dest="blink",
        action='store_true',
        help=
        "Blink LED (requires --set-color or color set as last argument, and optionally --delay)"
    )

    group.add_option(
        "--pulse",
        dest="pulse",
        action='store_true',
        help=
        "Pulse LED (requires --set-color or color set as last argument, and optionally --duration)."
    )

    group.add_option(
        "--morph",
        dest="morph",
        action='store_true',
        help=
        "Morph to specified color (requires --set-color or color set as last argument, and optionally --duration)."
    )

    group.add_option(
        "--duration",
        dest="duration",
        default=1000,
        help=
        "Set duration of transition in milliseconds (use with --morph and --pulse)."
    )

    group.add_option(
        "--delay",
        dest="delay",
        default=500,
        help="Set time in milliseconds to light LED for (use with --blink).")

    group.add_option(
        "--repeats",
        dest="repeats",
        default=1,
        help="Number of repetitions (use with --blink and --pulse).")

    parser.add_option_group(group)

    group = OptionGroup(
        parser, "Device data and behaviour",
        "These options will change device mode and data stored internally.  ")

    group.add_option(
        "--set-mode",
        default=0,
        dest="mode",
        help=
        "Set mode for BlinkStick Pro:\n\n    0 - default\n\n    1 - inverse\n\n    2 - ws2812\n\n    3 - ws2812 mirror"
    )

    group.add_option("--set-infoblock1",
                     dest="infoblock1",
                     help="Set the first info block for the device.")

    group.add_option("--set-infoblock2",
                     dest="infoblock2",
                     help="Set the second info block for the device.")

    parser.add_option_group(group)

    group = OptionGroup(parser, "Advanced options", "")

    group.add_option(
        "--add-udev-rule",
        action="store_true",
        dest="udev",
        help=
        "Add udev rule to access BlinkSticks without root permissions. Must be run as root."
    )

    parser.add_option_group(group)

    (options, args) = parser.parse_args()

    if options.serial is None:
        sticks = blinkstick.find_all()
    else:
        sticks = [blinkstick.find_by_serial(options.serial)]

        if len(sticks) == 0:
            print("BlinkStick with serial number " + options.device +
                  " not found...")
            return 64

    #Global action
    if options.udev:

        try:
            filename = "/etc/udev/rules.d/85-blinkstick.rules"
            file = open(filename, 'w')
            file.write(
                'SUBSYSTEM=="usb", ATTR{idVendor}=="20a0", ATTR{idProduct}=="41e5", MODE:="0666"'
            )
            file.close()

            print("Rule added to {0}").format(filename)
        except IOError as e:
            print(str(e))
            print(
                "Make sure you run this script as root: sudo blinkstick --add-udev-rule"
            )
            return 64

        print("Reboot your computer for changes to take effect")
        return 0

    for stick in sticks:
        if options.inverse:
            stick.set_inverse(True)

        stick.set_max_rgb_value(int(float(options.limit) / 100.0 * 255))

        stick.set_error_reporting(False)

    #Actions here work on all BlinkSticks
    for stick in sticks:
        if options.infoblock1:
            stick.set_info_block1(options.infoblock1)

        if options.infoblock2:
            stick.set_info_block2(options.infoblock2)

        if options.mode:
            if options.mode == "0" or options.mode == "1" or options.mode == "2" or options.mode == "3":
                stick.set_mode(int(options.mode))
            else:
                print("Error: Invalid mode parameter value")

        elif options.led_count:
            led_count = int(options.led_count)

            if led_count > 0 and led_count <= 32:
                stick.set_led_count(led_count)
            else:
                print("Error: Invalid led-count parameter value")

        elif options.info:
            print_info(stick)
        elif options.color or len(args) > 0:
            if options.color:
                color = options.color
            else:
                color = args[0]

            # determine color
            fargs = {}
            if color.startswith('#'):
                fargs['hex'] = color
            elif color == "random":
                fargs['name'] = 'random'
            elif color == "off":
                fargs['hex'] = "#000000"
            else:
                if len(color) == 6:
                    # If color contains 6 chars check if it's hex
                    try:
                        int(color, 16)
                        fargs['hex'] = "#" + color
                    except:
                        fargs['name'] = color
                else:
                    fargs['name'] = color

            fargs['index'] = int(options.index)
            fargs['channel'] = int(options.channel)

            # handle blink/pulse/morph
            func = stick.set_color
            if options.blink:
                func = stick.blink
                fargs['delay'] = options.delay
                fargs['repeats'] = int(options.repeats)
            elif options.pulse:
                func = stick.pulse
                fargs['duration'] = options.duration
                fargs['repeats'] = int(options.repeats)
            elif options.morph:
                func = stick.morph
                fargs['duration'] = options.duration

            func(**fargs)

        else:
            parser.print_help()
            return 0

    return 0
示例#26
0
def blinkoff():
    for bstick in blinkstick.find_all():
             bstick.turn_off()
    print('status: blinkstick off')    
    return redirect("/")
示例#27
0
def blinkon():
    for bstick in blinkstick.find_all():
    		bstick.set_random_color()
    print('status: blinkstick on')
    return redirect("/")
# Read values from access.txt to use with accessing Twitter stream
access = dict()
with open('access.txt', 'r') as fp:
    for line in fp:
        y = line.split('=')
        access[y[0].strip()] = y[1].strip()

API_KEY = access['consumer_key']
API_KEY_SECRET = access['consumer_key_secret']
ACCESS_TOKEN = access['access_token']
ACCESS_TOKEN_SECRET = access['access_token_secret']

HASHTAG = '#' + access['hashtag']

bsticks = blinkstick.find_all()


class MyStreamListener(tweepy.StreamListener):
    def on_status(
            self,
            status):  # When a status has been posted with certain keywords
        print status.text

        str = status.text  # The text from the tweet

        index_of_hashtag = str.find(
            HASHTAG)  # finding the index of the hashtag

        str = str[index_of_hashtag:len(
            str
示例#29
0
def blinkpreset():
    for bstick in blinkstick.find_all():
                 bstick.set_color(name=request.form['color'])
    print('status: blinkstick color - ' + request.form['color'])   
    return redirect("/")
示例#30
0
def turn_off():
    sticks = blinkstick.find_all()
    for stick in sticks:
        stick.set_led_data(0, [0, 0, 0] * stick.get_led_count())
示例#31
0
def main():
    global options
    global sticks

    parser = OptionParser(
        formatter=IndentedHelpFormatterWithNL()
    )

    parser.add_option("-i", "--info",
                      action="store_true", dest="info",
                      help="display BlinkStick info")

    parser.add_option("-s", "--serial",
                      dest="serial",
                      help="select device by serial number. If unspecified, action will be performed on all BlinkSticks.")

    parser.add_option("--inverse",
                      action="store_true", dest="inverse",
                      help="control BlinkSticks in inverse mode")

    parser.add_option("--channel",
                      default=0, dest="channel",
                      help="Select channel")

    parser.add_option("--index",
                      default=0, dest="index",
                      help="Select index")

    parser.add_option("--set-color",
                      dest="color",
                      help="set the color for the device. The value can either be a named color, hex value, 'random' or 'off'.\n\n"
                           "CSS color names are defined http://www.w3.org/TR/css3-color/ e.g. red, green, blue."
                           "Specify color using hexadecimal color value e.g. '#FF3366'")

    parser.add_option("--duration",
                      dest="duration",
                      default=1000,
                      help="Set duration of transition in milliseconds (use with --morph and --pulse).")

    parser.add_option("--delay",
                      dest="delay",
                      default=500,
                      help="Set time in milliseconds to light LED for (use with --blink).")

    parser.add_option("--repeats",
                      dest="repeats",
                      default=1,
                      help="Number of repetitions (use with --blink and --pulse).")

    parser.add_option("--blink",
                      dest="blink",
                      action='store_true',
                      help="Blink LED (requires --set-color, and optionally --delay)")

    parser.add_option("--pulse",
                      dest="pulse",
                      action='store_true',
                      help="Pulse LED (requires --set-color, and optionally --duration).")

    parser.add_option("--morph",
                      dest="morph",
                      action='store_true',
                      help="Morph to specified color (requires --set-color, and optionally --duration).")

    parser.add_option("--set-infoblock1",
                      dest="infoblock1",
                      help="set the first info block for the device.")

    parser.add_option("--set-infoblock2",
                      dest="infoblock2",
                      help="set the second info block for the device.")

    if sys.platform != "win32":
        parser.add_option("--cpu-usage",
                          dest="cpu_usage", action="store_true",
                          help="Use BlinkStick to display CPU usage.")

    parser.add_option("--connect",
                      dest="access_code",
                      help="Connect to blinkstick.com and control the device remotely.")

    parser.add_option("-v", "--verbose",
                      action="store_true", dest="verbose",
                      help="Display debug output")

    parser.add_option("--add-udev-rule",
                      action="store_true", dest="udev",
                      help="Add udev rule to access BlinkSticks without root permissions. Must be run as root.")

    (options, args) = parser.parse_args()

    print("BlinkStick control script {0}".format(blinkstick.get_blinkstick_package_version()))
    print("(c) Agile Innovative Ltd 2013")
    print("")

    if options.serial is None:
        sticks = blinkstick.find_all()
    else:
        sticks = [blinkstick.find_by_serial(options.serial)]

        if len(sticks) == 0:
            print("BlinkStick with serial number " + options.device + " not found...")
            return 64

    #Global action
    if options.udev:

        try:
            filename = "/etc/udev/rules.d/85-blinkstick.rules"
            file = open(filename, 'w')
            file.write('SUBSYSTEM=="usb", ATTR{idVendor}=="20a0", ATTR{idProduct}=="41e5", MODE:="0666"')
            file.close()

            print("Rule added to {0}").format(filename)
        except IOError as e:
            print(str(e))
            print("Make sure you run this script as root: sudo blinkstick --add-udev-rule")
            return 64

        print("Reboot your computer for changes to take effect")
        return 0

    for stick in sticks:
        if options.inverse:
            stick.set_inverse(True)

    #Actions here work only on the first BlinkStick found
    if sys.platform != "win32" and options.cpu_usage:
        show_cpu_usage(sticks[0])
    elif options.access_code:
        while True:
            connect()
            print("Attempting to reconnect in 15s")
            time.sleep(15)

    #Actions here work on all BlinkSticks
    for stick in sticks:
        if options.infoblock1:
            stick.set_info_block1(options.infoblock1)

        if options.infoblock2:
            stick.set_info_block2(options.infoblock2)

        if options.info:
            print_info(stick)
        elif options.color:
            # determine color
            args = {}
            if options.color.startswith('#'):
                args['hex'] = options.color
            elif options.color == "random":
                args['name'] = 'random'
            elif options.color == "off":
                args['hex'] = "#000000"
            else:
                args['name'] = options.color

            args['index'] = options.index
            args['channel'] = options.channel

            # handle blink/pulse/morph
            func = stick.set_color
            if options.blink:
                func = stick.blink
                args['delay'] = options.delay
                args['repeats'] = int(options.repeats)
            elif options.pulse:
                func = stick.pulse
                args['duration'] = options.duration
                args['repeats'] = int(options.repeats)
            elif options.morph:
                func = stick.morph
                args['duration'] = options.duration

            func(**args)


        else:
            parser.print_help()

    return 0
示例#32
0
def blinkcustom():
    var1 = "#" + request.form['color']
    for bstick in blinkstick.find_all():
                 bstick.set_color(hex=var1)
    print(var1)  
    return redirect("/")
示例#33
0
from blinkstick import blinkstick
from time import sleep

for bstick in blinkstick.find_all():
    try:
        while True:
           for x in xrange(0, 8):
            #trail
            bstick.set_color(channel =3, index = (x-1)%8, name="blue")
            bstick.set_color(channel =3, index = (x-2)%8, name="blue")
            bstick.set_color(channel =3, index = (x-3)%8, name="blue")
            bstick.set_color(channel =3, index = (x-4)%8, name="blue")
            #clear previous last light 
            bstick.set_color(channel =3, index = (x-5)%8)
            #head
            bstick.set_color(channel =3, index = x, name="green")
            sleep(0.1)
    except KeyboardInterrupt:
        pass
示例#34
0
from blinkstick import blinkstick

all_blink_sticks = blinkstick.find_all()

if len(all_blink_sticks) > 0:
    for bstick in all_blink_sticks:
        bstick.morph(hex='#00ff00', duration=1000)
else:
    print("No BlinkSticks found...")
示例#35
0
        'N': '-.', 
        'O': '---', 
        'P': '.--.', 
        'Q': '--.-', 
        'R': '.-.', 
        'S': '...', 
        'T': '-', 
        'U': '..-', 
        'V': '...-', 
        'W': '.--', 
        'X': '-..-', 
        'Y': '-.--', 
        'Z': '--..', 
        '_': '..--.-'}

sticks = blinkstick.find_all()
if len(sticks) == 0:
        print "No blinkstick found."
        sys.exit()

# We work with the first blinkstick
bstick = sticks[0]

words = iter(sys.argv)
next(words)
for word in words:
        for letter in str(word):
                sys.stdout.write(letter)
                sys.stdout.write(': ')
                for symbol in CODE[letter.upper()]:
                        if symbol == "-":
示例#36
0
def update_local_bstick_nano(tR, tG, tB, bR, bG, bB, topMode, bottomMode,
                             enableLocalBStick):
    # This function drives the local BlinkStick Nano (two LEDs, one on each side)
    if enableLocalBStick == '1':
        try:
            if topMode == 'on':
                for bstick in blinkstick.find_all():
                    bstick.set_color(channel=0,
                                     index=0,
                                     red=int(tR),
                                     green=int(tG),
                                     blue=int(tB))
                time.sleep(0.1)
                bstickStatus = topMode
            elif topMode == 'flash':
                for bstick in blinkstick.find_all():
                    bstick.blink(channel=0,
                                 index=0,
                                 red=int(tR),
                                 green=int(tG),
                                 blue=int(tB),
                                 repeats=1,
                                 delay=500)
                time.sleep(0.1)
                bstickStatus = topMode
            elif topMode == 'off':
                for bstick in blinkstick.find_all():
                    bstick.set_color(channel=0,
                                     index=0,
                                     red=0,
                                     green=0,
                                     blue=0)
            if bottomMode == 'on':
                for bstick in blinkstick.find_all():
                    bstick.set_color(channel=0,
                                     index=1,
                                     red=int(bR),
                                     green=int(bG),
                                     blue=int(bB))
                time.sleep(0.1)
                bstickStatus = topMode
            elif bottomMode == 'flash':
                for bstick in blinkstick.find_all():
                    bstick.blink(channel=0,
                                 index=1,
                                 red=int(bR),
                                 green=int(bG),
                                 blue=int(bB),
                                 repeats=1,
                                 delay=500)
                time.sleep(0.1)
                bstickStatus = topMode
            elif bottomMode == 'off':
                bstick.set_color(channel=0, index=1, red=0, green=0, blue=0)
        except Exception as e:
            print('[ERROR] Failed to update local Blinkstick color.\n', e)
            bstickStatus = 'unknown'
            traceback.print_exc()
            pass
    else:
        bstickStatus = 'disabled'
        for bstick in blinkstick.find_all():
            bstick.turn_off()
    return bstickStatus