示例#1
0
        private async void StartLogic(TraySettings settings)
        {
            //Initializing Chroma SDK
            IChroma chromaInstance = await ColoreProvider.CreateNativeAsync();

            AppInfo appInfo = new AppInfo(
                "Ambilight for Razer devices",
                "Shows an ambilight effect on your Razer Chroma devices",
                "Nico Jeske",
                "*****@*****.**",
                new[]
            {
                ApiDeviceType.Headset,
                ApiDeviceType.Keyboard,
                ApiDeviceType.Keypad,
                ApiDeviceType.Mouse,
                ApiDeviceType.Mousepad,
                ApiDeviceType.ChromaLink
            },
                Category.Application);
            await chromaInstance.InitializeAsync(appInfo);

            _keyboardLogic = new KeyboardLogic(settings, chromaInstance);
            _mousePadLogic = new MousePadLogic(settings, chromaInstance);
            _mouseLogic    = new MouseLogic(settings, chromaInstance);
            _linkLogic     = new LinkLogic(settings, chromaInstance);
            _headsetLogic  = new HeadsetLogic(settings, chromaInstance);
            _keypadLogic   = new KeypadLogic(settings, chromaInstance);

            DesktopDuplicatorReader reader = new DesktopDuplicatorReader(this, settings);
        }
示例#2
0
        /// <summary>
        /// Creates a new <see cref="IChroma" /> instance using the specified API instance.
        /// </summary>
        /// <param name="info">Information about the application.</param>
        /// <param name="api">The API instance to use to route SDK calls.</param>
        /// <returns>A new instance of <see cref="IChroma" />.</returns>
        public static async Task <IChroma> CreateAsync(AppInfo info, IChromaApi api)
        {
            await ClearCurrentAsync().ConfigureAwait(false);

            _instance = new ChromaImplementation(api, info);
            return(_instance);
        }
示例#3
0
 /// <summary>
 /// Explicitly creates and initializes the <see cref="_instance" /> field
 /// with a new instance of the <see cref="Chroma" /> class.
 /// </summary>
 /// <remarks>
 /// For internal use by singleton accessors in device interface implementations.
 /// </remarks>
 internal static void Initialize()
 {
     if (!Initialized)
     {
         _instance = new Chroma();
     }
 }
示例#4
0
        private async Task <bool> WaitForAccessGranted(IChroma chroma)
        {
            var tcs = new TaskCompletionSource <bool>();

            var callback = new EventHandler <DeviceAccessEventArgs>((s, e) =>
            {
                tcs.SetResult(e.Granted);
            });

            _cw.Chroma = chroma;
            chroma.Register(_cw.Handle);
            chroma.DeviceAccess += callback;

            using var ctsTimeout = new CancellationTokenSource();
            var tTimeout = Task.Delay(_accessGrantedTimeout, ctsTimeout.Token)
                           .ContinueWith(t => false, TaskScheduler.Default);

            var tRes = await Task.WhenAny(tTimeout, tcs.Task).ConfigureAwait(false);

            if (tRes == tcs.Task)
            {
                ctsTimeout.Cancel();
            }

            chroma.DeviceAccess -= callback;
            chroma.Unregister();
            _cw.Chroma = null;

            return(await tRes.ConfigureAwait(false));
        }
示例#5
0
        static void Main(string[] args) // Args - [Filepath - Relative to "C:\ProgramData\ZRazer\Lightpacks\" or absolute.]
        {
            AppCall callArgs = new AppCall(args);

            // Create a mutex to confirm it is the only existing process of its type.
            mutex = new Mutex(true, "RazerColor", out bool createdNew);

            // If its not created new, send its message to the main client.
            if (!createdNew)
            {
                string str = string.Join(":", args); // Combine the args back together
                StartInternalClient(str);            // Send it off to the client server
                return;
            }

            // Fetch a chroma interface
            IChroma chromaInstance = GetInstance().Result;

            bool state = SwitchColour(callArgs, chromaInstance).Result;

            while (state)
            {
                Console.WriteLine("Starting a new server connection...");

                string incomingData = StartInternalServer();
                state = SwitchColour(new AppCall(incomingData.Split(':')), chromaInstance).Result; // End program if it didn't work
            }
            ;

            Error(chromaInstance).Wait();
        }
        private void InitializeChromaSDK()
        {
            _chroma = Chroma.Instance;
            _chroma.Initialize();

            _keyboard = _chroma.Keyboard;
            _keyboard.Clear();
        }
        private static async void StartRestApp()
        {
            // When creating a Chroma instance using the REST API backend, you need to supply the SDK with information about your app.
            var appInfo = new AppInfo("Another App", "Another awesome Chroma app!", "Test Test", "*****@*****.**", Category.Application);

            IChroma chroma = await ColoreProvider.CreateRestAsync(appInfo);

            Console.WriteLine(chroma.Initialized);
        }
        public async Task Render(IChroma chroma)
        {
            var canvas = new ChromaCanvas();

            foreach (var layer in Layers)
            {
                layer.Render(canvas);
            }

            await canvas.SetEffect(chroma).ConfigureAwait(false);
        }
