/// 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(); }
public void StartScan() { if (!IsReady.Value) { return; } StartTime = DateTimeOffset.Now; qRCodeWatcher.Start(); }
private void StartTracking() { if (!_watching) { if (_listener == null) { // make sure C++ is init RclCppDotnet.Init(); _listener = new TransformListener(); } _watching = true; _qrWatcher?.Start(); } }
public void StartQRTracking() { if (qrTracker != null && !IsTrackerRunning) { Debug.Log("QRCodesManager starting QRCodeWatcher"); try { qrTracker.Start(); IsTrackerRunning = true; QRCodesTrackingStateChanged?.Invoke(this, true); } catch (Exception ex) { Debug.Log("QRCodesManager starting QRCodeWatcher Exception:" + ex.ToString()); } } }
/// <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")}"); }
public override void Enable() { base.Enable(); if (!IsInitialized) { return; } try { qrTracker.Start(); IsTracking = true; SendProgressMessage("Enabled tracking"); } catch (Exception ex) { InitializationFail($"QRCodeTrackingService starting QRCodeWatcher Exception: {ex}"); } }
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)); }