Пример #1
0
def __init__():
    sdk = CueSdk()
    sdk.connect()

    print(sdk.protocol_details)
    print(sdk.get_devices())

    sdk.set_led_colors_flush_buffer()
Пример #2
0
def main():
    sdk = CueSdk()
    connected = sdk.connect()
    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: %s" % err)
        return

    subscribed = sdk.subscribe_for_events(SdkEventHandler)
    if not subscribed:
        err = sdk.get_last_error()
        print("Subscribe for events error: %s" % err)
        return

    print("Working... Press any G/M key or connect/disconnect Corsair device" +
          " to see events in action\n")
    print("Press \"q\" to close program...")

    while (True):
        input_str = input()
        if input_str == "q" or input_str == "Q":
            print("Exiting.")
            break

    sdk.unsubscribe_from_events()
Пример #3
0
def main():
    sdk = CueSdk()
    connected = sdk.connect()
    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: " + err)
        return

    subscribed = sdk.subscribe_for_events(sdk_event_handler)
    if not subscribed:
        err = sdk.get_last_error()
        print("Subscribe for events error: " + err)
        return

    print("Working... Press any G/M key or connect/disconnect Corsair device"
          " to see events in action\n")
    print('Press "q" to close program...')

    while True:
        input_str = input()
        if input_str.lower() == "q":
            print("Exiting.")
            break

    sdk.unsubscribe_from_events()
Пример #4
0
class iCue(SDK):
    def __init__(self):
        super().__init__("iCue")
        self.sdk = CueSdk()
        self.devices = {}

    def available(self):
        if self.sdk.connect():
            self.enable()
            return True

        print("Handshake failed: %s" % self.sdk.get_last_error())
        return False

    def enable(self):
        super().enable()

        devices = self.sdk.get_devices()
        print(f"    Devices found: {len(devices)}")
        for device in devices:
            self.devices[device.id] = device
            print(
                f"      ({device.id}) Type: '{str(device.type).split('.')[-1]}'; "
                f"Model: '{device.model}'; ")

        return self

    def disable(self):
        super().disable()
        self.sdk.release_control()

    def change_colors(self, rgb=(255, 255, 255)):
        if not self.enabled:
            raise Exception(
                f"Trying to change colors while {self.name} SDK is disabled")
        all_leds = self.get_available_leds()
        for device in range(len(all_leds)):
            leds = all_leds[device]
            for led in leds:
                leds[led] = rgb
            self._set_color(device, leds)

        self.sdk.set_led_colors_flush_buffer()

        pass

    def get_available_leds(self):
        leds = [
            self.sdk.get_led_positions_by_device_index(index)
            for index in range(len(self.devices))
        ]
        return leds

    def _set_color(self, device, rgb):
        self.sdk.set_led_colors_buffer_by_device_index(device, rgb)
Пример #5
0
def init():
    global corsair_sdk
    corsair_sdk = CueSdk()
    connected = corsair_sdk.connect()
    corsair_sdk.request_control()
    if not connected:
        err = corsair_sdk.get_last_error()
        print("Handshake failed: %s" % err)
        return

    global corsair_all_leds
    corsair_all_leds = get_available_leds()
Пример #6
0
def main():
    sdk = CueSdk()
    connected = sdk.connect()
    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: %s" % err)
        return

    frames = list()
    device_count = sdk.get_device_count()
    for device_index in range(device_count):
        led_positions = sdk.get_led_positions_by_device_index(device_index)
        frames.append(DeviceFrame(led_positions))

    if (len(frames) == 0):
        return

    # list of effects
    fxs = [gradient, rainbow45, swirls2]
    fxi = 0

    inputQueue = queue.Queue()
    inputThread = threading.Thread(target=read_keys,
                                   args=(inputQueue, ),
                                   daemon=True)
    inputThread.start()

    print("Working...\nPress \"q\" to close program\n"
          "Press any other key to switch between effects")
    while (True):
        if (inputQueue.qsize() > 0):
            input_str = inputQueue.get()

            if input_str == "q" or input_str == "Q":
                print("Exiting.")
                break
            else:
                fxi = (fxi + 1) % len(fxs)
                print("Switching to %s" % fxs[fxi].__name__)

        frame_time = time.time()
        for di in range(device_count):
            frame = frames[di]
            if not frame.empty:
                frame.update(frame_time, fxs[fxi])
                sdk.set_led_colors_buffer_by_device_index(di, frame.colors)
        sdk.set_led_colors_flush_buffer()
