private void applyChanges(object sender, RoutedEventArgs e)
        {
            try
            {
                // Stop the current control mode if there is one
                if (currentControlMode != null)
                {
                    currentControlMode.Stop();
                }

                TabItem tabItem = tabControl.SelectedItem as TabItem;
                if (tabItem.Name.ToString() == "AUTO")
                {
                    if (radioButtonCycleColour.IsChecked ?? false)
                    {
                        currentControlMode = new BlinkColourCyclerControlMode((int)sliderCycleRate.Value);
                        currentControlMode.Start();
                        lableStatusText.Content = "Colour cycle mode enabled";
                    }
                    else if (radioButtonFadeColour.IsChecked ?? false)
                    {
                        currentControlMode = new FadeColourCyclerControlMode((int)sliderFadeRate.Value);
                        currentControlMode.Start();
                        lableStatusText.Content = "Colour fade mode enabled";
                    }
                    else if (radioButtonCPUUsage.IsChecked ?? false)
                    {
                        currentControlMode = new CPUUsageIndicatorControlMode(2000); //TODO make configurable
                        currentControlMode.Start();
                        lableStatusText.Content = "CPU utilisation indicator mode enabled";
                    }
                }
                else
                {
                    if (radioButtonDisableLed.IsChecked ?? false)
                    {
                        LEDController.DisableLED();
                        lableStatusText.Content = "LED disabled";
                    }
                    else
                    {
                        LEDTransition transition = comboBoxTransition.SelectedItem as LEDTransition;
                        LEDColour     colour     = comboBoxColour.SelectedItem as LEDColour;
                        LEDController.SetLEDState(transition, colour);
                        lableStatusText.Content = $"LED set: {colour.DisplayName} - {transition.DisplayName}";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error setting LED: {ex.Message.ToString()}", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void Tick(object source, ElapsedEventArgs e)
        {
            float cpuUtilisation = perfCounter.NextValue();

            LEDColour targetColour = mapUsageToColour(cpuUtilisation);

            if (currentColour != targetColour)
            {
                LEDController.SetLEDState(LEDTransition.getLEDTransition("ALWAYS_ON"), targetColour);
                currentColour = targetColour;
            }
        }
Exemplo n.º 3
0
 private void Tick(object source, ElapsedEventArgs e)
 {
     LEDController.SetLEDState(LEDTransition.getLEDTransition("ALWAYS_ON"), LEDColour.AvailableColours.ElementAt(currentColourIndex));
     if (currentColourIndex == maxColourIndex)
     {
         currentColourIndex = 0;
     }
     else
     {
         currentColourIndex++;
     }
 }
        private void Tick(object source, ElapsedEventArgs e)
        {
            LEDController.SetLEDState(LEDTransition.getLEDTransition("ALWAYS_ON"), LEDColour.AvailableColours.ElementAt(currentColourIndex), currentBrightness);

            // TODO more of the fade duration should be spent at the lower brightness levels, since the perceived change in brightness is much more apparent at the bottom end.
            // e.g. the perceived difference between 0x10 and 0x20 is much larger than 0x50 and 0x60, so scaling up linearly wastes a lot of time increasing imperceivable brightness changes at the top of the range.
            // presumably its logarithmic, like with sound?
            if (fadeDirection == FadeDirection.Up)
            {
                if (currentBrightness == maxBrightness)
                {
                    // Fade up finished, start fading down
                    fadeDirection = FadeDirection.Down;
                }
                else
                {
                    // Continue fading up
                    currentBrightness += brightnessStepping;
                }
            }
            else // Fading down
            {
                if (currentBrightness == minBrightness)
                {
                    // Fade cycle complete. Change colour and fade up
                    fadeDirection = FadeDirection.Up;

                    if (currentColourIndex == maxColourIndex)
                    {
                        currentColourIndex = 0;
                    }
                    else
                    {
                        currentColourIndex++;
                    }
                }
                else
                {
                    // Continue fading down
                    currentBrightness -= brightnessStepping;
                }
            }
        }