Пример #1
0
        /// <summary>
        /// The entry point of a background task.
        /// </summary>
        /// <param name="taskInstance">The current background task instance.</param>
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("Background " + taskInstance.Task.Name + " Starting...");

            // Associate a cancellation handler with the background task.
            // Even though this task isn't performing much work, it can still be canceled.
            taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);

            // Read the sensor readings from the trigger reports
            SensorDataThresholdTriggerDetails triggerDetails = taskInstance.TriggerDetails as SensorDataThresholdTriggerDetails;

            // Ensure the type of trigger we are dealing with is of type 'ProximitySensor'
            if (SensorType.ProximitySensor == triggerDetails.SensorType)
            {
                var reports     = ProximitySensor.GetReadingsFromTriggerDetails(triggerDetails);
                var settings    = ApplicationData.Current.LocalSettings;
                var lastReading = reports[reports.Count - 1];

                // cache appropriate details from this trigger in application data
                settings.Values["ReportCount"]   = reports.Count.ToString();
                settings.Values["LastTimestamp"] = lastReading.Timestamp.ToString("u");
                settings.Values["Detected"]      = lastReading.IsDetected.ToString();
                settings.Values["TaskStatus"]    = "Completed at " + DateTime.Now.ToString("u");
            }

            // No deferral is held on taskInstance because we are returning immediately.
        }
Пример #2
0
 public void Start()
 {
     wallSensors   = sensors.wallSensors;
     vision        = sensors.visionSensor;
     harpoonSensor = sensors.harpoonSensor;
     EnvironmentManager.ActiveFishes.Add(gameObject);
 }
Пример #3
0
        /// <summary>
        /// Invoked when the device watcher detects that the proximity sensor was added.
        /// </summary>
        /// <param name="sender">The device watcher.</param>
        /// <param name="device">The device that was added.</param>
        private async void OnProximitySensorAddedAsync(DeviceWatcher sender, DeviceInformation device)
        {
            if (this.proximitySensor == null)
            {
                var addedSensor = ProximitySensor.FromId(device.Id);

                if (addedSensor != null)
                {
                    var minimumDistanceSatisfied = true;

                    //if we care about minimum distance
                    if (this.MinimumDistanceInMillimeters > Int32.MinValue)
                    {
                        if ((this.MinimumDistanceInMillimeters > addedSensor.MaxDistanceInMillimeters) ||
                            (this.MinimumDistanceInMillimeters < addedSensor.MinDistanceInMillimeters))
                        {
                            minimumDistanceSatisfied = false;
                        }
                    }

                    if (minimumDistanceSatisfied)
                    {
                        this.proximitySensor = addedSensor;

                        await SetActiveFromReadingAsync(this.proximitySensor.GetCurrentReading());

                        this.proximitySensor.ReadingChanged += ProximitySensor_ReadingChangedAsync;
                    }
                }
            }
        }
        /// <summary>
        /// Invoked when the device watcher detects that the proximity sensor was added.
        /// </summary>
        /// <param name="sender">The device watcher.</param>
        /// <param name="device">The device that was added.</param>
        private async void OnProximitySensorAddedAsync(DeviceWatcher sender, DeviceInformation device)
        {
            if (this.proximitySensor == null)
            {
                var addedSensor = ProximitySensor.FromId(device.Id);

                if (addedSensor != null)
                {
                    var minimumDistanceSatisfied = true;

                    //if we care about minimum distance
                    if (this.MinimumDistanceInMillimeters > Int32.MinValue)
                    {
                        if ((this.MinimumDistanceInMillimeters > addedSensor.MaxDistanceInMillimeters) ||
                            (this.MinimumDistanceInMillimeters < addedSensor.MinDistanceInMillimeters))
                        {
                            minimumDistanceSatisfied = false;
                        }
                    }

                    if (minimumDistanceSatisfied)
                    {
                        this.proximitySensor = addedSensor;

                        await SetActiveFromReadingAsync(this.proximitySensor.GetCurrentReading());

                        this.proximitySensor.ReadingChanged += ProximitySensor_ReadingChangedAsync;
                    }
                }
            }
        }
    /*
     *  Uses Factory pattern and polymorphism to return the desired
     *  Sensor type.
     */
    public static Sensors GetInstance(int sensorType, GameObject gObj)
    {
        Cube = gObj;
        Sensors _sensor;

        switch (sensorType)
        {
        case 1: _sensor = new ProximitySensor();
            break;

        case 2: _sensor = new RangeSensor();
            break;

        case 3: _sensor = new LidarSensor();
            break;

        case 4: _sensor = new RadarSensor();
            break;

        case 5: _sensor = new BumperSensor();
            break;

        default: Debug.Log("The chosen sensor doesn't exist!");
            _sensor = new ProximitySensor();
            break;
        }
        sensors = _sensor;
        return(sensors);
    }