Пример #7
0
def main():
    global sdk

    input_queue = queue.Queue()
    input_thread = threading.Thread(target=read_keys,
                                    args=(input_queue, ),
                                    daemon=True)
    input_thread.start()
    sdk = CueSdk()

    connected = sdk.connect()
    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: %s" % err)
        return

    wave_duration = 500
    colors = get_available_leds()
    if not colors:
        return

    print('Working... Use "+" or "-" to increase or decrease speed.\n'
          'Press "q" to close program...')

    while True:
        if input_queue.qsize() > 0:
            input_str = input_queue.get()

            if input_str.lower() == "q":
                print("Exiting.")
                break
            elif input_str == "+":
                if wave_duration > 100:
                    wave_duration -= 100
            elif input_str == "-":
                if wave_duration < 2000:
                    wave_duration += 100

        perform_pulse_effect(wave_duration, colors)

        time.sleep(0.01)
Пример #8
0
def main():
    sdk = CueSdk()
    connected = sdk.connect()
    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: %s" % err)
        return

    frames = list()
    device_count = sdk.get_device_count()
    for device_index in range(device_count):
        led_positions = sdk.get_led_positions_by_device_index(device_index)
        frames.append(DeviceFrame(led_positions))

    if (len(frames) == 0):
        return

    # list of effects
    fxs = [gradient, rainbow45, swirls2]
    fxi = 0
    print("Working...\nPress \"q\" to close program\n"
          "Press any other key to switch between effects")
    while (True):
        if msvcrt.kbhit():
            key = msvcrt.getch().decode()
            if key == "q" or key == "Q":
                print("Exiting.")
                break
            else:
                fxi = (fxi + 1) % len(fxs)
                print("Switching to %s" % fxs[fxi].__name__)

        frame_time = time.time()
        for di in range(device_count):
            frame = frames[di]
            if not frame.empty:
                frame.update(frame_time, fxs[fxi])
                sdk.set_led_colors_buffer_by_device_index(di, frame.colors)
        sdk.set_led_colors_flush_buffer()
Пример #9
0
def main():
    global sdk
    sdk = CueSdk()
    connected = sdk.connect()
    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: %s" % err)
        return

    wave_duration = 500
    colors = get_available_leds()
    if not colors:
        return

    step = 20
    while (True):
        transition(colors, (255, 0, 0), (255, 255, 0), step)
        transition(colors, (255, 255, 0), (0, 255, 0), step)
        transition(colors, (0, 255, 0), (0, 255, 255), step)
        transition(colors, (0, 255, 255), (0, 0, 255), step)
        transition(colors, (0, 0, 255), (255, 0, 255), step)
        transition(colors, (255, 0, 255), (255, 0, 0), step)
def main():
    global sdk
    global color
    color = "ff0000"
    rainbowColor = 0
    sdk = CueSdk()
    connected = sdk.connect()
    print(connected)
    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: %s" % err)
        return

    while True:
        if rainbow:
            rainbowEffect(get_available_leds(), rainbowColor)
            time.sleep(0.05)
            rainbowColor += 1
            #print(rainbowColor*2)
            if rainbowColor > 99:
                rainbowColor = 0
        else:
            static(get_available_leds(), color)
