예제 #1
0
        private void DataAvailable(object sender, WaveInEventArgs e)
        {
            var peak = MaxFloat(e.Buffer, e.BytesRecorded) * 100F;
            var val  = peak <= 2F? 38F : 255F * Math.Log10(peak) / 2F;

            SerialCom.Enqueue(Message.SetBright((int)val));
            Thread.Sleep(33);
        }
예제 #2
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());
     }
 }
예제 #3
0
        internal static void Stop()
        {
            if (instance == null)
            {
                return;
            }

            instance.capture.StopRecording();
            instance = null;
            SerialCom.Enqueue(Message.SetBright(Settings.Model.Brightness));
        }
예제 #4
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();
        }