Пример #6
0
        public static async Task Initialize()
        {
            DeviceInformationCollection devices;

            CallManager = await CallManager.GetSystemPhoneCallManagerAsync();

            CallStore = await PhoneCallManager.RequestStoreAsync();

            CallHistoryStore = await PhoneCallHistoryManager.RequestStoreAsync(PhoneCallHistoryStoreAccessType.AllEntriesReadWrite);

            devices = await DeviceInformation.FindAllAsync(ProximitySensor.GetDeviceSelector());

            ProximitySensor = devices.Count > 0 ? ProximitySensor.FromId(devices.First().Id) : null;
            VibrationAccessStatus accessStatus = await VibrationDevice.RequestAccessAsync();

            if (accessStatus == VibrationAccessStatus.Allowed)
            {
                VibrationDevice = await VibrationDevice.GetDefaultAsync();
            }
            try
            {
                DefaultLine = await PhoneLine.FromIdAsync(await CallStore.GetDefaultLineAsync());
            }
            catch
            {
            }
            Initialized = true;
        }
Пример #7
0
 /// <summary>
 /// Invoked when the device watcher finds a proximity sensor
 /// </summary>
 /// <param name="sender">The device watcher</param>
 /// <param name="device">Device information for the proximity sensor that was found</param>
 private void OnProximitySensorAdded(Windows.Devices.Enumeration.DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformation device)
 {
     if (_sensor == null && ProximitySensor.FromId(device.Id) is ProximitySensor foundSensor)
     {
         _sensor = foundSensor;
     }
 }
Пример #8
0
        private static bool InShortRange(BotController myself, BotController target)
        {
            ProximitySensor proxSensor = myself.GetComponentInChildren <ProximitySensor>();
            float           minRange   = proxSensor != null ? proxSensor.minRange : 0;

            return(DistanceBetween(myself, target, minRange, shortToMediumRange));
        }
        public Scenario1_DataEvents()
        {
            this.InitializeComponent();

            watcher        = DeviceInformation.CreateWatcher(ProximitySensor.GetDeviceSelector());
            watcher.Added += OnProximitySensorAdded;
            watcher.Start();
        }
Пример #10
0
        public ProximityStateTrigger()
        {
            var watcher = DeviceInformation.CreateWatcher(ProximitySensor.GetDeviceSelector());

            watcher.Added   += OnProximitySensorAddedAsync;
            watcher.Removed += OnProximitySensorRemoved;
            watcher.Start();
        }
 /// <summary>
 /// Constructor of ProximitySensorAdapter.
 /// </summary>
 public ProximitySensorAdapter()
 {
     sensor = new ProximitySensor
     {
         Interval    = 100,
         PausePolicy = SensorPausePolicy.None
     };
 }
Пример #12
0
 public void LoadProximitySensor(UDP ethernet)
 {
     ethernet.ProximityActions.Add((ProximitySensor) =>
     {
         this.ProximitySensor        = ProximitySensor;
         this.NewProximitySensorData = true;
     });
 }
Пример #13
0
 public GhoulAI(Settings settings, ProximitySensor sensor, CharacterMotor motor, FaceDirection faceDirection, Pushback pushback)
 {
     _sensor        = sensor;
     _motor         = motor;
     _faceDirection = faceDirection;
     _settings      = settings;
     _pushback      = pushback;
 }
Пример #14
0
 public EnemyAttackAI(ProximitySensor sensor, Attack attack, Settings settings, FaceDirection faceDirection, [Inject(Id = InjectId.Owner)] GameObject owner)
 {
     _sensor        = sensor;
     _attack        = attack;
     _settings      = settings;
     _owner         = owner;
     _faceDirection = faceDirection;
 }
