コード例 #1
0
 public StreamDeckHidTestContext(IHardwareInternalInfos hardware)
 {
     Hardware = hardware ?? throw new ArgumentNullException(nameof(hardware));
     Log      = new StringWriter();
     Hid      = new FakeStreamDeckHid(Log, Hardware);
     Board    = new BasicHidClient(Hid, Hardware);
 }
コード例 #2
0
        public CachedHidClient(IStreamDeckHid deckHid, IHardwareInternalInfos hardwareInformation)
            : base(deckHid, hardwareInformation)
        {
            imageQueue = new ConcurrentBufferedQueue <int, byte[]>(RelativeTimeSource.Default, hardwareInformation.KeyCooldown);

            writerTask = StartBitmapWriterTask();
        }
コード例 #3
0
        internal async Task InputReportsBehaveAsExpected(
            string testName,
            IHardwareInternalInfos hardware,
            IEnumerable <byte[]> inputReports
            )
        {
            // Arrange
            Verifier.Initialize();

            Verifier
            .UseFileNameAsDirectory()
            .UseFileName(testName);

            using var context = new StreamDeckHidTestContext(hardware);

            var keyLog = new StringBuilder();

            context.Board.KeyStateChanged += (s, e)
                                             => keyLog.Append(e.Key).Append(" - ").AppendLine(e.IsDown ? "DOWN" : "UP");

            // Act
            foreach (var report in inputReports)
            {
                context.Hid.FakeIncommingInputReport(report);
            }

            // Assert
            await Verifier.VerifyAsync(keyLog.ToString());
        }
コード例 #4
0
        private CachedHidClient(IStreamDeckHid deckHid, IHardwareInternalInfos hardwareInformation)
            : base(deckHid, hardwareInformation)
        {
            imageQueue = new ConcurrentBufferedQueue <int, byte[]>(RelativeTimeSource.Default, 75);

            writerTask     = StartBitmapWriterTask();
            keyPollingTask = StartKeyPollingTask();
        }
コード例 #5
0
ファイル: Hardware.cs プロジェクト: something-insane/map-deck
        static Hardware()
        {
            var hwStreamDeck     = new StreamDeckHardwareInfo();
            var hwStreamDeckMini = new StreamDeckMiniHardwareInfo();

            StreamDeck     = hwStreamDeck;
            StreamDeckMini = hwStreamDeckMini;

            Internal_StreamDeck     = hwStreamDeck;
            Internal_StreamDeckMini = hwStreamDeckMini;
        }
コード例 #6
0
        public BasicHidClient(IStreamDeckHid deckHid, IHardwareInternalInfos hardwareInformation)
        {
            DeckHid = deckHid;
            Keys    = hardwareInformation.Keys;

            deckHid.ConnectionStateChanged += (s, e) => ConnectionStateChanged?.Invoke(this, e);
            deckHid.ReportReceived         += DeckHid_ReportReceived;

            HardwareInfo = hardwareInformation;
            Buffer       = new byte[deckHid.OutputReportLength];
            keyStates    = new byte[Keys.Count];
        }
コード例 #7
0
        internal async Task HardwareTwinsHaveExpectedValues(IHardwareInternalInfos hardware)
        {
            // This test is to make sure we don't accidentially change some important constants.
            Verifier.Initialize();

            Verifier
            .UseFileNameAsDirectory()
            .UseFileName(hardware.DeviceName)
            ;

            var hardwareJson = JsonConvert.SerializeObject(hardware);
            await Verifier.VerifyJsonAsync(hardwareJson);
        }
コード例 #8
0
        public BasicHidClient(IStreamDeckHid deckHid, IHardwareInternalInfos hardwareInformation)
        {
            this.deckHid = deckHid;
            Keys         = hardwareInformation.Keys;

            deckHid.ConnectionStateChanged += (s, e) => ConnectionStateChanged?.Invoke(this, e);

            this.hardwareInformation = hardwareInformation;
            keyStates = new byte[Keys.Count];

            reportGenerator = new OutputReportGenerator(
                deckHid.OutputReportLength,
                hardwareInformation.ReportSize,
                hardwareInformation.StartReportNumber
                );
        }
コード例 #9
0
        internal async Task CallingShowLogoCausesTheExpectedOutput(IHardwareInternalInfos hardware)
        {
            // Arrange
            Verifier.Initialize();

            Verifier
            .UseFileNameAsDirectory()
            .UseFileName(hardware.DeviceName);

            using var context = new StreamDeckHidTestContext(hardware);

            // Act
            context.Board.ShowLogo();

            // Assert
            await Verifier.VerifyAsync(context.Log.ToString());
        }
コード例 #10
0
        static Hardware()
        {
            var hwStreamDeck     = new StreamDeckHardwareInfo();
            var hwStreamDeckRev2 = new StreamDeckRev2HardwareInfo();
            var hwStreamDeckXL   = new StreamDeckXlHardwareInfo();
            var hwStreamDeckMini = new StreamDeckMiniHardwareInfo();

            StreamDeck     = hwStreamDeck;
            StreamDeckRev2 = hwStreamDeckRev2;
            StreamDeckXL   = hwStreamDeckXL;
            StreamDeckMini = hwStreamDeckMini;

            Internal_StreamDeck     = hwStreamDeck;
            Internal_StreamDeckRev2 = hwStreamDeckRev2;
            Internal_StreamDeckXL   = hwStreamDeckXL;
            Internal_StreamDeckMini = hwStreamDeckMini;
        }