示例#9
0
        public async Task Render(IChroma chroma, object state)
        {
            var canvas = new ChromaCanvas();

            for (var i = 0; i < _layers.Count; i++)
            {
                _layers[i].Render(canvas, state);
            }

            await canvas.SetEffect(chroma).ConfigureAwait(false);
        }
示例#10
0
        static async void ambiantColor()
        {
            KeyboardController keyboard       = new KeyboardController();
            IChroma            ChromaInstance = await ColoreProvider.CreateNativeAsync();

            while (true)
            {
                ScreenShotController screen = new ScreenShotController();
                keyboard.changeKeyboardColor(screen.GetScreenAverageColor());
                keyboard.applyKeyboardColor(ChromaInstance);
            }
        }
示例#11
0
        private void initChromaSkd()
        {
            var t = ColoreProvider.CreateNativeAsync();

            t.Wait();
            this.chroma = t.Result;

            this.muted = KeyboardCustom.Create();
            this.muted.Set(Colore.Data.Color.Red);
            this.muted[Key.Macro4] = Colore.Data.Color.Green;

            this.unmuted = KeyboardCustom.Create();
            this.unmuted.Set(Colore.Data.Color.Green);
            this.unmuted[Key.Macro4] = Colore.Data.Color.Red;
        }
示例#12
0
        void init()
        {
            // User Settings

            XmlDocument xmlConfig = new XmlDocument();

            xmlConfig.Load(AppDomain.CurrentDomain.BaseDirectory + "config.xml");
            var mqttConfig = xmlConfig["RazerChromaMqtt"]["MQTT"];
            var v          = mqttConfig["MqttUser"].InnerText.Trim();

            mqttHost     = mqttConfig["MqttHost"].InnerText.Trim();
            mqttPort     = mqttConfig["MqttPort"].InnerText.Trim();
            mqttUser     = mqttConfig["MqttUser"].InnerText.Trim();
            mqttPw       = mqttConfig["MqttPw"].InnerText.Trim();
            mqttPreTopic = mqttConfig["MqttPreTopic"].InnerText.Trim();

            if (mqttUser == "" || mqttPw == "")
            {
                mqttUser = mqttPw = null;
            }


            // MQTT
            mqttClient                 = MqttClientFactory.CreateClient($"tcp://{mqttHost}:{mqttPort}", "chroma", mqttUser, mqttPw);
            mqttClient.Connected      += MqttC_Connected;
            mqttClient.ConnectionLost += MqttC_ConnectionLost;
            mqttClient.PublishArrived += MqttC_PublishArrived;

            MqttAppender.mqttClient   = mqttClient;
            MqttAppender.mqttPreTopic = mqttPreTopic;

            try
            {
                mqttClient.Connect(mqttPreTopic + "state", QoS.BestEfforts, new MqttPayload("offline"), false);
            }
            catch (Exception e)
            {
                log.Error("Mqtt connect eror : " + e.Message);
                base.Stop();
            }


            Task <IChroma> connectChroma = ColoreProvider.CreateNativeAsync();

            connectChroma.Wait();
            chroma = connectChroma.Result;
        }
示例#13
0
        static async Task Error(IChroma chroma) // Flashes entire keyboard red.
        {
            for (int i = 0; i < 4; i++)
            {
                await chroma.Keyboard.SetAllAsync(ColoreColor.Red);

                await Task.Delay(250);

                await chroma.Keyboard.SetAllAsync(ColoreColor.Black);

                await Task.Delay(250);
            }
            await chroma.SetAllAsync(ColoreColor.Red);

            await Task.Delay(1500);

            return;
        }
示例#14
0
        public void Initialize()
        {
            if (Initialized)
            {
                return;
            }

            ColoreProvider.CreateNativeAsync().ContinueWith(task =>
            {
                if (task.IsCompleted)
                {
                    _chroma     = task.Result;
                    Initialized = _chroma.Initialized;
                }

                SdkInit?.Invoke(this, new SdkInitEvent {
                    Initialized = Initialized
                });
            });
        }