Пример #15
0
        public List <DeviceInfo> CreateList()
        {
            List <DeviceInfo> selectors = new List <DeviceInfo>();

            // Pre-canned device class selectors
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "All Device Interfaces (default)", DeviceClassSelector = DeviceClass.All, Selection = null
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Audio Capture", DeviceClassSelector = DeviceClass.AudioCapture, Selection = null
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Audio Render", DeviceClassSelector = DeviceClass.AudioRender, Selection = null
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Image Scanner", DeviceClassSelector = DeviceClass.ImageScanner, Selection = null
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Location", DeviceClassSelector = DeviceClass.Location, Selection = null
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Portable Storage", DeviceClassSelector = DeviceClass.PortableStorageDevice, Selection = null
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Video Capture", DeviceClassSelector = DeviceClass.VideoCapture, Selection = null
            });

            // A few examples of selectors built dynamically by windows runtime apis.
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Human Interface (HID)", Selection = HidDevice.GetDeviceSelector(0, 0)
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Activity Sensor", Selection = ActivitySensor.GetDeviceSelector()
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Pedometer", Selection = Pedometer.GetDeviceSelector()
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Proximity", Selection = ProximityDevice.GetDeviceSelector()
            });
            selectors.Add(new DeviceInfo()
            {
                DisplayName = "Proximity Sensor", Selection = ProximitySensor.GetDeviceSelector()
            });

            return(selectors);
        }
Пример #16
0
 public GolemDeath(FaceDirection faceDirection, Life life, ProximitySensor sensor,
                   EnemyAttackAI attackAi, [Inject(Id = InjectId.Owner)] GameObject owner)
 {
     _life          = life;
     _sensor        = sensor;
     _attackAi      = attackAi;
     _faceDirection = faceDirection;
     _collider      = owner.GetComponent <Collider2D>();
 }
Пример #17
0
        /// <summary>
        /// Invoked when the device watcher finds a proximity sensor
        /// </summary>
        /// <param name="sender">The device watcher</param>
        /// <param name="device">Device information for the proximity sensor that was found</param>
        private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
        {
            if (null == sensor)
            {
                ProximitySensor foundSensor = ProximitySensor.FromId(device.Id);
                if (null != foundSensor)
                {
                    if (null != foundSensor.MaxDistanceInMillimeters)
                    {
                        // Check if this is the sensor that matches our ranges.

                        // TODO: Customize these values to your application's needs.
                        // Here, we are looking for a sensor that can detect close objects
                        // up to 3cm away, so we check the upper bound of the detection range.
                        const uint distanceInMillimetersLValue = 30; // 3 cm
                        const uint distanceInMillimetersRValue = 50; // 5 cm

                        if (foundSensor.MaxDistanceInMillimeters >= distanceInMillimetersLValue &&
                            foundSensor.MaxDistanceInMillimeters <= distanceInMillimetersRValue)
                        {
                            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                rootPage.NotifyUser("Found a proximity sensor that meets the detection range", NotifyType.StatusMessage);
                            });
                        }
                        else
                        {
                            // We'll use the sensor anyway, to demonstrate how events work.
                            // Your app may decide not to use the sensor.
                            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                rootPage.NotifyUser("Proximity sensor does not meet the detection range, using it anyway", NotifyType.StatusMessage);
                            });
                        }
                    }
                    else
                    {
                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            rootPage.NotifyUser("Proximity sensor does not report detection ranges, using it anyway", NotifyType.StatusMessage);
                        });
                    }

                    if (null != foundSensor)
                    {
                        sensor = foundSensor;
                    }
                }
                else
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
                    });
                }
            }
        }
Пример #18
0
 void Start()
 {
     movement.Throttle = 1f;
     proximitySensor   = shipSensors.visionSensor;
     wallSensors       = shipSensors.wallSensors;
     environment       = GameObject.FindGameObjectWithTag("GameManager").GetComponent <EnvironmentManager>();
     // bootstrap intention and tell other ships I'm here
     TryFindWhale(true);
 }
Пример #19
0
        /// <summary>
        /// Invoked when the device watcher detects that the proximity sensor was removed.
        /// </summary>
        /// <param name="sender">The device watcher.</param>
        /// <param name="device">The device that was removed.</param>
        private void OnProximitySensorRemoved(DeviceWatcher sender, DeviceInformationUpdate device)
        {
            if ((this.proximitySensor != null) && (this.proximitySensor.DeviceId == device.Id))
            {
                this.proximitySensor.ReadingChanged -= ProximitySensor_ReadingChangedAsync;
                this.proximitySensor = null;

                SetActive(false);
            }
        }
