/// <summary> /// The device was closed. If we will autoreconnect to the device, reflect that in the UI /// </summary> /// <param name="sender"></param> /// <param name="deviceInformation"></param> private async void OnDeviceClosing(FadecandyEventHandler sender, DeviceInformation deviceInformation) { await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, new DispatchedHandler(() => { })); }
private async void ConnectToDevice(DeviceInformation deviceInfo, string deviceSelector) { // Create an EventHandlerForDevice to watch for the device we are connecting to FadecandyEventHandler.CreateNewEventHandlerForDevice(); // Get notified when the device was successfully connected to or about to be closed FadecandyEventHandler.Current.OnDeviceConnected = this.OnDeviceConnected; FadecandyEventHandler.Current.OnDeviceClose = this.OnDeviceClosing; // It is important that the FromIdAsync call is made on the UI thread because the consent prompt, when present, // can only be displayed on the UI thread. Since this method is invoked by the UI, we are already in the UI thread. Boolean openSuccess = await FadecandyEventHandler.Current.OpenDeviceAsync(deviceInfo, deviceSelector); if (openSuccess) { NotifyUser("Device Connected.", deviceInfo.Id, NotifyType.StatusMessage); } else { NotifyUser("Device Failed.", deviceInfo.Id, NotifyType.ErrorMessage); } }
/// <summary> /// Creates a new instance of EventHandlerForDevice, enables auto reconnect, and uses it as the Current instance. /// </summary> public static void CreateNewEventHandlerForDevice() { eventHandlerForDevice = new FadecandyEventHandler(); }
//private void StartHandlingAppEvents() //{ //} /// <summary> /// If all the devices have been enumerated, select the device in the list we connected to. Otherwise let the EnumerationComplete event /// from the device watcher handle the device selection /// </summary> /// <param name="sender"></param> /// <param name="deviceInformation"></param> private void OnDeviceConnected(FadecandyEventHandler sender, DeviceInformation deviceInformation) { NotifyUser("Connected to Device", FadecandyEventHandler.Current.DeviceInformation.Id, NotifyType.StatusMessage); }