private void OnDeviceStatusChanged(object sender, DeviceStatusChangedEventArgs e) { var ignore = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { switch (e.Status) { case DeviceStatus.Idle: textBlockStatus.Text = AppObjects.GetStringForDeviceStatus(e.Status); buttonFileTransfer.IsEnabled = true; buttonRealTime.IsEnabled = true; break; case DeviceStatus.ExpectingConnectionConfirmation: textBlockStatus.Text = AppObjects.GetStringForDeviceStatus(e.Status); buttonFileTransfer.IsEnabled = false; buttonRealTime.IsEnabled = false; break; case DeviceStatus.NotAuthorizedConnectionNotConfirmed: await new MessageDialog(AppObjects.GetStringForDeviceStatus(e.Status)).ShowAsync(); Frame.Navigate(typeof(ScanAndConnectPage)); break; default: textBlockStatus.Text = AppObjects.GetStringForDeviceStatus(e.Status); break; } }); }
private void OnDeviceStatusChanged(object sender, DeviceStatusChangedEventArgs e) { IDigitalInkDevice device = sender as IDigitalInkDevice; if (device == null) { return; } TextBlock textBlock = null; switch (device.TransportProtocol) { case TransportProtocol.BLE: textBlock = tbBle; break; case TransportProtocol.USB: textBlock = tbUsb; break; case TransportProtocol.BTC: textBlock = tbBtc; break; } var ignore = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { textBlock.Text = AppObjects.GetStringForDeviceStatus(e.Status); }); }
private void OnDeviceStatusChanged(object sender, DeviceStatusChangedEventArgs e) { var ignore = Task.Run(() => { tbBle.Text = AppObjects.GetStringForDeviceStatus(e.Status); // FIX: make a switch on the transport protocol to switch the message for each text boxF }); }
private async void RealTimeInkPage_Loaded(object sender, RoutedEventArgs e) { IDigitalInkDevice device = AppObjects.Instance.Device; if (device == null) { textBlockPrompt.Text = "Device not connected"; return; } device.Disconnected += OnDeviceDisconnected; device.DeviceStatusChanged += OnDeviceStatusChanged; device.PairingModeEnabledCallback = OnPairingModeEnabledAsync; IRealTimeInkService service = device.GetService(InkDeviceService.RealTimeInk) as IRealTimeInkService; service.NewPage += OnNewPage; service.HoverPointReceived += OnHoverPointReceived; //service.StrokeStarted += Service_StrokeStarted; //service.StrokeEnded += Service_StrokeEnded; //service.StrokeUpdated += Service_StrokeUpdated; if (service == null) { textBlockPrompt.Text = "The Real-time Ink service is not supported on this device"; return; } textBlockPrompt.Text = AppObjects.GetStringForDeviceStatus(device.DeviceStatus); try { uint width = (uint)await device.GetPropertyAsync("Width", m_cts.Token); uint height = (uint)await device.GetPropertyAsync("Height", m_cts.Token); uint ptSize = (uint)await device.GetPropertyAsync("PointSize", m_cts.Token); service.Transform = AppObjects.CalculateTransform(width, height, ptSize); float scaleFactor = ptSize * AppObjects.micrometerToDip; InkCanvasDocument document = new InkCanvasDocument(); document.Size = new Windows.Foundation.Size(height * scaleFactor, width * scaleFactor); document.InkCanvasLayers.Add(new InkCanvasLayer()); inkCanvas.InkCanvasDocument = document; inkCanvas.GesturesManager = new GesturesManager(); inkCanvas.StrokeDataProvider = service; if (!service.IsStarted) { await service.StartAsync(false, m_cts.Token); } } catch (Exception) { } }
private async void OnButtonConnectClick(object sender, RoutedEventArgs e) { int index = listView.SelectedIndex; if ((index < 0) || (index >= m_deviceInfos.Count)) { return; } IDigitalInkDevice device = null; m_connectingDeviceInfo = m_deviceInfos[index]; btnConnect.IsEnabled = false; StopScanning(); try { device = await InkDeviceFactory.Instance.CreateDeviceAsync(m_connectingDeviceInfo, AppObjects.Instance.AppId, true, false, OnDeviceStatusChanged); } catch (Exception ex) { StringBuilder sb = new StringBuilder($"Device creation failed:\n{ex.Message}"); string indent = " "; for (Exception inner = ex.InnerException; inner != null; inner = inner.InnerException) { sb.Append($"\n{indent}{inner.Message}"); indent = indent + " "; } MessageBox.Show(sb.ToString()); } if (device == null) { m_connectingDeviceInfo = null; btnConnect.IsEnabled = true; StartScanning(); return; } AppObjects.Instance.DeviceInfo = m_connectingDeviceInfo; AppObjects.Instance.Device = device; m_connectingDeviceInfo = null; await AppObjects.SerializeDeviceInfoAsync(AppObjects.Instance.DeviceInfo); if (NavigationService.CanGoBack) { NavigationService.GoBack(); } }
private async void MainPage_Loaded(object sender, RoutedEventArgs e) { buttonScan.IsEnabled = false; buttonFileTransfer.IsEnabled = false; buttonRealTime.IsEnabled = false; if (AppObjects.Instance.DeviceInfo == null) { AppObjects.Instance.DeviceInfo = await AppObjects.DeserializeDeviceInfoAsync(); } if (AppObjects.Instance.DeviceInfo == null) { textBlockDeviceName.Text = "Not connected to a device, click the \"Scan for Devices\" button and follow the instructions."; buttonScan.IsEnabled = true; return; } InkDeviceInfo inkDeviceInfo = AppObjects.Instance.DeviceInfo; textBlockDeviceName.Text = $"Reconnecting to device {inkDeviceInfo.DeviceName} ({inkDeviceInfo.TransportProtocol}) ..."; try { if (AppObjects.Instance.Device == null) { AppObjects.Instance.Device = await InkDeviceFactory.Instance.CreateDeviceAsync(inkDeviceInfo, AppObjects.Instance.AppId, false, false, OnDeviceStatusChanged); } AppObjects.Instance.Device.Disconnected += OnDeviceDisconnected; AppObjects.Instance.Device.DeviceStatusChanged += OnDeviceStatusChanged; AppObjects.Instance.Device.PairingModeEnabledCallback = OnPairingModeEnabledAsync; } catch (Exception ex) { textBlockDeviceName.Text = $"Cannot init device: {inkDeviceInfo.DeviceName} [{ex.Message}]"; buttonScan.IsEnabled = true; return; } textBlockDeviceName.Text = $"Current device: {inkDeviceInfo.DeviceName}"; buttonFileTransfer.IsEnabled = true; buttonRealTime.IsEnabled = true; buttonScan.IsEnabled = true; textBlockStatus.Text = AppObjects.GetStringForDeviceStatus(AppObjects.Instance.Device.DeviceStatus); await DisplayDevicePropertiesAsync(); }
private void OnDeviceStatusChanged(object sender, DeviceStatusChangedEventArgs e) { var ignore = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { switch (e.Status) { case DeviceStatus.NotAuthorizedConnectionNotConfirmed: await new MessageDialog(AppObjects.GetStringForDeviceStatus(e.Status)).ShowAsync(); Frame.Navigate(typeof(ScanAndConnectPage)); break; default: textBlockPrompt.Text = AppObjects.GetStringForDeviceStatus(e.Status); break; } }); }
private async void FileTransferPage_Loaded(object sender, RoutedEventArgs e) { IDigitalInkDevice device = AppObjects.Instance.Device; device.Disconnected += OnDeviceDisconnected; device.DeviceStatusChanged += OnDeviceStatusChanged; device.PairingModeEnabledCallback = OnPairingModeEnabledAsync; IFileTransferService service = device.GetService(InkDeviceService.FileTransfer) as IFileTransferService; if (service == null) { textBlockPrompt.Text = "The File Transfer service is not supported on this device"; return; } try { textBlockPrompt.Text = s_fileTransferPromptMessage; uint width = (uint)await device.GetPropertyAsync("Width", m_cts.Token); uint height = (uint)await device.GetPropertyAsync("Height", m_cts.Token); uint ptSize = (uint)await device.GetPropertyAsync("PointSize", m_cts.Token); service.Transform = AppObjects.CalculateTransform(width, height, ptSize); if (!service.IsStarted) { await service.StartAsync(StrokesReceivedAsync, false, m_cts.Token); } } catch (Exception) { } }
private async void OnButtonConnectClick(object sender, RoutedEventArgs e) { int index = listView.SelectedIndex; if ((index < 0) || (index >= m_deviceInfos.Count)) { return; } IDigitalInkDevice device = null; m_connectingDeviceInfo = m_deviceInfos[index]; btnConnect.IsEnabled = false; StopScanning(); SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; if (m_connectingDeviceInfo != null) { string msg = $"Initializing connection with device: \"{m_connectingDeviceInfo.DeviceName}\""; switch (m_connectingDeviceInfo.TransportProtocol) { case TransportProtocol.BLE: tbBle.Text = msg; break; case TransportProtocol.USB: tbUsb.Text = msg; break; case TransportProtocol.BTC: tbBtc.Text = msg; break; } } try { device = await InkDeviceFactory.Instance.CreateDeviceAsync(m_connectingDeviceInfo, AppObjects.Instance.AppId, true, false, OnDeviceStatusChanged); } catch (Exception ex) { string message = $"Device creation failed: {ex.Message}"; await new MessageDialog(message).ShowAsync(); } if (device == null) { SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; m_connectingDeviceInfo = null; btnConnect.IsEnabled = true; StartScanning(); return; } AppObjects.Instance.DeviceInfo = m_connectingDeviceInfo; AppObjects.Instance.Device = device; m_connectingDeviceInfo = null; await AppObjects.SerializeDeviceInfoAsync(AppObjects.Instance.DeviceInfo); if (Frame.CanGoBack) { Frame.GoBack(); } }