Пример #20
0
 // Start is called before the first frame update
 void Start()
 {
     closestShip     = null;
     previousHarpoon = null;
     wallSensors     = sensors.wallSensors;
     vision          = sensors.visionSensor;
     harpoonSensor   = sensors.harpoonSensor;
     environment     = GameObject.FindGameObjectWithTag("GameManager").GetComponent <EnvironmentManager>();
     movement.Speed  = 1;
 }
        /// <summary>
        /// Invoked when the device watcher detects that the proximity sensor was removed.
        /// </summary>
        /// <param name="sender">The device watcher.</param>
        /// <param name="device">The device that was removed.</param>
        private void OnProximitySensorRemoved(DeviceWatcher sender, DeviceInformationUpdate device)
        {
            if ((this.proximitySensor != null) && (this.proximitySensor.DeviceId == device.Id))
            {
                this.proximitySensor.ReadingChanged -= ProximitySensor_ReadingChangedAsync;
                this.proximitySensor = null;

                SetActive(false);
            }
        }
Пример #22
0
 public GhoulDeath([Inject(Id = InjectId.Owner)] GameObject owner, Settings settings,
                   Life life, Attack attack, FaceDirection faceDirection, GhoulAI ghoulAi, ProximitySensor sensor)
 {
     _owner         = owner;
     _settings      = settings;
     _life          = life;
     _faceDirection = faceDirection;
     _attack        = attack;
     _ghoulAi       = ghoulAi;
     _sensor        = sensor;
     _collider      = owner.GetComponent <Collider2D>();
 }
Пример #23
0
        public override async Task Start()
        {
            switch (SelectedSensor)
            {
            case "VCNL4010":
                Sensor = new Vcnl4010(Board.I2c);
                break;
            }

            Sensor.AutoUpdateWhenPropertyRead = false;
            OnPropertyChanged(nameof(Sensor));
        }
Пример #24
0
        /// <summary>Initializes the upper proximity sensor</summary>
        private static void InitializeUpperProximitySensor()
        {
            DisplayInitializationMessage("Upper Sensor");

            var upperProximitySensorInput = new AnalogInput(Cpu.AnalogChannel.ANALOG_0);

            UpperProximitySensor = new ProximitySensor(ProximitySensorType.GP2Y0A21YK, upperProximitySensorInput)
            {
                IsEnabled = true,
                ObjectDetectionTrigger =
                    (maximumReadableDistance, distance) => distance < maximumReadableDistance,
            };
            UpperProximitySensor.ObjectDetected += OnObjectDetected;
        }
        void Start()
        {
            _sensor = GetComponentInParent <ProximitySensor>();
            Assert.IsNotNull(_sensor);

            _animator = GetComponent <Animator>();
            Assert.IsNotNull(_animator);

            _life.OnDead += onDead;

            _sensor.ReadySensor.OnEnterSensor += onEnterReadySensor;
            _sensor.ReadySensor.OnLeaveSensor += onLeaveReadySensor;
            _life.OnResurrect += () => { _animator.SetTrigger("Alive"); };
        }
Пример #26
0
 /// <summary>
 /// Invoked when the device watcher finds a proximity sensor
 /// </summary>
 /// <param name="sender">The device watcher</param>
 /// <param name="device">Device information for the proximity sensor that was found</param>
 private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
 {
     if (null == sensor)
     {
         sensor = ProximitySensor.FromId(device.Id);
         if (null == sensor)
         {
             // failed to find the sensor corresponding to the id
             await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
             });
         }
     }
 }
 /// <summary>
 /// Invoked when the device watcher finds a proximity sensor
 /// </summary>
 /// <param name="sender">The device watcher</param>
 /// <param name="device">Device information for the proximity sensor that was found</param>
 private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
 {
     if (null == sensor)
     {
         sensor = ProximitySensor.FromId(device.Id);
         if (null == sensor)
         {
             // failed to find the sensor corresponding to the id
             await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
             });
         }
     }
 }
Пример #28
0
        private async Task AttachAsync()
        {
            if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1))
            {
                var devices = await DeviceInformation.FindAllAsync(ProximitySensor.GetDeviceSelector());

                if (devices.Count > 0)
                {
                    _sensor = ProximitySensor.FromId(devices[0].Id);
                    //_sensor.ReadingChanged += OnReadingChanged;

                    _controller = _sensor.CreateDisplayOnOffController();
                }
            }
        }
Пример #29
0
        public ProximityPage()
        {
            Model = new ProximityModel
            {
                IsSupported = ProximitySensor.IsSupported,
                SensorCount = ProximitySensor.Count
            };

            InitializeComponent();

            if (Model.IsSupported)
            {
                Proximity              = new ProximitySensor();
                Proximity.DataUpdated += Proximity_DataUpdated;
            }
        }
