public void UpdateColors() { if (UserSettings.Settings.ActiveDevice == null || _triangles == null) { return; } var client = NanoleafClient.GetClientForDevice(UserSettings.Settings.ActiveDevice); //Get colors of current effect var effect = client.EffectsEndpoint.GetEffectDetails(OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice).GetActiveEffectName()); Dispatcher.Invoke(new Action(() => { if (effect == null) { foreach (var triangle in _triangles) { triangle.Polygon.Fill = Brushes.LightSlateGray; } } else { var colors = effect.Palette.Select(hsb => new SolidColorBrush( HsbToRgbConverter.ConvertToMediaColor(hsb.Hue, hsb.Saturation, hsb.Brightness) )).ToList(); foreach (var triangle in _triangles) { triangle.Polygon.Fill = colors[_random.Next(colors.Count)]; } } })); }
public void Finish_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(setupViewModel.Name)) { PopupCreator.Error(Setup.Resources.NameCannotBeEmpty); return; } else if (UserSettings.HasSettings() && UserSettings.Settings.Devices.Any(d => d.Name.ToLower().Equals(setupViewModel.Name))) { PopupCreator.Error(Setup.Resources.NameAlreadyExists); return; } selectedDevice.Name = setupViewModel.Name; UserSettings.Settings.AddDevice(selectedDevice); _logger.Info($"Successfully added device {selectedDevice.Name}"); if (_parent != null) { OrchestratorCollection.AddOrchestratorForDevice(selectedDevice); _parent.DeviceAdded(selectedDevice); _parent.SelectedDevice = selectedDevice.Name; } else { UserSettings.Settings.SetActiveDevice(selectedDevice.Name); //The first added device must always be active App.NormalStartup(null); } Close(); }
public void DrawLayout() { CanvasArea.Children.Clear(); var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice); _triangles = orchestrator.PanelLayout.GetScaledTriangles(_width, _height); if (_triangles == null || !_triangles.Any()) { return; } foreach (var triangle in _triangles) { triangle.Polygon.MouseDown += TriangleClicked; } //Draw the triangles foreach (var triangle in _triangles) { CanvasArea.Children.Add(triangle.Polygon); } UpdateColors(); }
private async Task SetOperationMode() { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); if (_activeTriggersPriorities.Any()) { var lowestPriority = _activeTriggersPriorities.Min(); if (ActiveTrigger == null || ActiveTrigger.Priority != lowestPriority) { //Event operation mode is already active or we try to activate it (can fail if the user has manual enabled) var eventOperationModeActive = orchestrator.Device.OperationMode == OperationMode.Event || await orchestrator.TrySetOperationMode(OperationMode.Event); if (eventOperationModeActive) { //A trigger has been activated or deactivated and the current active trigger is no longer the trigger with the highest priority (priority 1 is highest) ActiveTrigger = _eventTriggers.FirstOrDefault(eventTrigger => eventTrigger.Priority == lowestPriority); await orchestrator.ActivateEffect(ActiveTrigger.EffectName, ActiveTrigger.Brightness); _logger.Info($"Process event started with effect {ActiveTrigger.EffectName} with brightness {ActiveTrigger.Brightness} for device {_device.IPAddress}"); } } } else if (orchestrator.Device.OperationMode == OperationMode.Event) //Only go back to schedule if the current devices operation mode is event { //Let orchestrator know that all events have stopped so it can continue with normal program, will not fail since an event can only be activated when no override is active //Always return to schedule since only 1 event can be active at a time ActiveTrigger = null; await orchestrator.TrySetOperationMode(OperationMode.Schedule); _logger.Info($"Stopped all process events for device {_device.IPAddress}"); } }
/// <summary> /// Updates all elements to display the current effect and brightness /// </summary> public void Update() { //Update UI on main thread Dispatcher.Invoke(new Action(() => { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); var activeEffect = orchestrator.GetActiveEffectName(); if (string.IsNullOrEmpty(activeEffect)) { ActiveEffectLabel.Content = MainWindows.Resources.None; } else { ActiveEffectLabel.Content = $"{activeEffect} ({EnumLocalizer.GetLocalizedEnum(_device.OperationMode)})"; } _selectedEffect = activeEffect; var activeBrightness = orchestrator.GetActiveBrightness(); Brightness = activeBrightness < 0 ? 0 : activeBrightness; OnPropertyChanged(nameof(Brightness)); //Call property changed to correctly set slider position //Update the colors in the mainwindow _parent.UpdateLayoutColors(_device.Name); //Update the dropdown EffectComboBox.UpdateSelection(_selectedEffect); })); }
private async Task Override() { if (!string.IsNullOrEmpty(SelectedEffect)) { try { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice); if (await orchestrator.TrySetOperationMode(OperationMode.Manual, true)) { orchestrator.Device.OverrideEffect = SelectedEffect; orchestrator.Device.OverrideBrightness = Brightness; await orchestrator.ActivateEffect(SelectedEffect, Brightness); MainWindow.UpdateCurrentEffectLabelsAndLayout(); } } catch (Exception e) { _logger.Error(e, "Error during overriding schedule"); PopupCreator.Error(MainWindows.Resources.OverrideError); } } }
public void UpdateColors() { if (UserSettings.Settings.ActiveDevice == null || _triangles == null) { return; } //Run code on main thread since we update the UI Dispatcher.Invoke(new Action(() => { var client = NanoleafClient.GetClientForDevice(UserSettings.Settings.ActiveDevice); var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice); //Get colors of current effect, we can display colors for nanoleaf effects or custom color effects var effectName = orchestrator.GetActiveEffectName(); var customEffect = orchestrator.GetCustomEffectFromName(effectName); List <SolidColorBrush> colors = null; if (customEffect != null) { if (customEffect is CustomColorEffect customColorEffect) { colors = new List <SolidColorBrush>() { new SolidColorBrush(Color.FromArgb(customColorEffect.Color.A, customColorEffect.Color.R, customColorEffect.Color.G, customColorEffect.Color.B)) }; } } else { var effect = client.EffectsEndpoint.GetEffectDetails(OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice).GetActiveEffectName()); if (effect != null) { colors = effect.Palette.Select(hsb => new SolidColorBrush( HsbToRgbConverter.ConvertToMediaColor(hsb.Hue, hsb.Saturation, hsb.Brightness) )).ToList(); } } if (colors == null) { foreach (var triangle in _triangles) { triangle.Polygon.Fill = Brushes.LightSlateGray; } } else { foreach (var triangle in _triangles) { triangle.Polygon.Fill = colors[_random.Next(colors.Count)]; } } })); }
public AddProcessEventWindow(EventUserControl parent) { _parent = parent; Effects = new List <Effect>(UserSettings.Settings.ActiveDevice.Effects); Effects.InsertRange(0, OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice).GetCustomEffectAsEffects()); DataContext = this; InitializeComponent(); }
public OverrideScheduleUserControl() { InitializeComponent(); Effects = new List <Effect>(UserSettings.Settings.ActiveDevice.Effects); Effects.InsertRange(0, OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice).GetCustomEffectAsEffects()); DataContext = this; Brightness = 70; //TODO: get the value from the device itself }
public void ReloadEffects() { //Reset the orchestrator since it can happen that the orchestrators have been reset before calling this function RegisterWithOrchestrator(); var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); EffectComboBox.InitializeEffects(orchestrator); EffectComboBox.UpdateSelection(_selectedEffect); }
/// <summary> /// Stops the timer and gives it 1 second to complete. Also stop the screengrabber if no other ambilight effects are active /// </summary> public async Task Deactivate() { _timer.Stop(); Thread.Sleep(1000); //Give the last command the time to complete, 1000 is based on testing and a high value (better safe then sorry) //Check if any other screen mirror effects are active, if not, stop the screen grabber if (OrchestratorCollection.CountOrchestratorsWithActiveScreenMirrorEffect() <= 0) { ScreenGrabber.Stop(); } }
private async Task StopOverride() { if (UserSettings.Settings.ActiveDevice.OperationMode == OperationMode.Manual) { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice); if (await orchestrator.TrySetOperationMode(OperationMode.Schedule, true)) { MainWindow.UpdateCurrentEffectLabelsAndLayout(); } } }
public void Visualize(double scale) { var scaleType = _screenMirrorAlgorithm == ScreenMirrorAlgorithm.ScreenMirrorFit ? ScaleType.Fit : ScaleType.Stretch; var width = Convert.ToInt32(_screenBounds.Width / scale); var height = Convert.ToInt32(_screenBounds.Height / scale); var panels = OrchestratorCollection.GetOrchestratorForDevice(_device).PanelLayout.GetScaledTriangles(width, height, scaleType); DrawPanels(panels); //Horizontally center the close label CloseInfoLabel.Margin = new Thickness(width / 2, 0, 0, 0); }
/// <inheritdoc /> public async Task Activate() { if (_screenMirrorAlgorithm == ScreenMirrorAlgorithm.ScreenMirrorFit || _screenMirrorAlgorithm == ScreenMirrorAlgorithm.ScreenMirrorStretch) { //For screen mirror, we need to enable external control var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); await _nanoleafClient.ExternalControlEndpoint.PrepareForExternalControl(orchestrator.PanelLayout.DeviceType, orchestrator.Device.IPAddress); } //Start the screengrabber ScreenGrabber.Start(); _timer.Start(); }
private async Task StopManualAsync() { if (_device.OperationMode == OperationMode.Manual) { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); await orchestrator.TrySetOperationMode(OperationMode.Schedule, true, true); if (!orchestrator.HasActiveEffect()) { //Special case: when the user has no active schedule, the schedule will not set an effect and therefore //not trigger an update to the effects, hence we need to call update here Update(); } } }
public void LoadEffects() { // Effects collection is not rebuild. Effects.Clear(); var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice); var effects = orchestrator.GetCustomEffectAsEffects(); effects.AddRange(UserSettings.Settings.ActiveDevice.Effects); foreach (var effect in effects) { Effects.Add(effect); } }
public void UpdateLabels() { var device = UserSettings.Settings.ActiveDevice; if (device != null) { var effect = OrchestratorCollection.GetOrchestratorForDevice(device).GetActiveEffectName(); var brightness = OrchestratorCollection.GetOrchestratorForDevice(device).GetActiveBrightness(); Dispatcher.Invoke(new Action(() => { CurrentEffect.Content = string.IsNullOrEmpty(effect) ? MainWindows.Resources.Nothing : effect; CurrentBrightness.Content = brightness >= 0 ? brightness.ToString() : MainWindows.Resources.Nothing; })); } }
public static void NormalStartup(StartupEventArgs startupEventArgs) { var silent = false; if (startupEventArgs != null && startupEventArgs.Args.Length > 0) { silent = startupEventArgs.Args[0].Equals("-s"); } try { UserSettings.LoadSettings(); } catch (SettingsFileJsonException ex) { _logger.Fatal("Corrupt settings file found", ex); PopupCreator.Error(string.Format(AppResources.CorruptSettings, UserSettings.SettingsFolder + "Settings.json")); return; } if (!string.IsNullOrEmpty(UserSettings.Settings.UserLocale)) { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(UserSettings.Settings.UserLocale); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(UserSettings.Settings.UserLocale); } UserSettings.Settings.ResetOperationModes(); SunTimesUpdater.UpdateSunTimes(); OrchestratorCollection.Initialize(); SpotifyEventTimer.Initialize(); var mainWindow = new MainWindow(); if (!silent) { mainWindow.Show(); } mainWindow.Initialize(); CheckForUpdate(); }
/// <summary> /// Initialize effects based on all devices. /// Only effects that are shared between all devices will be /// part of the dropdown. /// </summary> public void InitializeEffects() { var orchestrators = new List <Orchestrator>(); var customEffects = new List <ICustomEffect>(); var effects = new List <Effect>(); foreach (var device in UserSettings.Settings.Devices) { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(device); customEffects.AddRange(orchestrator.GetCustomEffects()); //ToList to make a copy such that we do not get CollectionModifiedException (caused by calling UpdateEffect) effects.AddRange(orchestrator.Device.Effects.ToList()); orchestrators.Add(orchestrator); } BuildEffects(customEffects.Distinct(new CustomEffectEqualityComparer()), effects.Distinct(), orchestrators); }
public DeviceUserControl(Device device, MainWindow parent) { InitializeComponent(); _device = device; RegisterWithOrchestrator(); _parent = parent; DeviceNameLabel.Content = _device.Name; var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); //Set the correct icon switch (orchestrator.PanelLayout.DeviceType) { case DeviceType.Canvas: SquareIcon.Visibility = Visibility.Visible; break; case DeviceType.Aurora: TriangleIcon.Visibility = Visibility.Visible; break; case DeviceType.Shapes: HexagonIcon.Visibility = Visibility.Visible; break; case DeviceType.Unknown: UnknownIcon.Visibility = Visibility.Visible; break; default: throw new NotImplementedException($"No icon implemented for device type {orchestrator.PanelLayout.DeviceType}"); } //Initialize the effect combox box EffectComboBox.InitializeEffects(orchestrator); EffectComboBox.ParentUserControl = this; DataContext = this; Update(); }
public AddTimeTriggerWindow(DayUserControl parent) { _parent = parent; Effects = new List <Effect>(UserSettings.Settings.ActiveDevice.Effects); Effects.InsertRange(0, OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice).GetCustomEffectAsEffects()); _triggerTypeMapping = new Dictionary <string, TriggerType>() { { EnumLocalizer.GetLocalizedEnum(TriggerType.Time), TriggerType.Time }, { EnumLocalizer.GetLocalizedEnum(TriggerType.Sunrise), TriggerType.Sunrise }, { EnumLocalizer.GetLocalizedEnum(TriggerType.Sunset), TriggerType.Sunset } }; DataContext = this; InitializeComponent(); SelectedTriggerType = EnumLocalizer.GetLocalizedEnum(TriggerType.Time); }
/// <summary> /// Draws the layout and gives the polygons colors /// </summary> /// <param name="resetLayout"> /// If true, the panel layout is always requested from the panels /// even if it has been retrieved before. /// </param> public void DrawLayout(bool resetLayout = false) { CanvasArea.Children.Clear(); if (resetLayout || _panelLayout == null) { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice); if (orchestrator == null) { return; } _panelLayout = orchestrator.PanelLayout; } _polygons = _panelLayout.GetScaledPolygons((int)ActualWidth, (int)ActualHeight, ScaleType.Fit, FlipType.None); if (_polygons == null || !_polygons.Any()) { return; } if (_panelsClickable) { foreach (var polygon in _polygons) { polygon.Polygon.MouseDown += PolygonClicked; } } //Draw the triangles foreach (var polygon in _polygons) { CanvasArea.Children.Add(polygon.Polygon); } UpdateColors(); }
private async Task SelectedEffectChanged() { try { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); if (await orchestrator.TrySetOperationMode(OperationMode.Manual, true, true)) { _logger.Info($"User manually enabling effect {_selectedEffect} with brightness {Brightness} for device {_device.IPAddress}"); _device.ManualEffect = _selectedEffect; _device.ManualBrightness = Brightness; await orchestrator.ActivateEffect(_selectedEffect, Brightness); UserSettings.Settings.SaveSettings(); } } catch (Exception e) { _logger.Error(e, "Error during setting manual control"); PopupCreator.Error(MainWindows.Resources.ManualControlError); } }
private void Save_Click(object sender, RoutedEventArgs e) { #region LatLong double latitude = 0; double longitude = 0; try { if (!string.IsNullOrWhiteSpace(OptionsViewModel.Latitude)) { latitude = Convert.ToDouble(OptionsViewModel.Latitude, CultureInfo.InvariantCulture); } } catch { PopupCreator.Error(Options.Resources.InvalidLatitude); return; } try { if (!string.IsNullOrWhiteSpace(OptionsViewModel.Longitude)) { longitude = Convert.ToDouble(OptionsViewModel.Longitude, CultureInfo.InvariantCulture); } } catch { PopupCreator.Error(Options.Resources.InvalidLongitude); return; } if ((latitude != UserSettings.Settings.Latitude || longitude != UserSettings.Settings.Longitude) && (latitude != 0 && longitude != 0)) { var client = new SunsetSunriseClient(); try { var sunTimes = client.GetSunsetSunriseAsync(latitude, longitude).GetAwaiter().GetResult(); UserSettings.Settings.UpdateSunriseSunset(sunTimes.SunriseHour, sunTimes.SunriseMinute, sunTimes.SunsetHour, sunTimes.SunsetMinute); } catch { PopupCreator.Error(Options.Resources.SunsetSunriseError); return; } UserSettings.Settings.Latitude = latitude; UserSettings.Settings.Longitude = longitude; } #endregion #region StartAtWindowsStartup if (UserSettings.Settings.StartAtWindowsStartup != OptionsViewModel.StartAtWindowsStartUp) { if (OptionsViewModel.StartAtWindowsStartUp) { _startupKey.SetValue(UserSettings.APPLICATIONNAME, $"{System.Reflection.Assembly.GetExecutingAssembly().Location} -s"); } else { _startupKey.DeleteValue(UserSettings.APPLICATIONNAME, false); } _startupKey.Close(); UserSettings.Settings.StartAtWindowsStartup = OptionsViewModel.StartAtWindowsStartUp; } #endregion #region ScreenMirror var monitorNames = WindowsDisplayAPI.DisplayConfig.PathDisplayTarget.GetDisplayTargets().Select(m => m.FriendlyName).ToArray(); foreach (var device in UserSettings.Settings.Devices) { device.ScreenMirrorAlgorithm = OptionsViewModel.AlgorithmPerDevice[device.Name]; device.ScreenMirrorRefreshRatePerSecond = OptionsViewModel.ScreenMirrorRefreshRatePerDevice[device.Name]; device.ScreenMirrorControlBrightness = OptionsViewModel.ScreenMirrorControlBrightnessPerDevice[device.Name]; device.ScreenMirrorMonitorIndex = Array.IndexOf(monitorNames, OptionsViewModel.MonitorPerDevice[device.Name]); } #endregion #region Language if (OptionsViewModel.SelectedLanguage != null) { UserSettings.Settings.UserLocale = _languageDictionary[OptionsViewModel.SelectedLanguage]; } #endregion #region MinimizeToSystemTray UserSettings.Settings.MinimizeToSystemTray = OptionsViewModel.MinimizeToSystemTray; #endregion #region Colors UserSettings.Settings.CustomEffects = OptionsViewModel.CustomColorEffects; #endregion Colors UserSettings.Settings.SaveSettings(); // Reload the orchestrator so custom effects are reloaded. OrchestratorCollection.ResetOrchestratorForActiveDevice(); _mainWindow.ReloadEffects(); Close(); }
public void RegisterWithOrchestrator() { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); orchestrator.AddEffectChangedCallback(Update); }
private void Save_Click(object sender, RoutedEventArgs e) { #region LatLong double latitude = 0; double longitude = 0; try { if (!string.IsNullOrWhiteSpace(OptionsViewModel.Latitude)) { latitude = Convert.ToDouble(OptionsViewModel.Latitude, CultureInfo.InvariantCulture); } } catch { PopupCreator.Error(Options.Resources.InvalidLatitude); return; } try { if (!string.IsNullOrWhiteSpace(OptionsViewModel.Longitude)) { longitude = Convert.ToDouble(OptionsViewModel.Longitude, CultureInfo.InvariantCulture); } } catch { PopupCreator.Error(Options.Resources.InvalidLongitude); return; } if ((latitude != UserSettings.Settings.Latitude || longitude != UserSettings.Settings.Longitude) && (latitude != 0 && longitude != 0)) { var client = new SunsetSunriseClient(); try { var sunTimes = client.GetSunsetSunriseAsync(latitude, longitude).GetAwaiter().GetResult(); UserSettings.Settings.UpdateSunriseSunset(sunTimes.SunriseHour, sunTimes.SunriseMinute, sunTimes.SunsetHour, sunTimes.SunsetMinute); } catch { PopupCreator.Error(Options.Resources.SunsetSunriseError); return; } UserSettings.Settings.Latitude = latitude; UserSettings.Settings.Longitude = longitude; } #endregion #region StartAtWindowsStartup if (UserSettings.Settings.StartAtWindowsStartup != OptionsViewModel.StartAtWindowsStartUp) { if (OptionsViewModel.StartAtWindowsStartUp) { //Replace .dll with .exe since in .net core 3 the current executing assembly is the dll _startupKey.SetValue(UserSettings.APPLICATIONNAME, $"{System.Reflection.Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe")} -s"); } else { _startupKey.DeleteValue(UserSettings.APPLICATIONNAME, false); } _startupKey.Close(); UserSettings.Settings.StartAtWindowsStartup = OptionsViewModel.StartAtWindowsStartUp; } #endregion #region ScreenMirror foreach (var device in UserSettings.Settings.Devices) { device.ScreenMirrorAlgorithm = OptionsViewModel.AlgorithmPerDevice[device.Name]; } UserSettings.Settings.ScreenMirrorMonitorIndex = Array.IndexOf(_monitorNames.ToArray(), OptionsViewModel.SelectedMonitor); UserSettings.Settings.ScreenMirrorRefreshRatePerSecond = OptionsViewModel.ScreenMirrorRefreshRatePerSecond; #endregion #region Language if (OptionsViewModel.SelectedLanguage != null) { UserSettings.Settings.UserLocale = _languageDictionary[OptionsViewModel.SelectedLanguage]; } #endregion #region MinimizeToSystemTray UserSettings.Settings.MinimizeToSystemTray = OptionsViewModel.MinimizeToSystemTray; #endregion #region Colors var deletedColors = UserSettings.Settings.CustomEffects?.Except(OptionsViewModel.CustomColorEffects).ToList(); UserSettings.Settings.CustomEffects = OptionsViewModel.CustomColorEffects; //Remove invalid triggers from the schedules if (deletedColors?.Any() == true) { UserSettings.Settings.DeleteTriggers(deletedColors.Select(color => UserCustomColorEffect.DisplayName(color.EffectName))); } #endregion Colors UserSettings.Settings.SaveSettings(); //Reload the orchestrator so custom effects are reloaded. OrchestratorCollection.ResetOrchestrators(); //Reload effects such that custom effects are updated in the view _mainWindow.ReloadEffectsInView(); Close(); }
public void UpdateColors() { if (UserSettings.Settings.ActiveDevice == null || _polygons == null) { return; } //Run code on main thread since we update the UI Dispatcher.Invoke(new Action(() => { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice); //Get colors of current effect, we can display colors for nanoleaf effects or custom color effects var effectName = orchestrator.GetActiveEffectName(); ICustomEffect customEffect = null; if (effectName != null) { customEffect = orchestrator.GetCustomEffectFromName(effectName); } List <SolidColorBrush> colors = null; if (customEffect != null) { if (customEffect is CustomColorEffect customColorEffect) { colors = new List <SolidColorBrush>() { new SolidColorBrush(Color.FromArgb(customColorEffect.Color.A, customColorEffect.Color.R, customColorEffect.Color.G, customColorEffect.Color.B)) }; } } else { var effect = UserSettings.Settings.ActiveDevice.Effects.FirstOrDefault(effect => effect.Name == effectName); //Only retrieve palette if it is not known yet if (effect?.Palette == null) { var client = NanoleafClient.GetClientForDevice(UserSettings.Settings.ActiveDevice); effect = client.EffectsEndpoint.GetEffectDetails(effectName); if (effect != null) { //Update the effect such that the palette is known in the future UserSettings.Settings.ActiveDevice.UpdateEffect(effect); } } if (effect != null) { colors = effect.Palette.Select(hsb => new SolidColorBrush( HsbToRgbConverter.ConvertToMediaColor(hsb.Hue, hsb.Saturation, hsb.Brightness) )).ToList(); } } if (colors == null) { foreach (var polygon in _polygons) { polygon.Polygon.Fill = Brushes.LightSlateGray; } } else { foreach (var polygon in _polygons) { polygon.Polygon.Fill = colors[_random.Next(colors.Count)]; } } })); }
private void SetOrchestrator() { _orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); _orchestrator.AddEffectChangedCallback(Update); }