예제 #1
0
        public void Start(HypnoLsdController device, Remapper remapper, int mbaud, Action <uint[]> imageFilterIn = null)
        {
            this.device = device;

            Remapper = remapper;
            Width    = remapper.Width;
            Height   = remapper.Height;

            if (imageFilterIn != null)
            {
                this.imageFilter = imageFilterIn;
            }
            else
            {
                this.imageFilter = b => { }
            };                               // identity

            AddDemos();

            // get attention
            device.WriteString("\r\n");
            Thread.Sleep(250);

            //device.ConnectionSpeed = 1000000; // 1 Mbaud for testing
            //Thread.Sleep(100);

            //Thread.Sleep(1000);
            //device.Drawing = true;
            //Thread.Sleep(1000);
            //device.Drawing = false;
            //Thread.Sleep(1000);

            device.WriteString("\r\n");


            device.ConnectionSpeed = mbaud; // 12000000;// 3000000;// 12000000; // 12 Mbaud for testing
            Thread.Sleep(500);

            const int delay = 200;

            device.Drawing = false;
            Thread.Sleep(delay);

            device.Drawing = true;
            Thread.Sleep(delay);
            device.Drawing = false;
            Thread.Sleep(delay);

            if (remapper.SupportedStrands.Contains(remapper.Strands))
            {
                device.SetSize(remapper.Strands, remapper.Width * remapper.Height / remapper.Strands);
            }
            else
            {
                throw new NotImplementedException("Remapper does not support " + remapper.Strands + " strands");
            }

            // some context switches to ensure we're at the top in case we disconnected early last time.
            device.Drawing = true;
            Thread.Sleep(delay);
        }
예제 #2
0
        /// <summary>
        ///     Do a test that the remote image buffer is getting the right
        ///     byte structure in RAM when receiving bytes.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="message"></param>
        public void TestImage(HypnoLsdController device, Action <string> message)
        {
            // fill buffer and test wraparound of buffer
            var buffer = new byte[device.RamSize + 1000];

            // save these
            int w = device.ImageWidth, h = device.ImageHeight;

            // set to full size and zero it
            device.SetSize(16, 625);

            Thread.Sleep(500); // wait for above to settle

            // zero the buffer
            var returnedBytes = RoundTripBuffer(buffer, device);

            // amount expected back. Accounts for small and large wraparound buffers
            var testLength = Math.Min(buffer.Length, device.RamSize);

            // compare it
            var error      = returnedBytes.Length != testLength;
            var errorCount = 0;

            if (!error)
            {
                for (var i = 0; i < returnedBytes.Length; ++i)
                {
                    errorCount += buffer[i] != returnedBytes[i] ? 1 : 0;
                }
            }
            if (error || errorCount != 0)
            {
                message("Comparison error on zero image, " + errorCount + " places" +
                        (errorCount == 0
                            ? ". " + returnedBytes.Length + " bytes bytes returned out of " + testLength
                            : "") + "\n");
            }
            else
            {
                message("No comparison error on zero image\n");
            }

            // restore settings
            device.SetSize(w, h);

            // create legal random image. Remove sync bytes
            var rand = new Random();

            rand.NextBytes(buffer);
            for (var i = 0; i < buffer.Length; ++i)
            {
                if (buffer[i] == 254)
                {
                    buffer[i] = 255;
                }
            }

            // get the buffer back
            returnedBytes = RoundTripBuffer(buffer, device);

            // compare it
            error      = returnedBytes.Length != testLength;
            errorCount = 0;
            byte[] packedBuffer = null;
            if (!error)
            {
                packedBuffer = StripeBuffer(device, w, h, buffer);
                for (var i = 0; i < testLength; ++i)
                {
                    errorCount += packedBuffer[i] != returnedBytes[i] ? 1 : 0;
                }
            }
            if (error || errorCount != 0)
            {
                message("Comparison error on complex image, " + errorCount + " places" +
                        (errorCount == 0
                            ? ". " + returnedBytes.Length + " bytes bytes returned out of " + testLength
                            : "") +
                        "\n");
            }
            else
            {
                message("No comparison error on complex image\n");
            }
        }