/// <summary>
        /// This class object is not deserializable, and should be created by EgsDevicesManager.
        /// </summary>
        internal EgsDevice()
        {
            _IndexInHidDevicePathList = -1;
            _HidDeviceDevicePath      = "";
            _IsHidDeviceConnected     = false;

            _IsConnected = false;

            _IsUpdatingFirmware = false;

            _IsSendingTouchScreenHidReport = false;
            _IsSendingHoveringStateOnTouchScreenHidReport = false;
            _IsSendingEgsGestureHidReport = false;

            WaitTimeInMillisecondsBeforeSetFeatureReport = 2;
            WaitTimeInMillisecondsBeforeGetFeatureReport = 10;

            CreateProperties();

            HidReportsUpdate     = new EgsDeviceHidReportsUpdate();
            TouchScreenHidReport = new EgsDeviceTouchScreenHidReport();
            EgsGestureHidReport  = new EgsDeviceEgsGestureHidReport();

            IsHidDeviceConnectedChanged += UpdateIsHidDeviceConnectedRelatedProperties;

            _Settings = new EgsDeviceSettings();
            _Settings.InitializeOnceAtStartup();
            _Settings.CurrentConnectedEgsDevice = this;
            _Settings.HidAccessPropertyUpdated += EgsDeviceSettings_HidAccessPropertyUpdated;
        }
        public static EgsDevice GetDefaultEgsDevice(EgsDeviceSettings settings)
        {
            var ret = GetDefaultEgsDevice();

            ret.SetSettings(settings);
            return(ret);
        }
        public void UpdateDeviceSettings(EgsDeviceSettings deviceSettings)
        {
            RatioRect RightHandDetectionAreaRatioRect = new RatioRect();
            RatioRect LeftHandDetectionAreaRatioRect  = new RatioRect();

            RightHandDetectionAreaRatioRect.XRange.From = (float)(CaptureImageRightHandDetectionArea.X / CaptureImageWidth);
            RightHandDetectionAreaRatioRect.XRange.To   = (float)((CaptureImageRightHandDetectionArea.X + CaptureImageRightHandDetectionArea.Width) / CaptureImageWidth);
            RightHandDetectionAreaRatioRect.YRange.From = (float)(CaptureImageRightHandDetectionArea.Y / CaptureImageHeight);
            RightHandDetectionAreaRatioRect.YRange.To   = (float)((CaptureImageRightHandDetectionArea.Y + CaptureImageRightHandDetectionArea.Height) / CaptureImageHeight);
            LeftHandDetectionAreaRatioRect.XRange.From  = (float)(CaptureImageLeftHandDetectionArea.X / CaptureImageWidth);
            LeftHandDetectionAreaRatioRect.XRange.To    = (float)((CaptureImageLeftHandDetectionArea.X + CaptureImageLeftHandDetectionArea.Width) / CaptureImageWidth);
            LeftHandDetectionAreaRatioRect.YRange.From  = (float)(CaptureImageLeftHandDetectionArea.Y / CaptureImageHeight);
            LeftHandDetectionAreaRatioRect.YRange.To    = (float)((CaptureImageLeftHandDetectionArea.Y + CaptureImageLeftHandDetectionArea.Height) / CaptureImageHeight);

            var newHandDetectionScaleForEgsDevice = HandDetectionScaleForEgsDevice_DividedBy_CaptureImagePalmImageWidth * CaptureImagePalmImageWidth;

            if (newHandDetectionScaleForEgsDevice > HandDetectionScaleForEgsDeviceMaximum)
            {
                if (false)
                {
                    Debug.WriteLine("newHandDetectionScaleForEgsDevice: " + newHandDetectionScaleForEgsDevice);
                }
            }
            int HandDetectionScaleForEgsDevice = (int)Math.Min(newHandDetectionScaleForEgsDevice, short.MaxValue);

            if (HandDetectionScaleForEgsDevice == 0)
            {
                // TODO: MUSTDO: Test another way.
                if (deviceSettings.IsToDetectHandsOnDevice.Value != false)
                {
                    deviceSettings.IsToDetectHandsOnDevice.Value = false;
                }
            }
            else
            {
                try
                {
                    // It has to set Value property atomically.
                    deviceSettings.RightHandDetectionAreaOnFixed.Value = RightHandDetectionAreaRatioRect;
                    deviceSettings.RightHandDetectionScaleOnFixed.RangedValue.Value = HandDetectionScaleForEgsDevice;
                    deviceSettings.LeftHandDetectionAreaOnFixed.Value = LeftHandDetectionAreaRatioRect;
                    deviceSettings.LeftHandDetectionScaleOnFixed.RangedValue.Value = HandDetectionScaleForEgsDevice;

                    var newIsToDetectHandsOnDevice = deviceSettings.IsToDetectHands.Value;
                    if (deviceSettings.IsToDetectHandsOnDevice.Value != newIsToDetectHandsOnDevice)
                    {
                        deviceSettings.IsToDetectHandsOnDevice.Value = newIsToDetectHandsOnDevice;
                    }
                }
                catch (Exception ex)
                {
                    if (ApplicationCommonSettings.IsDebugging)
                    {
                        Debugger.Break();
                    }
                }
            }
        }
        public void SetSettings(EgsDeviceSettings value)
        {
            Trace.Assert(value != null);

            if (_Settings != null)
            {
                _Settings.HidAccessPropertyUpdated -= EgsDeviceSettings_HidAccessPropertyUpdated;
                _Settings.CurrentConnectedEgsDevice = null;
                _Settings = null;
            }
            value.CurrentConnectedEgsDevice = this;
            value.HidAccessPropertyUpdated += EgsDeviceSettings_HidAccessPropertyUpdated;
            _Settings = value;

            // NOTE: When device is connected and then settings is updated, the app sets the settings from host to device.
            if (IsHidDeviceConnected)
            {
                SetAllSettingsToDeviceAndReadStatusFromDevice();
            }
            TouchScreenHidReport.Reset();
            EgsGestureHidReport.Reset();
        }