示例#15
0
        public Task SetEffect(IChroma chroma)
        {
            if (chroma == null)
            {
                throw new ArgumentNullException(nameof(chroma));
            }

            var tasks = new List <Task <Guid> >();

            if (_keyboard.IsValueCreated)
            {
                tasks.Add(chroma.Keyboard.SetCustomAsync(Keyboard));
            }

            if (_mouse.IsValueCreated)
            {
                tasks.Add(chroma.Mouse.SetGridAsync(Mouse));
            }

            if (_headset.IsValueCreated)
            {
                tasks.Add(chroma.Headset.SetCustomAsync(Headset));
            }

            if (_mousepad.IsValueCreated)
            {
                tasks.Add(chroma.Mousepad.SetCustomAsync(Mousepad));
            }

            if (_keypad.IsValueCreated)
            {
                tasks.Add(chroma.Keypad.SetCustomAsync(Keypad));
            }

            if (_chromaLink.IsValueCreated)
            {
                tasks.Add(chroma.ChromaLink.SetCustomAsync(ChromaLink));
            }

            return(Task.WhenAll(tasks));
        }
示例#16
0
        private async Task Initialize()
        {
            // get chroma instance
            chroma = await ColoreProvider.CreateNativeAsync();

            // Create the custom Grid
            keyboardGrid = KeyboardCustom.Create();

            // show bounds
            CreateGridBorder(ColoreColor.Yellow);

            // show controls
            keyboardGrid[ColoreKey.Left]  = ColoreColor.Blue;
            keyboardGrid[ColoreKey.Right] = ColoreColor.Blue;
            keyboardGrid[ColoreKey.Up]    = ColoreColor.Blue;
            keyboardGrid[ColoreKey.Down]  = ColoreColor.Blue;

            // set player start position
            currentDirection = lastDirection = Position2D.Right;
            playerPosition   = (leftBottomBounds + rightTopBounds) / 2;
            playerBody.Clear();

            // Create a Grid containing all used positions
            freeCells.Clear();
            TraverseGrid((row, col) =>
            {
                var pos = new Position2D(row, col);
                if (pos != playerPosition && pos != targetPosition && !playerBody.Contains(pos))
                {
                    freeCells.Add(pos);
                }
            });

            // Create Target Position
            CreateNextRandomTarget(ColoreColor.Red);

            await chroma.Keyboard.SetCustomAsync(keyboardGrid);
        }
示例#17
0
 public RazerSdkAdapter()
 {
     this._chromaInterface = ColoreProvider.CreateNativeAsync().Result;
 }
示例#18
0
 /// <summary>
 /// Explicitly creates and initializes the <see cref="_instance" /> field
 /// with a new instance of the <see cref="Chroma" /> class.
 /// </summary>
 /// <remarks>
 /// For internal use by singleton accessors in device interface implementations.
 /// </remarks>
 internal static void Initialize()
 {
     if (!Initialized)
         _instance = new Chroma();
 }
示例#19
0
 public KeyboardLogic(TraySettings settings, IChroma chromaInstance)
 {
     this._settings = settings;
     this._chroma   = chromaInstance;
 }
示例#20
0
 public MousePadLogic(TraySettings settings, IChroma chromaInstance)
 {
     this._settings = settings;
     this._chroma   = chromaInstance;
 }
        private void InitializeChromaSDK()
        {
            _chroma = Chroma.Instance;
            _chroma.Initialize();

            _keyboard = _chroma.Keyboard;
            _keyboard.Clear();
        }
示例#22
0
 public async Task InitChromaAsync()
 {
     chroma = await ColoreProvider.CreateNativeAsync();
 }
示例#23
0
 public HeadsetLogic(TraySettings settings, IChroma chroma)
 {
     _settings = settings;
     _chroma   = chroma;
 }
