public override async void Initialize() { if (QRCodeWatcher.IsSupported()) { #if WINDOWS_UWP try { var capture = new Windows.Media.Capture.MediaCapture(); await capture.InitializeAsync(); Debug.Log("Camera and Microphone permissions OK"); } catch (UnauthorizedAccessException) { Debug.LogError("Camera and microphone permissions not granted."); return; } #endif if (await QRCodeWatcher.RequestAccessAsync() == QRCodeWatcherAccessStatus.Allowed) { _qrWatcher = new QRCodeWatcher();; _qrWatcher.Added += OnQRCodeAddedEvent; _qrWatcher.Updated += OnQRCodeUpdatedEvent; _qrWatcher.Removed += OnQRCodeRemovedEvent; _qrWatcher.EnumerationCompleted += OnQREnumerationEnded; } } }
async protected virtual void Start() { IsSupported = QRCodeWatcher.IsSupported(); capabilityTask = QRCodeWatcher.RequestAccessAsync(); accessStatus = await capabilityTask; capabilityInitialized = true; }
async void Start() { IsSupported = QRCodeWatcher.IsSupported(); await QRCodeWatcher.RequestAccessAsync(); qRCodeWatcher = new QRCodeWatcher(); qRCodeWatcher.Added += QRCodeWatcher_Added; qRCodeWatcher.Updated += QRCodeWatcher_Updated; qRCodeWatcher.Removed += QRCodeWatcher_Removed; IsReady.Value = true; this.UpdateAsObservable() .Subscribe(_ => { if (pendingActions.TryDequeue(out var action)) { if (action.Type == ActionData.EventType.Added || action.Type == ActionData.EventType.Updated) { if (DateTimeOffset.Compare(StartTime, action.QRCode.LastDetectedTime) < 0) { onScanned.OnNext(action.QRCode); } } } }) .AddTo(this); }
/// Initialization is just a matter of asking for permission, and then /// hooking up to the `QRCodeWatcher`'s events. `QRCodeWatcher.RequestAccessAsync` /// is an async call, so you could re-arrange this code to be non-blocking! /// /// You'll also notice there's some code here for filtering out QR codes. /// The default behavior for the QR code library is to provide all QR /// codes that it knows about, and that includes ones that were found /// before the session began. We don't need that, so we're ignoring those. public void Initialize() { // Ask for permission to use the QR code tracking system var status = QRCodeWatcher.RequestAccessAsync().Result; if (status != QRCodeWatcherAccessStatus.Allowed) { return; } // Set up the watcher, and listen for QR code events. watcherStart = DateTime.Now; watcher = new QRCodeWatcher(); watcher.Added += (o, qr) => { // QRCodeWatcher will provide QR codes from before session start, // so we often want to filter those out. if (qr.Code.LastDetectedTime > watcherStart) { poses.Add(qr.Code.Id, QRData.FromCode(qr.Code)); } }; watcher.Updated += (o, qr) => poses[qr.Code.Id] = QRData.FromCode(qr.Code); watcher.Removed += (o, qr) => poses.Remove(qr.Code.Id); watcher.Start(); }
// Use this for initialization protected virtual void Start() { IsSupported = QRCodeWatcher.IsSupported(); #if !UNITY_EDITOR RequestCapability(); #endif }
/// <summary> /// Record whether the QRCodeWatcher reports itself as supported, and request access. /// </summary> private async void Start() { _isSupported = QRCodeWatcher.IsSupported(); _capabilityTask = QRCodeWatcher.RequestAccessAsync(); _accessStatus = await _capabilityTask; _capabilityInitialized = true; SimpleConsole.AddLine(log, $"Requested caps, access: {_accessStatus.ToString()}"); }
/// <summary> /// Record whether the QRCodeWatcher reports itself as supported, and request access. /// </summary> private async void Start() { isSupported = QRCodeWatcher.IsSupported(); var capabilityTask = QRCodeWatcher.RequestAccessAsync(); accessStatus = await capabilityTask; SimpleConsole.AddLine(log, $"Requested caps, access: {accessStatus.ToString()}"); }
private void SetupTracking() { qrTracker = new QRCodeWatcher(); qrTracker.Updated += QRCodeWatcher_Updated; IsInitialized = true; Initialized?.Invoke(this, new EventArgs()); SendProgressMessage("QR tracker initialized"); }
// Use this for initialization async protected virtual void Start() { IsSupported = QRCodeWatcher.IsSupported(); capabilityTask = QRCodeWatcher.RequestAccessAsync(); accessStatus = await capabilityTask; capabilityInitialized = true; //AROA EDIT //qrCodesList.Clear();//Clear list on initialization }
async private void RequestCapability() { // Windows.Security.Authorization.AppCapabilityAccess.AppCapability cap = Windows.Security.Authorization.AppCapabilityAccess.AppCapability.Create("webcam"); // accessStatus = await cap.RequestAccessAsync(); accessStatus = await QRCodeWatcher.RequestAccessAsync(); capabilityInitialized = true; }
/// <summary> /// Deregister from the QRCodeWatcher and shut down the instance. /// </summary> private void TearDownQRWatcher() { if (qrWatcher != null) { qrWatcher.Stop(); qrWatcher.Added -= OnQRCodeAddedEvent; qrWatcher.Updated -= OnQRCodeUpdatedEvent; qrWatcher.Removed -= OnQRCodeRemovedEvent; qrWatcher.EnumerationCompleted -= OnQREnumerationEnded; qrWatcher = null; } }
/// <summary> /// Record whether the QRCodeWatcher reports itself as supported, and request access. /// </summary> /// <remarks> /// If the camera permission has not already been granted (GetPermissions has successfully completed), /// then the call to QRCodeWather.RequestAccessAsync will never return, even after the user grants permissions. /// See https://github.com/microsoft/MixedReality-WorldLockingTools-Samples/issues/20 /// </remarks> private async void Start() { isSupported = QRCodeWatcher.IsSupported(); SimpleConsole.AddLine(log, $"QRCodeWatcher.IsSupported={isSupported}"); bool gotPermission = await GetPermissions(); if (gotPermission) { var capabilityTask = QRCodeWatcher.RequestAccessAsync(); accessStatus = await capabilityTask; SimpleConsole.AddLine(log, $"Requested caps, access: {accessStatus.ToString()}"); } }
private async void GetAccessStatus() { if (IsSupported && (!_capabilityInitialized || _accessStatus != QRCodeWatcherAccessStatus.Allowed)) { if (_currentTime <= _maxTime) { _currentTime += Time.deltaTime; return; } _currentTime = 0; _capabilityTask = QRCodeWatcher.RequestAccessAsync(); _accessStatus = await _capabilityTask; _capabilityInitialized = true; } }
/// <summary> /// Create the QRCodeWatcher instance and register for the events to be transported to the main thread. /// </summary> private void SetUpQRWatcher() { try { qrWatcher = new QRCodeWatcher(); qrWatcher.Added += OnQRCodeAddedEvent; qrWatcher.Updated += OnQRCodeUpdatedEvent; qrWatcher.Removed += OnQRCodeRemovedEvent; qrWatcher.EnumerationCompleted += OnQREnumerationEnded; qrWatcher.Start(); } catch (System.Exception e) { Debug.LogError($"Failed to start QRCodeWatcher, error: {e.Message}"); } SimpleConsole.AddLine(log, $"SetUpQRWatcher {(qrWatcher != null ? "Success" : "Failed")}"); }
private void SetupQRTracking() { try { qrTracker = new QRCodeWatcher(); IsTrackerRunning = false; qrTracker.Added += QRCodeWatcher_Added; qrTracker.Updated += QRCodeWatcher_Updated; qrTracker.Removed += QRCodeWatcher_Removed; qrTracker.EnumerationCompleted += QRCodeWatcher_EnumerationCompleted; } catch (Exception ex) { Debug.Log("QRCodesManager : exception starting the tracker " + ex.ToString()); } if (AutoStartQRTracking) { StartQRTracking(); } }
private async Task <QRCodeWatcherAccessStatus> StartQRWatchingAsyncImpl(CancellationToken token) { QRCodeWatcherAccessStatus accessStatus = QRCodeWatcherAccessStatus.DeniedBySystem; #if WINDOWS_UWP DebugLog("Requesting QRCodeWatcher capability"); accessStatus = await QRCodeWatcher.RequestAccessAsync(); if (accessStatus != QRCodeWatcherAccessStatus.Allowed) { DebugLog("Failed to obtain QRCodeWatcher capability. QR Codes will not be detected"); } else { DebugLog("QRCodeWatcher capability granted."); } #endif if (accessStatus == QRCodeWatcherAccessStatus.Allowed) { // Note: If the QRCodeWatcher is created prior to obtaining the QRCodeWatcher capability, initialization will fail. if (qrWatcher == null) { DebugLog("Creating qr tracker"); qrWatcher = new QRCodeWatcher(); qrWatcher.Added += QRWatcherAdded; qrWatcher.Updated += QRWatcherUpdated; qrWatcher.Removed += QRWatcherRemoved; } if (!token.IsCancellationRequested && !IsWatcherRunning) { qrWatcher.Start(); IsWatcherRunning = true; } } return(await Task.FromResult(accessStatus)); }
private async Task InitializeTracker() { try { IsSupported = QRCodeWatcher.IsSupported(); if (IsSupported) { SendProgressMessage($"Initializing QR tracker attempt {++initializationAttempt}"); var capabilityTask = QRCodeWatcher.RequestAccessAsync(); await capabilityTask.AwaitWithTimeout(profile.AccessRetryTime, ProcessTrackerCapabilityReturned, () => _ = InitializeTracker()); } else { InitializationFail("QR tracking not supported"); } } catch (Exception ex) { InitializationFail($"QRCodeTrackingService initialization failed: {ex}"); } }