コード例 #1
0
        public void ClearColorFromVirtualLedGrid_ShouldSetAllKeyColorToNull()
        {
            var instance = new VirtualLedGrid(2, 2);

            instance.Set(Color.Green);
            instance.Clear();
            Assert.All(instance, (x) => Assert.Null(x.Color));
        }
コード例 #2
0
        public void Indexer_WithInvalidIndex_ShouldThrowIndexOutOfRange(int x, int y)
        {
            VirtualLedGrid instance = new VirtualLedGrid(2, 2);

            instance.Set(Color.Red);

            Assert.Throws <IndexOutOfRangeException>(() => instance[x, y]);
        }
コード例 #3
0
        public void SetColorToVirtualLedGrid_AllKeyShouldChangeAccordingly()
        {
            var givenColor    = Color.Green;
            var expectedColor = Color.Green;
            var instance      = new VirtualLedGrid(2, 2);

            instance.Set(givenColor);
            Assert.All(instance, (x) => Assert.Equal(expectedColor, x.Color.Value));
        }
コード例 #4
0
        public void SetNullColorToVirtualLedGrid_AllKeyShouldChangeAccordingly()
        {
            Color?givenColor    = null;
            Color?expectedColor = null;
            var   instance      = new VirtualLedGrid(2, 2);

            instance.Set(givenColor);

            Assert.All(instance, (x) => Assert.Equal(expectedColor, x.Color));
        }
コード例 #5
0
        public void Indexer_WithProperIndex_ShouldReturnColor(int x, int y)
        {
            VirtualLedGrid instance = new VirtualLedGrid(2, 2);

            instance.Set(Color.Red);

            var expected = Color.Red;
            var actual   = instance[x, y];

            Assert.Equal(expected, actual);
        }
コード例 #6
0
        public async Task Apply_LedGrid_ToAdapter_ShouldSuccess()
        {
            var grid = new VirtualLedGrid(30, 9);

            var mockAdapter = new Mock <IPhysicalDeviceAdapter>();

            mockAdapter.Setup(x => x.ColumnCount).Returns(20);
            mockAdapter.Setup(x => x.RowCount).Returns(9);
            mockAdapter.Setup(x => x.Initialized).Returns(true);

            var mediator = new PhysicalDeviceMediator(grid);

            mediator.Attach(0, 0, mockAdapter.Object);

            grid.Set(Color.Red);

            await mediator.ApplyAsync();
        }
コード例 #7
0
        public void SetColorsToVirtualLedGrid_ShouldSetKeyColorCorrectly()
        {
            var givenColors = new Color?[2][]
            {
                new Color?[] { Color.Red, Color.Green },
                new Color?[] { Color.Blue, Color.White }
            };
            var expectedColors = new Color?[2][]
            {
                new Color?[] { Color.Red, Color.Green },
                new Color?[] { Color.Blue, Color.White }
            };
            var instance = new VirtualLedGrid(2, 2);

            instance.Set(givenColors);

            foreach (var key in instance)
            {
                var col           = key.Index.X;
                var row           = key.Index.Y;
                var expectedColor = expectedColors[row][col];
                Assert.Equal(expectedColor, key.Color);
            }
        }
コード例 #8
0
        static async Task Main(string[] args)
        {
            if (!OperatingSystem.IsWindows())
            {
                throw new NotSupportedException("This application is designed to support only Windows OS.");
            }

            // This program is use to demonstrate the usage of VirtualGrid library
            // by capture some parameters from system information
            // and create an effect to reflect those parameters accordingly.

            var cpuCounter        = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            var memoryCounter     = new PerformanceCounter("Memory", "Available MBytes");
            var totalMemoryMBytes = GC.GetGCMemoryInfo().TotalAvailableMemoryBytes / 1024 / 1024;
            var gpu = PhysicalGPU.GetPhysicalGPUs().FirstOrDefault();

            var backgroundGrid = new VirtualLedGrid(30, 9);

            backgroundGrid.Set(new Color(0, 16, 0));

            var grid = new VirtualLedGrid(30, 9);

            // Order of grid matters, predecessor grids will get override by successor grids.
            // in this example the green background will get override by custom system color in some area.
            using var mediator = new PhysicalDeviceMediator(backgroundGrid, grid);

            mediator.Attach <RazerKeyboardAdapter>(0, 1);
            mediator.Attach <RazerMousepadAdapter>(0, 0);
            mediator.Attach <RazerMouseAdapter>(23, 0);
            mediator.Attach <RazerHeadsetAdapter>(25, 7);
            mediator.Attach <RazerChromaLinkAdapter>(12, 8);

            var cpuGrid    = grid.Slice(2, 2, 12, 1);
            var memoryGrid = grid.Slice(2, 3, 12, 1);
            var diskGrid   = grid.Slice(2, 4, 11, 1);
            var gpuGrid    = grid.Slice(2, 5, 11, 1);

            var cpuColor    = new Color(17, 125, 187);
            var memoryColor = new Color(139, 18, 174);
            var diskColor   = new Color(77, 166, 12);

            var cpuIdleColor         = new Color(2, 12, 19);
            var memoryAvailableColor = new Color(14, 2, 17);
            var diskAvailableColor   = new Color(8, 17, 1);

            for (; ;)
            {
                cpuGrid.Set(cpuIdleColor);
                memoryGrid.Set(memoryAvailableColor);
                diskGrid.Set(diskAvailableColor);
                gpuGrid.Set(cpuIdleColor);

                var cpuUtilize         = cpuCounter.NextValue() / 100f;
                var currentMemoryUsage = memoryCounter.NextValue();
                var memoryUtilize      = 1.0f - (currentMemoryUsage / totalMemoryMBytes);
                var gpuUtilize         = (gpu?.UsageInformation.GPU.Percentage ?? 0) / 100f;

                var cpuGridLength    = (int)(cpuGrid.ColumnCount * cpuUtilize);
                var memoryGridLength = (int)(memoryGrid.ColumnCount * memoryUtilize);
                var gpuGridLegth     = (int)(gpuGrid.ColumnCount * gpuUtilize);

                var diskInfo         = new DriveInfo("C");
                var freeSpacePercent = (double)(diskInfo.TotalSize - diskInfo.TotalFreeSpace) / diskInfo.TotalSize;
                var diskGridLength   = (int)(diskGrid.ColumnCount * (freeSpacePercent));

                for (var cpuCol = 0; cpuCol < cpuGridLength; cpuCol++)
                {
                    cpuGrid[cpuCol, 0] = cpuColor;
                }

                for (var memoryCol = 0; memoryCol < memoryGridLength; memoryCol++)
                {
                    memoryGrid[memoryCol, 0] = memoryColor;
                }

                for (var diskCol = 0; diskCol < diskGridLength; diskCol++)
                {
                    diskGrid[diskCol, 0] = diskColor;
                }

                for (var gpuCol = 0; gpuCol < gpuGridLegth; gpuCol++)
                {
                    gpuGrid[gpuCol, 0] = cpuColor;
                }

                await mediator.ApplyAsync();

                await Task.Delay(100);
            }
        }