Пример #30
0
        public ProximitySensorExample()
        {
            var sensor = new ProximitySensor(Connectors.GPIO17);

            sensor.PresenceStatusChanged += (active) => {
                count++;
                Console.WriteLine($"PresenceStatusChanged {3}. {0}/{1}", count, max, active);
            };

            while (count < max)
            {
                sensor.OnUpdate();
                Thread.Sleep(250);
            }
            sensor.OnDispose();
        }
Пример #31
0
 private void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation args)
 {
     if (_sensor == null)
     {
         ProximitySensor foundSensor = ProximitySensor.FromId(args.Id);
         if (foundSensor != null)
         {
             _sensor = foundSensor;
         }
         else
         {
             // No proximity sensor found
             Debug.WriteLine("No proximity sensor found");
         }
     }
 }
Пример #32
0
        public Agent()
        {
            // create the short range sensor for wall following
            shortRangeSensor = new ProximitySensor(10, 10, 90);

            // Create the bumper sensor
            bumperSensor = new Bumper(12, 130);

            // create the movement interface
            movement = new Movement();

            // create the cleaning module
            cleaner = new Cleaner();

            random = new Random();
        }
 /// <summary>
 /// Invoked when the device watcher finds a proximity sensor
 /// </summary>
 /// <param name="sender">The device watcher</param>
 /// <param name="device">Device information for the proximity sensor that was found</param>
 private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
 {
     if (null == sensor)
     {
         ProximitySensor foundSensor = ProximitySensor.FromId(device.Id);
         if (null != foundSensor)
         {
             sensor = foundSensor;
         }
         else
         {
             await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
             });
         }
     }
 }
 /// <summary>
 /// Invoked when the device watcher finds a proximity sensor
 /// </summary>
 /// <param name="sender">The device watcher</param>
 /// <param name="device">Device information for the proximity sensor that was found</param>
 private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
 {
     if (null == sensor)
     {
         ProximitySensor foundSensor = ProximitySensor.FromId(device.Id);
         if (null != foundSensor)
         {
             sensor = foundSensor;
         }
         else
         {
             await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
             });
         }
     }
 }
        /// <summary>
        /// This is the event handler for ReadingChanged events.
        /// </summary>
        /// <param name="sender">The proximity sensor that sent the reading change</param>
        /// <param name="e"></param>
        async private void ReadingChanged(ProximitySensor sender, ProximitySensorReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                ProximitySensorReading reading = e.Reading;
                if (null != reading)
                {
                    ScenarioOutput_DetectionState.Text = reading.IsDetected ? "Detected" : "Not detected";
                    ScenarioOutput_Timestamp.Text      = reading.Timestamp.ToString("u");

                    // Show the detection distance, if available
                    if (null != reading.DistanceInMillimeters)
                    {
                        ScenarioOutput_DetectionDistance.Text = reading.DistanceInMillimeters.ToString();
                    }
                }
            });
        }
 /// <summary>
 /// Invoked when the device watcher finds a proximity sensor
 /// </summary>
 /// <param name="sender">The device watcher</param>
 /// <param name="device">Device information for the proximity sensor that was found</param>
 private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
 {
     if (null == sensor)
     {
         ProximitySensor foundSensor = ProximitySensor.FromId(device.Id);
         if (null != foundSensor)
         {
             // Optionally check the ProximitySensor.MaxDistanceInCentimeters/MinDistanceInCentimeters
             // properties here. Refer to Scenario 1 for details.
             sensor = foundSensor;
         }
         else
         {
             await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
                 rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
             });
         }
     }
 }
