Example #1
0
 internal static void StartStopComThread()
 {
     serial?.Dispose();
     if (!string.IsNullOrWhiteSpace(Settings.Model.SerialComId))
     {
         serial = new SerialCom();
         SerialCom.Enqueue(Message.SetLedNumber(Settings.Model.TotalLeds));
         SerialCom.Enqueue(Message.GetPatterns());
     }
 }
Example #2
0
        internal static void Run(object obj)
        {
            Thread.CurrentThread.Name = "DXGI Capture";
            var token = (CancellationToken)obj;

            int i, ix;

            byte[] points, color;
            HardwareScreenCapture <T> instance = null;

            while (!token.IsCancellationRequested)
            {
                try
                {
                    if (instance == null)
                    {
                        instance = new HardwareScreenCapture <T>();
                        instance.Initialize();
                        SerialCom.Enqueue(Message.StreamStart());
                        //first call or two returns an empty (black) screen
                        //consume here during init
                        instance.CaptureFrameGPU();
                    }

                    if (instance.CaptureFrameGPU())
                    {
#if DOT_TIMER
                        var sw = new Stopwatch();
                        sw.Start();
#endif
                        instance.TransferFrameCPU();
#if PARALLEL
                        Parallel.ForEach(instance.ledPoints, x => x.Calculate());
#else
                        for (i = 0; i < instance.ledPoints.Length; i++)
                        {
                            instance.ledPoints[i].Calculate();
                        }
#endif
                        points = new byte[instance.ledPoints.Length * 3];

                        for (i = 0, ix = 0; i < instance.ledPoints.Length; ++i, ix = i * 3)
                        {
                            color          = instance.ledPoints[i].mean;
                            points[ix]     = color[0];
                            points[ix + 1] = color[1];
                            points[ix + 2] = color[2];
                        }

                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        SerialCom.Enqueue(new Message.Command()
                        {
                            Type = Message.Type.Stream,
                            Raw  = points
                        });
#if DOT_TIMER
                        Console.WriteLine(sw.Elapsed.TotalMilliseconds);
#endif
                        instance.Render(points);
                    }
                }
                catch (Exception)
                {
                    instance?.Dispose();
                    instance = null;
                }
            }
            instance?.Dispose();
        }