Ejemplo n.º 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)
Ejemplo n.º 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]
Ejemplo n.º 3
0
                hue_angle = int(
                    math.atan2(greenCenter[1] -
                               yellowCenter[1], greenCenter[0] -
                               yellowCenter[0]) * -180 / math.pi + 180)
                prev_hue_angle = max(
                    hue_angleDeque) if hue_angleDeque.__len__() > 0 else 0
                hue_angleDeque.append(hue_angle)
                current_hue_angle = max(hue_angleDeque)

                if math.fabs(current_hue_angle - prev_hue_angle) > 1:
                    light_color = light.get_color()
                    hue_value = scaleValue(current_hue_angle, 0, 65535, 0, 359)
                    new_light_color = (hue_value, light_color[1],
                                       light_color[2], light_color[3])
                    light.set_hue(hue_value, rapid=True)
                    light.set_color(new_light_color, rapid=True)

                cv2.putText(
                    image, 'Hue: {}'.format(max(hue_angleDeque)),
                    (int(yellowCenter[0] - 40), int(yellowCenter[1] + 80)),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)

    except Exception as inst:
        # if inst.__str__().index("greenCenter") < 0 or inst.__str__().index("yellowCenter") < 0: print(inst)
        print(inst)

    cv2.imshow("Window - Main", image)
    key = cv2.waitKey(1) & 0xFF
    # if the 'q' key is pressed, stop the loop
    if key == ord("q"):