示例#24
0
        static async Task <bool> SwitchColour(AppCall args, IChroma chroma)
        {
            if (args.invalid)
            {
                return(false);
            }

            var grid = KeyboardCustom.Create();

            if (args.addWeak || args.addStrong)
            {
                grid = currentKeyboard;
            }

            ColoreColor clr = ColoreColor.Black;

            foreach (string fline in File.ReadLines(args.filePath))
            {
                string line = fline;
                if (line.Contains(";"))
                {
                    line = line.Substring(0, line.IndexOf(";"));
                }
                line = line.Trim();
                if (line == "")
                {
                    continue;
                }


                if (line.ToLower().StartsWith("rgb"))
                {
                    var b = line.Remove(0, 3).Trim();

                    try
                    {
                        clr = ColoreColor.FromRgb(uint.Parse(b, System.Globalization.NumberStyles.HexNumber));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("yo your color was invalid dude");
                        Console.WriteLine(e);
                        return(false);
                    }
                }

                if (line.ToLower().StartsWith("all"))
                {
                    grid.Set(clr);
                }

                if (!Enum.TryParse(line, true, out Key currKey) && !line.ToLower().StartsWith("rgb") && !line.ToLower().StartsWith("all")) // horrible code hours
                {
                    Console.WriteLine("thats not a valid key pls fix");
                    Console.WriteLine(currKey.ToString());
                    return(false);
                }


                if (args.addWeak)
                {
                    if (grid[currKey] == ColoreColor.Black)
                    {
                        grid[currKey] = clr;
                    }
                }
                else
                {
                    grid[currKey] = clr;
                }
            }

            currentKeyboard = grid;
            Console.WriteLine("bro");
            await chroma.Keyboard.SetCustomAsync(grid);

            return(true);
        }
示例#25
0
 public ChromaKeyboardClient(IChroma chroma, int?columnCount, int?rowCount)
 {
     keyboard          = chroma.Keyboard;
     keyboardPositions = CalculatePositions(columnCount ?? KeyboardConstants.MaxColumns, rowCount ?? KeyboardConstants.MaxRows).ToArray();
     positions         = keyboardPositions.Select(k => new Position(k.X, k.Y)).ToArray();
 }
示例#26
0
        public Module Setup()
        {
            IChroma chroma = ColoreProvider.CreateNativeAsync().Result;

            chroma.SetAllAsync(Colore.Data.Color.Red);
            chroma.Keyboard[Key.A] = Colore.Data.Color.Red;

            Module module = new Module()
            {
                Name = "Razer"
            };

            module.Devices.Add(new Device()
            {
                Id    = "RAZER_BLACKWIDOW_V1",
                Title = "BlackWidow",
                Map   = new DeviceMap()
                {
                    BackgroundImage = ImageToByteArray(Resource.keyboard),
                    Size            = new Size(100, 30),
                    Leds            = new Point[1, 2]
                    {
                        { new Point(10, 10), new Point(10, 40) }
                    }
                }

                /*Map = new int[7, 23]
                 *  {
                 *      {0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
                 *      {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 *      {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 *      {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0},
                 *      {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1},
                 *      {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                 *      {0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0}
                 *  }*/
            });

            module.Devices.Add(new Device()
            {
                Id    = "LED_STRIP",
                Title = "LedStrip",
                Map   = new DeviceMap()
                {
                    BackgroundImage = null,
                    Size            = new Size(300, 5),
                    Leds            = new Point[1, 21]
                    {
                        {
                            new Point(0, 0),
                            new Point(15, 0),
                            new Point(30, 0),
                            new Point(45, 0),
                            new Point(60, 0),
                            new Point(75, 0),
                            new Point(90, 0),
                            new Point(105, 0),
                            new Point(120, 0),
                            new Point(135, 0),
                            new Point(150, 0),
                            new Point(165, 0),
                            new Point(180, 0),
                            new Point(195, 0),
                            new Point(210, 0),
                            new Point(225, 0),
                            new Point(240, 0),
                            new Point(255, 0),
                            new Point(270, 0),
                            new Point(285, 0),
                            new Point(300, 0)
                        }
                    }
                }
            });

            module.Devices.Add(new Device()
            {
                Id    = "RAZER_DEATHADDER_V2",
                Title = "Death Adder",
                Map   = new DeviceMap()
                {
                    BackgroundImage = ImageToByteArray(Resource.mouse),
                    Size            = new Size(50, 50),
                    Leds            = new Point[1, 2]
                    {
                        { new Point(25, 15), new Point(25, 40) }
                    }
                }
            });

            module.Devices.Add(new Device()
            {
                Id    = "RAZER_CHROMA_7.1",
                Title = "Chroma 7.1",
                Map   = new DeviceMap()
                {
                    BackgroundImage = ImageToByteArray(Resource.headphones),
                    Size            = new Size(50, 50),
                    Leds            = new Point[2, 1]
                    {
                        { new Point(5, 36) }, { new Point(45, 36) }
                    }
                }
            });

            return(module);
        }