예제 #1
0
def _update_light(light: Light, midi_message: MidiMessage):
    # TODO: Probably need to fiddle with these and see what happens. They could become parameters.
    MIN_BRIGHTNESS = 500  # 0 - 65535
    BRIGHTNESS_INCREASE_SPEED = 100  # 0-?
    BRIGHTNESS_DROP_SPEED = 200  # 0-? in ms, so 1000 is 1s

    velocity = midi_message.getVelocity()
    mapped_velocity = _map_value_to_range(value=velocity,
                                          from_min=MIDI_VALUE_MIN,
                                          from_max=MIDI_VALUE_MAX,
                                          to_min=LIFX_VALUE_MIN,
                                          to_max=LIFX_VALUE_MAX)

    ########
    # TODO: We should try some different stuff here, but I'm making something up that I think will be interesting?
    ########

    # Set the color to w/e the velocity is. This could be really erratic, so maybe add duration
    # which transitions to the given color over the # of ms. Just not sure if it blocks execution.
    light.set_hue(hue=mapped_velocity, rapid=True)

    # Push the brightness up by some function of the velocity. Will need to mess with this.
    def _new_brightness(current_brightness: int):
        return current_brightness + BRIGHTNESS_INCREASE_SPEED

    light.set_brightness(brightness=_new_brightness(current_brightness=light.get_color()[2]), rapid=True)

    # Then start to lower the brightness to some min level slowly
    light.set_brightness(brightness=MIN_BRIGHTNESS, duration=BRIGHTNESS_DROP_SPEED, rapid=True)
예제 #2
0
 def apply(self, device_profile):
     duration = device_profile['duration']  #milliseconds
     dev = Light(device_profile['mac'], device_profile['ip'])
     dev.set_power(device_profile['power'], duration)  #range [0,65535]
     dev.set_hue(device_profile['hue'], duration)  #range [0-65535]
     dev.set_saturation(device_profile['saturation'],
                        duration)  #range [0-65535]
     dev.set_brightness(device_profile['brightness'],
                        duration)  #range [0-65535]
     dev.set_colortemp(device_profile['temperature'],
                       duration)  #range [2500-9000]
예제 #3
0
class Bulb(object):
    def __init__(self, ip, mac, multizone=False):
        self.rapid = False
        if multizone:
            self.bulb = MultiZoneLight(mac, ip)
        else:
            self.bulb = Light(mac, ip)

    def supports_multizone(self):
        return self.bulb.supports_multizone()

    def get_color_zones(self):
        return self.bulb.get_color_zones()

    def set_zone_color(self, startZone, endZone, color, duration=5):
        return self.bulb.set_zone_color(startZone,
                                        endZone,
                                        color,
                                        duration=duration,
                                        rapid=self.rapid)

    def set_zone_colors(self, colors, duration=5):
        return self.bulb.set_zone_colors(colors,
                                         duration=duration,
                                         rapid=self.rapid)

    def set_power(self, power, duration=5):
        if duration:
            self.bulb.set_power(power, duration=duration, rapid=self.rapid)
        else:
            self.bulb.set_power(power)

    def get_power(self):
        return self.bulb.get_power()

    def set_color(self, color, duration=5):
        if duration:
            self.bulb.set_color(color, duration=duration, rapid=self.rapid)
        else:
            self.bulb.set_color(color)

    def get_color(self):
        return self.bulb.get_color()

    def get_label(self):
        return self.bulb.get_label()

    def get_brightness(self):
        return self.bulb.get_color()[2]

    def set_brightness(self, brightness, duration=5):
        return self.bulb.set_brightness(brightness, duration, rapid=self.rapid)

    def fast_mode(self, hostIP=None):
        self.rapid = True

    def slow_mode(self):
        self.rapid = False
예제 #4
0
    avg = sum(amplitudes) / len(amplitudes)
    avg = avg * avg * avg
    if max < avg:
        max = avg
    else:
        max = 0.99 * max
    serout = int(avg / max * 69390)
    if serout > 65535:
        serout = 65535
    elif serout < 20000:
        serout = 20000
    # s.write(chr(serout))
    if count % 1 == 0:
        print(serout)
        try:
            bulb.set_brightness(serout, rapid=True)
        except:
            pass
    # frames.append(data)
print "finished recording"

# stop Recording
stream.stop_stream()
stream.close()
audio.terminate()

# plt.plot(amplitudes)
# plt.show()

waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
waveFile.setnchannels(CHANNELS)
예제 #5
0
            # Control brightness using Stack
            if greenCArea > 6480 or greenCCount > 1:
                brightness_Deque.append(
                    scaleValue(greenCArea, 0, 100, 0, 25000))
                current_brightness = max(brightness_Deque)
                if current_brightness > 100:
                    current_brightness = 100
                elif current_brightness < 0:
                    current_brightness = 0
                brightness = current_brightness
                if math.fabs(current_brightness - prev_brightness) > 2:
                    prev_brightness = current_brightness
                    current_brightness = scaleValue(current_brightness, 0,
                                                    65535, 0, 100)
                    light.set_brightness(current_brightness, rapid=True)

            # Control brightness using Slider
            elif greenCArea < 7100 or (0 < greenCCount < 1):
                brightness_Deque.append(
                    scaleValue(greenCenter[1], 0, 100, 256, 768))
                current_brightness = max(brightness_Deque)
                if current_brightness > 100:
                    current_brightness = 100
                elif current_brightness < 0:
                    current_brightness = 0
                brightness = current_brightness
                if math.fabs(current_brightness - prev_brightness) > 2:
                    prev_brightness = current_brightness
                    current_brightness = scaleValue(current_brightness, 0,
                                                    65535, 0, 100)
예제 #6
0
try:
    print("Starting LiPiSwitch for the light named", lightname, "...")
    print("")
    print("lifXbutton Ready ...")
    print("")

    # Loop until user quits with CTRL-C
    while True:

        # If the Button is triggered
        if button.is_pressed and previousstate == 0:
            print("Button Pressed - Turning Light ON")

            # LifxLAN light details
            r = lifxlan.set_power("on")
            h = lifxlan.set_brightness(
                "65535")  #Set the light to full brightness
            g = lifxlan.set_color(WHITE)  #Set the light to daylight

            # Record new previous state
            previousstate = 65535

            #Wait 3 seconds before looping again
            print("Waiting 3 seconds")
            time.sleep(3)
            print("")
            print("Ready")
            print("")

        elif button.is_held:
            print("Button Held - Dimming Light")