コード例 #11
0
        internal async Task SettingBrightnessCausesTheExpectedOuput(IHardwareInternalInfos hardware, byte brightness)
        {
            // Arrange
            Verifier.Initialize();

            Verifier
            .UseFileNameAsDirectory()
            .UseFileName(hardware.DeviceName)
            .UseUniqueSuffix($"Value={brightness}");

            using var context = new StreamDeckHidTestContext(hardware);

            // Act
            context.Board.SetBrightness(brightness);

            // Assert
            await Verifier.VerifyAsync(context.Log.ToString());
        }
コード例 #12
0
        internal void GettingFirmwareVersionWorksAsExpected(
            IHardwareInternalInfos hardware,
            byte[] featureData,
            string expectedParsedFirmware
            )
        {
            // Arrange
            using var context = new StreamDeckHidTestContext(hardware);

            context.Hid.ReadFeatureResonseQueue.Enqueue((hardware.FirmwareVersionFeatureId, true, featureData));

            // Act
            context.Board.GetFirmwareVersion().Should().Be(expectedParsedFirmware);

            // Assert
            context.Hid.ReadFeatureResonseQueue.Should().BeEmpty();
            context.Log.ToString().Should().BeEmpty();
        }
コード例 #13
0
        internal async Task BasicBitmapKeyOutputAsExpected(IHardwareInternalInfos hardware)
        {
            // Arrange
            Verifier.Initialize();

            Verifier
            .UseFileNameAsDirectory()
            .UseFileName(hardware.DeviceName)
            ;

            using var context = new StreamDeckHidTestContext(hardware);
            context.Hid.BytesPerLineOutput = 1024;

            var colorEachChannelDifferent = KeyBitmap.Create.FromRgb(0x6A, 0x4A, 0x4F);
            var red  = KeyBitmap.Create.FromRgb(0xFF, 0, 0);
            var blue = KeyBitmap.Create.FromRgb(0, 0, 0xFF);

            // Act
            context.Log.WriteLine("Set all keys to a defined color.");
            context.Board.SetKeyBitmap(colorEachChannelDifferent);

            context.Log.WriteLine("Clear all keys.");
            context.Board.ClearKeys();

            context.Log.WriteLine("Set key 0 to red.");
            context.Board.SetKeyBitmap(0, red);

            context.Log.WriteLine("Clear key 0.");
            context.Board.ClearKey(0);

            context.Log.WriteLine("Set key 0 to blue");
            context.Board.SetKeyBitmap(0, blue);

            context.Log.WriteLine("Set key 0 to KeyBitmap.Black");
            context.Board.SetKeyBitmap(0, KeyBitmap.Black);

            // Assert
            await Verifier.VerifyAsync(context.Log.ToString());
        }
コード例 #14
0
 public FakeStreamDeckHid(TextWriter log, IHardwareInternalInfos hardware)
 {
     this.log      = log ?? throw new ArgumentNullException(nameof(log));
     this.hardware = hardware ?? throw new ArgumentNullException(nameof(hardware));
 }
コード例 #15
0
        internal async Task SetBitmapResultsInExpectedOutput8PxTiles(IHardwareInternalInfos hardware)
        {
            // Arrange
            Verifier.Initialize();

            Verifier
            .UseFileNameAsDirectory()
            .UseFileName(hardware.DeviceName)
            ;

            using var context = new StreamDeckHidTestContext(hardware);
            context.Hid.BytesPerLineOutput = 1024;

            // create an image that probably survives JPEG compression
            // by using 8x8 tiles that have the same color and hopefully results in similar JPEGs
            // even when using different JPEG encoders.
            // In a best case scenario I hope this test is resistant against swapping JPEG encoders.

            // we have to create a key bitmap for the exact key size to prevent automatic resizing.

            var keySize = hardware.Keys.KeySize;

            const int tileSize     = 8;
            const int channelCount = 3;

            // make sure the key size is divisible by 8
            (keySize % tileSize).Should().Be(0);

            var tileCnt     = keySize / tileSize;
            var rnd         = new Random(42);
            var colorBuffer = new byte[3];

            (byte R, byte G, byte B) GetNextRndColor()
            {
                rnd.NextBytes(colorBuffer);
                return(colorBuffer[0], colorBuffer[1], colorBuffer[2]);
            }

            var pixelData = new byte[keySize * keySize * channelCount];

            for (int y = 0; y < tileCnt; y++)
            {
                for (int x = 0; x < tileCnt; x++)
                {
                    var(r, g, b) = GetNextRndColor();

                    for (int dy = 0; dy < tileSize; dy++)
                    {
                        for (int dx = 0; dx < tileSize; dx++)
                        {
                            var yOffset = (y * tileSize + dy) * keySize;
                            var xOffset = x * tileSize + dx;
                            var index   = (yOffset + xOffset) * channelCount;

                            pixelData[index]     = b;
                            pixelData[index + 1] = g;
                            pixelData[index + 2] = r;
                        }
                    }
                }
            }

            var colorFullKeyBitmap = KeyBitmap.FromBgr24Array(keySize, keySize, pixelData);

            // Act
            context.Board.SetKeyBitmap(0, colorFullKeyBitmap);

            // Assert
            await Verifier.VerifyAsync(context.Log.ToString());
        }