Exemple #5
0
        /// <summary>
        /// This class object is not deserializable, and should be created by EgsDevicesManager.
        /// </summary>
        internal EgsDevice()
        {
            _IndexInHidDevicePathList = -1;
            _HidDeviceDevicePath      = "";
            _IsHidDeviceConnected     = false;

            _IsConnected = false;

            _IsUpdatingFirmware = false;

            _IsSendingTouchScreenHidReport = false;
            _IsSendingHoveringStateOnTouchScreenHidReport = false;
            _IsSendingEgsGestureHidReport = false;

            WaitTimeInMillisecondsBeforeSetFeatureReport = 2;
            WaitTimeInMillisecondsBeforeGetFeatureReport = 10;

            CreateProperties();

            if (IsToUseWin32CreateFile)
            {
                HidReportsUpdate = new EgsDeviceHidReportsUpdate();
            }
            TouchScreenHidReport = new EgsDeviceTouchScreenHidReport();
            EgsGestureHidReport  = new EgsDeviceEgsGestureHidReport();

            IsHidDeviceConnectedChanged += UpdateIsHidDeviceConnectedRelatedProperties;

            CameraViewImageSourceBitmapCapture = new EgsDeviceCameraViewImageSourceBitmapCapture();
            FaceDetectionOnHost = new EgsDeviceFaceDetectionOnHost();
            CameraViewImageSourceBitmapCapture.IsCameraDeviceConnectedChanged += UpdateIsConnected;

            _Settings = new EgsDeviceSettings();
            _Settings.InitializeOnceAtStartup();
            _Settings.CurrentConnectedEgsDevice = this;
            _Settings.HidAccessPropertyUpdated += EgsDeviceSettings_HidAccessPropertyUpdated;
        }