예제 #1
0
        protected override void ThreadAction()
        {
            if (ObservedImage == null)
            {
                return;
            }

            if (m_SampleImage == null)
            {
                return;
            }

            Profiler.Start(Name);

            Profiler.Start(Name + "_CloneScreen");
            lock (ScreenStateThread.ScreenBmpLock)
            {
                BitmapUtility.Clone32BPPBitmap(ScreenStateThread.ScreenBmp, ObservedImage);
            }
            Profiler.Stop(Name + "_CloneScreen");

            Profiler.Start(Name + "_FindMatch");
            var points  = FindImagePositions();
            var success = ValidatePointsCorrectness(points);

            Profiler.Stop(Name + "_FindMatch");

            if (success)
            {
                PositionFound?.Invoke(points);
                LastKnownPositions  = points;
                WasImageFound       = true;
                WasLastCheckSuccess = true;
                TimeSinceLastFind   = 0;
                m_Watch.Restart();
            }
            else
            {
                WasLastCheckSuccess = false;
                TimeSinceLastFind   = (int)m_Watch.ElapsedMilliseconds;
            }

            Profiler.Stop(Name);
        }
예제 #2
0
 private void SetPositionAndGetReading(int position)
 {
     try
     {
         _contoller.SetPwm(PwmChannel.C0, 0, position);
         Task.Delay(50).Wait();
         if (_haveReading())
         {
             PositionFound?.Invoke(this, new PositionalDistanceEventArgs {
                 Angle = Angle(position), Proximity = _lastReading.Proximity, RawValue = _lastReading.RawValue
             });
         }
     }
     catch (Exception ex)
     {
         SensorException?.Invoke(this, new ExceptionEventArgs {
             Exception = ex, Message = "An error occured setting Angle and getting distance."
         });
     }
 }
예제 #3
0
 protected virtual void OnFindPositionFound(FindByteDataEventArgs e)
 {
     PositionFound?.Invoke(this, e);
 }