Пример #11
0
def main():
    global sdk

    sdk = CueSdk()
    connected = sdk.connect()

    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: %s" % err)
        return

    colors = get_available_leds()

    # I couldn't be bothered making this play on all devices because I only have 1 anyway, but it shouldn't be too hard to implement
    firstDevice = colors[0]

    keyList = []
    for c in firstDevice:
        keyList.append([c, firstDevice[c]])

    y = []
    x = []
    for c in keyList:
        x.append(c[1][0])
        y.append(c[1][1])

    # Normalize and get min/max
    normY = (np.max(y) - np.min(y))
    normX = (np.max(x) - np.min(x))
    yMin = np.min(y)
    xMin = np.min(x)

    # Make sure the keyvals X:Y are set to 24:6 (just because the keyboard has basically 6 rows and 24 keys as width)
    # Change this as needed.
    for c in keyList:
        c[1] = ((c[1][0] - xMin) / normX * 24, (c[1][1] - yMin) / normY * 6)

    # Reset every key to black, because we might not write to all keys, and it will throw an error if a key doesnt have rgb value
    for key in firstDevice:
        firstDevice[key] = (0, 0, 0)

    # Lets just map all the keys right now so we can skip checking the distance every frame
    keymap = []
    for y in range(6):
        keymap.append([])
        for x in range(0, 24):
            # We add 1 to y here, because apparently that makes the top row work properly.
            key = getClosestPoint((x, y + 1), keyList)
            keymap[y].append(key)

    # Use mss to capture screen
    with mss.mss() as sct:
        # Part of the screen to capture
        monitor = {"top": 0, "left": 0, "width": 1920, "height": 1080}

        while "Screen capturing":
            # Get raw pixels from the screen, save it to a Numpy array
            image = np.array(sct.grab(monitor))
            image = Image.fromarray(image)
            image = scaleImage(image)

            # Change these values as you wish, they are there to enhance colours etc. to make it look nice on the keyboard
            # image = ImageEnhance.Brightness(image).enhance(3.0)
            image = ImageEnhance.Color(image).enhance(3.0)
            image = ImageEnhance.Contrast(image).enhance(2.0)

            image = np.asarray(image)

            for y in range(len(image)):
                for x in range(len(image[y])):
                    key = keymap[y][x]
                    firstDevice[key[0]] = (int(image[y, x,
                                                     2]), int(image[y, x, 1]),
                                           int(image[y, x, 0]))

            sdk.set_led_colors_buffer_by_device_index(0, firstDevice)
            sdk.set_led_colors_flush_buffer()
Пример #12
0
from cuesdk import CueSdk
import time
from PIL import ImageGrab
from PIL import Image
import pandas as pd
import numpy as np

sdk = CueSdk()
sdk.connect()

devices = sdk.get_devices()
device_list = dict()
mouse_on_right = True

for i in range(sdk.get_device_count()):
    device_type = str(devices[i].type)
    if 'Mouse' in device_type:
        device_list.update({'mouse': i})
    if 'Keyboard' in device_type:
        device_list.update({'keyboard': i})


def get_available_leds():
    leds = dict()
    device_count = sdk.get_device_count()
    for device_index in range(device_count):
        led_positions = sdk.get_led_positions_by_device_index(device_index)
        leds.update({device_index: led_positions})
    return leds

Пример #13
0
            if g > 0:
                g -= inc
                continue
            elif r < 255:
                r += inc
                continue
    print("colour (%s,%s,%s)" % (r, g, b))
    set_all_devices_colour((r, g, b))


if __name__ == "__main__":
    # Set-Up Hues
    # b = Bridge("192.168.0.11")
    # lights_object = b.get_light_objects()
    # luke_room = get_hue_lights_from_file(b, "light_names.txt")

    # hue_flash_lights(luke_room, 10)

    # Set-Up CUE
    sdk = CueSdk()
    connected = sdk.connect()
    if not connected:
        err = sdk.get_last_error()
        print("Handshake failed: %s" % err)

    cue_rainbow_cycle(6)

# TODO
#   Threads
#   Speed adjustment