Exemplo n.º 1
0
 public void Stop()
 {
     timer?.Dispose();
     snapshotStorage.Save(behavior.StartingBrightLevel, behavior.CurrentBright);
     portProvider.WriteCommand("#LEDBOFF");
     behavior = null;
     OnStopped();
 }
Exemplo n.º 2
0
        public Result Run(PupilReaction model, bool isAutoMode)
        {
            if (cameraProvider.ConnectedCamera == null)
            {
                return(Result.Failure("Camera not found. Please connect camera."));
            }

            if (portProvider.ConnectedPort == null)
            {
                return(Result.Failure("Port not found. Please connect port"));
            }

            if (behavior != null)
            {
                return(Result.Failure("Previous operation was not finished."));
            }

            try
            {
                if (!cameraProvider.ConnectedCamera.IsGrabbing)
                {
                    cameraProvider.ConnectedCamera.StartGrabbing();
                }

                behavior = model;
                behavior.Init();
                OnBrightChanged(behavior.CurrentBright);

                portProvider.WriteCommand("#LEDAON");
                portProvider.WriteCommand($"#PWMB{behavior.StartingBrightLevel}");

                if (isAutoMode)
                {
                    timer = new Timer(state =>
                    {
                        if (behavior.CurrentBright == byte.MaxValue)
                        {
                            Stop();
                            return;
                        }

                        IncreaseBright();
                        Snapshot();
                    }, null, 2000, 2000);
                }
            }
            catch (Exception e)
            {
                return(Result.Failure(e.Message));
            }

            return(Result.Success());
        }