Пример #37
0
 private async void Sensor_ReadingChanged(ProximitySensor sender, ProximitySensorReadingChangedEventArgs e)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
     {
         ProximitySensorReading reading = e.Reading;
         if (null != reading)
         {
             if (reading.IsDetected)
             {
                 //hide status bar
                 if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
                 {
                     var statusBar = StatusBar.GetForCurrentView();
                     await statusBar.HideAsync();
                 }
                 //enable timer
                 timer.Change(4000, 4000);
                 Overlay_RecordingTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                 Overlay_RecordingTextBlock.Text = "Recording...";
                 Overlay_RecordingTextBlock.Visibility = Visibility.Visible;
                 Overlay_Grid.Visibility = Visibility.Visible;
                 await Task.Delay(1000);
                 Overlay_RecordingTextBlock.Visibility = Visibility.Collapsed;
             }
             else
             {
                 if (isRecording)
                 {
                     //disable timer
                     timer.Change(Timeout.Infinite, 4000);
                     Overlay_RecordingTextBlock.Foreground = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));
                     Overlay_RecordingTextBlock.Text = "Done...";
                     Overlay_RecordingTextBlock.Visibility = Visibility.Visible;
                     await Task.Delay(1000);
                     Overlay_Grid.Visibility = Visibility.Collapsed;
                     await StopRecordingAsync();
                     isRecording = false;
                 }
                 else
                 {
                     timer.Change(Timeout.Infinite, 4000);
                     Overlay_RecordingTextBlock.Foreground = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));
                     Overlay_RecordingTextBlock.Text = "Canceled...";
                     Overlay_RecordingTextBlock.Visibility = Visibility.Visible;
                     await Task.Delay(1000);
                     Overlay_Grid.Visibility = Visibility.Collapsed;
                     isRecording = false;
                 }
             }
         }
     });
 }
        /// <summary>
        /// This is the event handler for ReadingChanged events.
        /// </summary>
        /// <param name="sender">The proximity sensor that sent the reading change</param>
        /// <param name="e"></param>
        async private void ReadingChanged(ProximitySensor sender, ProximitySensorReadingChangedEventArgs e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                ProximitySensorReading reading = e.Reading;
                if (null != reading)
                {
                    ScenarioOutput_DetectionState.Text = reading.IsDetected ? "Detected" : "Not detected";
                    ScenarioOutput_Timestamp.Text = reading.Timestamp.ToString("u");

                    // Show the detection distance, if available
                    if (null != reading.DistanceInMillimeters)
                    {
                        ScenarioOutput_DetectionDistance.Text = reading.DistanceInMillimeters.ToString();
                    }
                }
            });
        }
        /// <summary>
        /// Invoked when the device watcher finds a proximity sensor
        /// </summary>
        /// <param name="sender">The device watcher</param>
        /// <param name="device">Device information for the proximity sensor that was found</param>
        private async void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
        {
            if (null == sensor)
            {
                ProximitySensor foundSensor = ProximitySensor.FromId(device.Id);
                if (null != foundSensor)
                {
                    if (null != foundSensor.MaxDistanceInMillimeters)
                    {
                        // Check if this is the sensor that matches our ranges.

                        // TODO: Customize these values to your application's needs.
                        // Here, we are looking for a sensor that can detect close objects
                        // up to 3cm away, so we check the upper bound of the detection range.
                        const uint distanceInMillimetersLValue = 30; // 3 cm
                        const uint distanceInMillimetersRValue = 50; // 5 cm

                        if (foundSensor.MaxDistanceInMillimeters >= distanceInMillimetersLValue &&
                            foundSensor.MaxDistanceInMillimeters <= distanceInMillimetersRValue)
                        {
                            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                rootPage.NotifyUser("Found a proximity sensor that meets the detection range", NotifyType.StatusMessage);
                            });
                        }
                        else
                        {
                            foundSensor = null;
                        }
                    }
                    else
                    {
                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                        {
                            rootPage.NotifyUser("Proximity sensor does not report detection ranges, using it anyway", NotifyType.StatusMessage);
                        });
                    }

                    if (null != foundSensor)
                    {
                        sensor = foundSensor;
                    }
                }
                else
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        rootPage.NotifyUser("Could not get a proximity sensor from the device id", NotifyType.ErrorMessage);
                    });
                }
            }
        }
Пример #40
0
 private void OnProximitySensorAdded(DeviceWatcher sender, DeviceInformation device)
 {
     if (null == sensor)
     {
         ProximitySensor foundSensor = ProximitySensor.FromId(device.Id);
         if (null != foundSensor)
         {
             sensor = foundSensor;
             sensor.ReadingChanged += Sensor_ReadingChanged;
         }
         else
         {
             Debug.WriteLine("device has no proximity sensor");
         }
     }
 }
 /// <summary>
 /// Invoked when ProximitySensor reading changed event gets raised.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private async void ProximitySensor_ReadingChangedAsync(ProximitySensor sender, ProximitySensorReadingChangedEventArgs args)
 {
     await SetActiveFromReadingAsync(args.Reading);
 }
 public ProximitySensorEvents(ProximitySensor This)
 {
     this.This = This;
 }