コード例 #1
0
        private void btn_RotateReset_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Debug.WriteLine("Resetting the led rotation.");
                vCurrentRotation = 0;

                SettingsFunction.Save("LedRotate" + vCurrentRatio, "0");
                tb_RotateValue.Text = "Led rotation: 0";

                //Check the maximum rotation count
                CheckMaximumRotationCount();
            }
            catch { }
        }
コード例 #2
0
ファイル: Settings-Save.cs プロジェクト: dumbie/AmbiPro
 //Reset all led rotate settings
 void SettingResetLedRotate()
 {
     try
     {
         Debug.WriteLine("Resetting all led rotate settings.");
         foreach (string settingName in ConfigurationManager.AppSettings)
         {
             if (settingName.StartsWith("LedRotate") && settingName.Contains(":"))
             {
                 SettingsFunction.Save(settingName, "0");
             }
         }
     }
     catch { }
 }
コード例 #3
0
        private void btn_RotateCounterwise_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Debug.WriteLine("Rotating the leds counterwise.");
                vCurrentRotation += 1;

                SettingsFunction.Save("LedRotate" + vCurrentRatio, vCurrentRotation.ToString());
                tb_RotateValue.Text = "Led rotation: " + vCurrentRotation;

                //Check the maximum rotation count
                CheckMaximumRotationCount();
            }
            catch { }
        }
コード例 #4
0
        //Handle window closing event
        protected override void OnClosing(CancelEventArgs e)
        {
            try
            {
                e.Cancel = true;
                Debug.WriteLine("Settings window closing.");

                //Disable debug to save performance
                SettingsFunction.Save("DebugMode", "False");
                checkbox_DebugMode.IsChecked = false;
                image_DebugPreview.Source    = null;

                //Hide the settings window
                this.Hide();
            }
            catch { }
        }
コード例 #5
0
ファイル: Settings-Save.cs プロジェクト: dumbie/AmbiPro
        //Save baud rate after delay
        public async void SettingSaveBaudRate(object sender, EventArgs e)
        {
            try
            {
                //Stop the timer
                vDispatcherTimer_SettingBaudRate.Stop();

                //Color brushes
                BrushConverter BrushConvert = new BrushConverter();
                Brush          BrushInvalid = BrushConvert.ConvertFromString("#cd1a2b") as Brush;
                Brush          BrushValid   = BrushConvert.ConvertFromString("#1db954") as Brush;

                //Check text input and length
                if (string.IsNullOrWhiteSpace(textbox_BaudRate.Text))
                {
                    textbox_BaudRate.BorderBrush = BrushInvalid; return;
                }

                //Check text input has invalid characters
                if (Regex.IsMatch(textbox_BaudRate.Text, "(\\D+)"))
                {
                    textbox_BaudRate.BorderBrush = BrushInvalid; return;
                }

                //Check text input number
                int intBaudRate = Convert.ToInt32(textbox_BaudRate.Text);
                if (intBaudRate < 1 || intBaudRate > 268435456)
                {
                    textbox_BaudRate.BorderBrush = BrushInvalid; return;
                }

                //Save the new baud rate setting
                SettingsFunction.Save("BaudRate", textbox_BaudRate.Text);
                textbox_BaudRate.BorderBrush = BrushValid;

                //Restart the leds
                if (!Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                {
                    await LedSwitch(LedSwitches.Restart);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed saving baudrate: " + ex.Message);
            }
        }
コード例 #6
0
ファイル: Settings-Save.cs プロジェクト: dumbie/AmbiPro
        //Save led sides
        public async Task SettingSaveLedSide(string sideName, string sideIndex)
        {
            try
            {
                //Save the new led side setting
                SettingsFunction.Save(sideName, sideIndex);

                //Reset led rotate setting
                SettingResetLedRotate();

                //Restart the leds
                if (!Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                {
                    await LedSwitch(LedSwitches.Restart);
                }
            }
            catch { }
        }
コード例 #7
0
ファイル: Settings-Save.cs プロジェクト: dumbie/AmbiPro
        //Update server port after delay
        private async void SettingSaveServerPort(object sender, EventArgs e)
        {
            try
            {
                //Stop the timer
                vDispatcherTimer_SettingServerPort.Stop();

                //Color brushes
                BrushConverter BrushConvert = new BrushConverter();
                Brush          BrushInvalid = BrushConvert.ConvertFromString("#cd1a2b") as Brush;
                Brush          BrushValid   = BrushConvert.ConvertFromString("#1db954") as Brush;

                //Check text input and length
                if (string.IsNullOrWhiteSpace(tb_ServerPort.Text))
                {
                    tb_ServerPort.BorderBrush = BrushInvalid; return;
                }

                //Check text input has invalid characters
                if (Regex.IsMatch(tb_ServerPort.Text, "(\\D+)"))
                {
                    tb_ServerPort.BorderBrush = BrushInvalid; return;
                }

                //Check text input number
                int ServerPort = Convert.ToInt32(tb_ServerPort.Text);
                if (ServerPort < 1 || ServerPort > 65535)
                {
                    tb_ServerPort.BorderBrush = BrushInvalid; return;
                }

                SettingsFunction.Save("ServerPort", tb_ServerPort.Text);
                tb_ServerPort.BorderBrush = BrushValid;

                //Restart the socket server
                vArnoldVinkSockets.vSocketServerPort = Convert.ToInt32(tb_ServerPort.Text);
                await vArnoldVinkSockets.SocketServerRestart();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed saving serverport: " + ex.Message);
            }
        }
コード例 #8
0
        //Update the rotation ratio
        void UpdateRotationRatio()
        {
            try
            {
                //Set the current screen resolution and ratio
                vCurrentRatio = AVFunctions.ScreenAspectRatio(vScreenOutputWidth, vScreenOutputHeight, false);
                if (string.IsNullOrWhiteSpace(vCurrentRatio))
                {
                    btn_RotateCounterwise.IsEnabled = false;
                    btn_RotateClockwise.IsEnabled   = false;
                    btn_RotateReset.IsEnabled       = false;
                    textblock_DebugPreview.Text     = "Select screen capture mode and turn leds on to debug.";
                    tb_RotateResolution.Text        = "Select screen capture mode and turn leds on to start calibration.";
                    return;
                }
                else
                {
                    string captureInfo = vScreenOutputWidth + "x" + vScreenOutputHeight + " (" + vCurrentRatio + ")";
                    if (vScreenOutputHDR)
                    {
                        captureInfo += " (HDR)";
                    }

                    textblock_DebugPreview.Text = "Screen capture preview " + captureInfo + ":";
                    tb_RotateResolution.Text    = "Capture resolution: " + captureInfo;
                }

                //Update the rotation based on ratio
                if (SettingsFunction.Check("LedRotate" + vCurrentRatio))
                {
                    vCurrentRotation = Convert.ToInt32(ConfigurationManager.AppSettings["LedRotate" + vCurrentRatio]);
                }
                tb_RotateValue.Text = "Led rotation: " + vCurrentRotation;
            }
            catch { }
        }
コード例 #9
0
ファイル: Settings-Check.cs プロジェクト: dumbie/AmbiPro
        //Check - Application Settings
        public static void SettingsCheck()
        {
            try
            {
                Debug.WriteLine("Checking application settings...");

                //Check - First launch
                if (ConfigurationManager.AppSettings["FirstLaunch2"] == null)
                {
                    SettingsFunction.Save("FirstLaunch2", "True");
                }

                //Check - Com Port
                if (ConfigurationManager.AppSettings["ComPort"] == null)
                {
                    SettingsFunction.Save("ComPort", "1");
                }

                //Check - Baud Rate
                if (ConfigurationManager.AppSettings["BaudRate"] == null)
                {
                    SettingsFunction.Save("BaudRate", "115200");
                }

                //Check - Enable or Disable Led Automatic
                if (ConfigurationManager.AppSettings["LedAutoOnOffBefore"] == null)
                {
                    SettingsFunction.Save("LedAutoOnOffBefore", "False");
                }
                if (ConfigurationManager.AppSettings["LedAutoTimeBefore"] == null)
                {
                    SettingsFunction.Save("LedAutoTimeBefore", "01/01/1970 9:00:00");
                }
                if (ConfigurationManager.AppSettings["LedAutoOnOffAfter"] == null)
                {
                    SettingsFunction.Save("LedAutoOnOffAfter", "False");
                }
                if (ConfigurationManager.AppSettings["LedAutoTimeAfter"] == null)
                {
                    SettingsFunction.Save("LedAutoTimeAfter", "01/01/1970 17:00:00");
                }

                //Check - Server Port
                if (ConfigurationManager.AppSettings["ServerPort"] == null)
                {
                    SettingsFunction.Save("ServerPort", "1020");
                }

                //Check - Monitor Capture
                if (ConfigurationManager.AppSettings["MonitorCapture"] == null)
                {
                    SettingsFunction.Save("MonitorCapture", "0");
                }

                //Check - Led Mode
                if (ConfigurationManager.AppSettings["LedMode"] == null)
                {
                    SettingsFunction.Save("LedMode", "0");
                }

                //Check - Adjust to Blackbars
                if (ConfigurationManager.AppSettings["AdjustBlackBars"] == null)
                {
                    SettingsFunction.Save("AdjustBlackBars", "True");
                }

                //Check - Blackbar Update Rate
                if (ConfigurationManager.AppSettings["AdjustBlackbarRate"] == null)
                {
                    SettingsFunction.Save("AdjustBlackbarRate", "1000");
                }

                //Check - Blackbar Update Range
                if (ConfigurationManager.AppSettings["AdjustBlackbarRange"] == null)
                {
                    SettingsFunction.Save("AdjustBlackbarRange", "40");
                }

                //Check - Adjust Blackbar Brightness
                if (ConfigurationManager.AppSettings["AdjustBlackBarBrightness"] == null)
                {
                    SettingsFunction.Save("AdjustBlackBarBrightness", "8");
                }

                //Check - Led Bottom Gap
                if (ConfigurationManager.AppSettings["LedBottomGap"] == null)
                {
                    SettingsFunction.Save("LedBottomGap", "0");
                }

                //Check - Led Contrast Level
                if (ConfigurationManager.AppSettings["LedContrast"] == null)
                {
                    SettingsFunction.Save("LedContrast", "0");
                }

                //Check - Led Brightness Level
                if (ConfigurationManager.AppSettings["LedBrightness"] == null)
                {
                    SettingsFunction.Save("LedBrightness", "90");
                }

                //Check - Led Gamma
                if (ConfigurationManager.AppSettings["LedGamma"] == null)
                {
                    SettingsFunction.Save("LedGamma", "75");
                }

                //Check - Led Saturation
                if (ConfigurationManager.AppSettings["LedSaturation"] == null)
                {
                    SettingsFunction.Save("LedSaturation", "120");
                }

                //Check - Led Temperature
                if (ConfigurationManager.AppSettings["LedTemperature"] == null)
                {
                    SettingsFunction.Save("LedTemperature", "0");
                }

                //Check - Color Loop Speed
                if (ConfigurationManager.AppSettings["ColorLoopSpeed"] == null)
                {
                    SettingsFunction.Save("ColorLoopSpeed", "75");
                }

                //Check - Spectrum Rotation Speed
                if (ConfigurationManager.AppSettings["SpectrumRotationSpeed"] == null)
                {
                    SettingsFunction.Save("SpectrumRotationSpeed", "20");
                }

                //Check - Solid Led Color
                if (ConfigurationManager.AppSettings["SolidLedColor"] == null)
                {
                    SettingsFunction.Save("SolidLedColor", "#FFA500");
                }

                //Check - Led Hue
                if (ConfigurationManager.AppSettings["LedHue2"] == null)
                {
                    SettingsFunction.Save("LedHue2", "0");
                }

                //Check - Led Minimum Brightness
                if (ConfigurationManager.AppSettings["LedMinBrightness"] == null)
                {
                    SettingsFunction.Save("LedMinBrightness", "10");
                }

                //Check - Led Minimum Color
                if (ConfigurationManager.AppSettings["LedMinColor"] == null)
                {
                    SettingsFunction.Save("LedMinColor", "5");
                }

                //Check - Led Color Red
                if (ConfigurationManager.AppSettings["LedColorRed"] == null)
                {
                    SettingsFunction.Save("LedColorRed", "100");
                }

                //Check - Led Color Green
                if (ConfigurationManager.AppSettings["LedColorGreen"] == null)
                {
                    SettingsFunction.Save("LedColorGreen", "100");
                }

                //Check - Led Color Blue
                if (ConfigurationManager.AppSettings["LedColorBlue"] == null)
                {
                    SettingsFunction.Save("LedColorBlue", "100");
                }

                //Check - Led Capture Range
                if (ConfigurationManager.AppSettings["LedCaptureRange"] == null)
                {
                    SettingsFunction.Save("LedCaptureRange", "20");
                }

                //Check - Led Side Types
                if (ConfigurationManager.AppSettings["LedSideFirst"] == null)
                {
                    SettingsFunction.Save("LedSideFirst", "0");
                }
                if (ConfigurationManager.AppSettings["LedSideSecond"] == null)
                {
                    SettingsFunction.Save("LedSideSecond", "0");
                }
                if (ConfigurationManager.AppSettings["LedSideThird"] == null)
                {
                    SettingsFunction.Save("LedSideThird", "0");
                }
                if (ConfigurationManager.AppSettings["LedSideFourth"] == null)
                {
                    SettingsFunction.Save("LedSideFourth", "0");
                }

                //Check - Led Count
                if (ConfigurationManager.AppSettings["LedCountFirst"] == null)
                {
                    SettingsFunction.Save("LedCountFirst", "0");
                }
                if (ConfigurationManager.AppSettings["LedCountSecond"] == null)
                {
                    SettingsFunction.Save("LedCountSecond", "0");
                }
                if (ConfigurationManager.AppSettings["LedCountThird"] == null)
                {
                    SettingsFunction.Save("LedCountThird", "0");
                }
                if (ConfigurationManager.AppSettings["LedCountFourth"] == null)
                {
                    SettingsFunction.Save("LedCountFourth", "0");
                }

                //Check - Led Output
                if (ConfigurationManager.AppSettings["LedOutput"] == null)
                {
                    SettingsFunction.Save("LedOutput", "0");
                }

                //Check - Update Rate
                if (ConfigurationManager.AppSettings["UpdateRate"] == null)
                {
                    SettingsFunction.Save("UpdateRate", "30");
                }

                //Check - Led Smoothing
                if (ConfigurationManager.AppSettings["LedSmoothing"] == null)
                {
                    SettingsFunction.Save("LedSmoothing", "1");
                }

                //Check - Debug Mode
                if (ConfigurationManager.AppSettings["DebugMode"] == null)
                {
                    SettingsFunction.Save("DebugMode", "False");
                }
                if (ConfigurationManager.AppSettings["DebugBlackBar"] == null)
                {
                    SettingsFunction.Save("DebugBlackBar", "False");
                }
                if (ConfigurationManager.AppSettings["DebugColor"] == null)
                {
                    SettingsFunction.Save("DebugColor", "True");
                }
                if (ConfigurationManager.AppSettings["DebugSave"] == null)
                {
                    SettingsFunction.Save("DebugSave", "False");
                }
            }
            catch
            {
                Debug.WriteLine("Failed to check the settings.");
            }
        }
コード例 #10
0
ファイル: Settings-Save.cs プロジェクト: dumbie/AmbiPro
        //Save led count after delay
        public async void SettingSaveLedCount(object sender, EventArgs e)
        {
            try
            {
                //Stop the timer
                vDispatcherTimer_SettingLedCount.Stop();

                //Color brushes
                BrushConverter BrushConvert = new BrushConverter();
                Brush          BrushInvalid = BrushConvert.ConvertFromString("#cd1a2b") as Brush;
                Brush          BrushValid   = BrushConvert.ConvertFromString("#1db954") as Brush;

                //Check the led count value
                bool invalidCount = false;
                if (string.IsNullOrWhiteSpace(textbox_LedCountFirst.Text))
                {
                    textbox_LedCountFirst.BorderBrush = BrushInvalid; invalidCount = true;
                }
                if (Regex.IsMatch(textbox_LedCountFirst.Text, "(\\D+)"))
                {
                    textbox_LedCountFirst.BorderBrush = BrushInvalid; invalidCount = true;
                }

                if (string.IsNullOrWhiteSpace(textbox_LedCountSecond.Text))
                {
                    textbox_LedCountSecond.BorderBrush = BrushInvalid; invalidCount = true;
                }
                if (Regex.IsMatch(textbox_LedCountSecond.Text, "(\\D+)"))
                {
                    textbox_LedCountSecond.BorderBrush = BrushInvalid; invalidCount = true;
                }

                if (string.IsNullOrWhiteSpace(textbox_LedCountThird.Text))
                {
                    textbox_LedCountThird.BorderBrush = BrushInvalid; invalidCount = true;
                }
                if (Regex.IsMatch(textbox_LedCountThird.Text, "(\\D+)"))
                {
                    textbox_LedCountThird.BorderBrush = BrushInvalid; invalidCount = true;
                }

                if (string.IsNullOrWhiteSpace(textbox_LedCountFourth.Text))
                {
                    textbox_LedCountFourth.BorderBrush = BrushInvalid; invalidCount = true;
                }
                if (Regex.IsMatch(textbox_LedCountFourth.Text, "(\\D+)"))
                {
                    textbox_LedCountFourth.BorderBrush = BrushInvalid; invalidCount = true;
                }
                if (invalidCount)
                {
                    return;
                }

                //Save the new led count setting
                SettingsFunction.Save("LedCountFirst", textbox_LedCountFirst.Text);
                SettingsFunction.Save("LedCountSecond", textbox_LedCountSecond.Text);
                SettingsFunction.Save("LedCountThird", textbox_LedCountThird.Text);
                SettingsFunction.Save("LedCountFourth", textbox_LedCountFourth.Text);
                textbox_LedCountFirst.BorderBrush  = BrushValid;
                textbox_LedCountSecond.BorderBrush = BrushValid;
                textbox_LedCountThird.BorderBrush  = BrushValid;
                textbox_LedCountFourth.BorderBrush = BrushValid;

                //Update total led count
                int totalCount = Convert.ToInt32(textbox_LedCountFirst.Text) + Convert.ToInt32(textbox_LedCountSecond.Text) + Convert.ToInt32(textbox_LedCountThird.Text) + Convert.ToInt32(textbox_LedCountFourth.Text);
                textblock_LedCount.Text = "Total led count: " + totalCount + " (must be equal with arduino script)";

                //Reset led rotate setting
                SettingResetLedRotate();

                //Restart the leds
                if (!Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                {
                    await LedSwitch(LedSwitches.Restart);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed saving ledcount: " + ex.Message);
            }
        }
コード例 #11
0
ファイル: Settings-Save.cs プロジェクト: dumbie/AmbiPro
        //Save - Application Settings
        public void SettingsSave()
        {
            try
            {
                Debug.WriteLine("Saving application settings...");

                //Save - Com Port
                cb_ComPort.SelectionChanged += async(sender, e) =>
                {
                    SettingsFunction.Save("ComPort", (cb_ComPort.SelectedIndex + 1).ToString());
                    if (!Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                    {
                        await LedSwitch(LedSwitches.Restart);
                    }
                };

                //Save - Baud Rate
                vDispatcherTimer_SettingBaudRate.Tick += SettingSaveBaudRate;
                textbox_BaudRate.TextChanged          += (sender, e) =>
                {
                    AVFunctions.TimerReset(vDispatcherTimer_SettingBaudRate);
                };

                //Save - Led Automatic Enable or Disable
                cb_LedAutoOnOffBefore.Click += (sender, e) =>
                {
                    bool enabledDisabled = (bool)cb_LedAutoOnOffBefore.IsChecked;
                    SettingsFunction.Save("LedAutoOnOffBefore", enabledDisabled.ToString());
                    timepicker_LedAutoTimeBefore.IsEnabled = enabledDisabled;
                };
                cb_LedAutoOnOffAfter.Click += (sender, e) =>
                {
                    bool enabledDisabled = (bool)cb_LedAutoOnOffAfter.IsChecked;
                    SettingsFunction.Save("LedAutoOnOffAfter", enabledDisabled.ToString());
                    timepicker_LedAutoTimeAfter.IsEnabled = enabledDisabled;
                };

                //Save - Led Automatic Time
                timepicker_LedAutoTimeBefore.DateTimeChanged += dateTime =>
                {
                    try
                    {
                        SettingsFunction.Save("LedAutoTimeBefore", dateTime.Value.ToString(vAppCultureInfo));
                    }
                    catch { }
                };
                timepicker_LedAutoTimeAfter.DateTimeChanged += dateTime =>
                {
                    try
                    {
                        SettingsFunction.Save("LedAutoTimeAfter", dateTime.Value.ToString(vAppCultureInfo));
                    }
                    catch { }
                };

                //Save - Server Port
                vDispatcherTimer_SettingServerPort.Tick += SettingSaveServerPort;
                tb_ServerPort.TextChanged += (sender, e) =>
                {
                    AVFunctions.TimerReset(vDispatcherTimer_SettingServerPort);
                };

                //Save - Adjust Black Bars
                cb_AdjustBlackBars.Click += async(sender, e) =>
                {
                    if ((bool)cb_AdjustBlackBars.IsChecked)
                    {
                        SettingsFunction.Save("AdjustBlackBars", "True");
                    }
                    else
                    {
                        SettingsFunction.Save("AdjustBlackBars", "False");
                    }
                    if (!Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                    {
                        await LedSwitch(LedSwitches.Restart);
                    }
                };

                //Save - Monitor Capture
                cb_MonitorCapture.SelectionChanged += async(sender, e) =>
                {
                    SettingsFunction.Save("MonitorCapture", cb_MonitorCapture.SelectedIndex.ToString());
                    if (!Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                    {
                        await LedSwitch(LedSwitches.Restart);
                        await UpdateSettingsInformation(true);
                    }
                };

                //Save - Led Mode
                cb_LedMode.SelectionChanged += async(sender, e) =>
                {
                    SettingsFunction.Save("LedMode", cb_LedMode.SelectedIndex.ToString());
                    if (!Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                    {
                        await LedSwitch(LedSwitches.Restart);
                        await UpdateSettingsInformation(true);
                    }
                };

                //Save - Led Bottom Gap
                sldr_LedBottomGap.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedBottomGap", sldr_LedBottomGap.Value.ToString("0"));
                    tb_LedBottomGap.Text = "Led gap bottom stand: " + sldr_LedBottomGap.Value.ToString("0") + " leds";
                };

                //Save - Led contrast level
                sldr_LedContrast.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedContrast", sldr_LedContrast.Value.ToString("0"));
                    tb_LedContrast.Text = "Contrast level: " + sldr_LedContrast.Value.ToString("0");
                };

                //Save - Led brightness level
                sldr_LedBrightness.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedBrightness", sldr_LedBrightness.Value.ToString("0"));
                    tb_LedBrightness.Text = "Brightness level: " + sldr_LedBrightness.Value.ToString("0") + "%";
                };

                //Save - Led Minimum Brightness
                sldr_LedMinBrightness.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedMinBrightness", sldr_LedMinBrightness.Value.ToString("0"));
                    tb_LedMinBrightness.Text = "Minimum brightness level: " + sldr_LedMinBrightness.Value.ToString("0") + "%";
                };

                //Save - Led Gamma
                sldr_LedGamma.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedGamma", sldr_LedGamma.Value.ToString("0"));
                    tb_LedGamma.Text = "Gamma level: " + sldr_LedGamma.Value.ToString("0") + "%";
                };

                //Save - Led Saturation
                sldr_LedSaturation.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedSaturation", sldr_LedSaturation.Value.ToString("0"));
                    tb_LedSaturation.Text = "Color saturation: " + sldr_LedSaturation.Value.ToString("0") + "%";
                };

                //Save - Led Temperature
                sldr_LedTemperature.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedTemperature", sldr_LedTemperature.Value.ToString("0"));
                    tb_LedTemperature.Text = "Color temperature: " + sldr_LedTemperature.Value.ToString("0") + "K";
                };

                //Save - Color Loop Speed
                sldr_ColorLoopSpeed.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("ColorLoopSpeed", sldr_ColorLoopSpeed.Value.ToString("0"));
                    tb_ColorLoopSpeed.Text = "Color loop speed: " + sldr_ColorLoopSpeed.Value.ToString("0") + " ms";
                };

                //Save - Spectrum Rotation Speed
                sldr_SpectrumRotationSpeed.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("SpectrumRotationSpeed", sldr_SpectrumRotationSpeed.Value.ToString("0"));
                    tb_SpectrumRotationSpeed.Text = "Spectrum rotation speed: " + sldr_SpectrumRotationSpeed.Value.ToString("0") + " sec";
                };

                //Select - Solid Led Color
                button_ColorPickerSolid.Click += async(sender, e) =>
                {
                    Color?newColor = await new AVColorPicker().Popup(null);
                    if (newColor != null)
                    {
                        SolidColorBrush newBrush = new SolidColorBrush((Color)newColor);
                        button_ColorPickerSolid.Background = newBrush;
                        SettingsFunction.Save("SolidLedColor", newColor.ToString());
                    }
                };

                //Save - Led Hue
                sldr_LedHue.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedHue2", sldr_LedHue.Value.ToString("0"));
                    tb_LedHue.Text = "Color hue: " + sldr_LedHue.Value.ToString("0") + "°";
                };

                //Save - Led Minimum Color
                sldr_LedMinColor.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedMinColor", sldr_LedMinColor.Value.ToString("0"));
                    tb_LedMinColor.Text = "Minimum color brightness: " + sldr_LedMinColor.Value.ToString("0") + "%";
                };

                //Save - Led Color Red
                sldr_LedColorRed.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedColorRed", sldr_LedColorRed.Value.ToString("0"));
                    tb_LedColorRed.Text = "Red: " + sldr_LedColorRed.Value.ToString("0") + "%";
                };

                //Save - Led Color Green
                sldr_LedColorGreen.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedColorGreen", sldr_LedColorGreen.Value.ToString("0"));
                    tb_LedColorGreen.Text = "Green: " + sldr_LedColorGreen.Value.ToString("0") + "%";
                };

                //Save - Led Color Blue
                sldr_LedColorBlue.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedColorBlue", sldr_LedColorBlue.Value.ToString("0"));
                    tb_LedColorBlue.Text = "Blue: " + sldr_LedColorBlue.Value.ToString("0") + "%";
                };

                //Save - Led Capture Range
                sldr_LedCaptureRange.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedCaptureRange", sldr_LedCaptureRange.Value.ToString("0"));
                    tb_LedCaptureRange.Text = "Led capture range: " + sldr_LedCaptureRange.Value.ToString("0") + "%";
                };

                //Save - Blackbar detect rate
                sldr_AdjustBlackbarRate.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("AdjustBlackbarRate", sldr_AdjustBlackbarRate.Value.ToString("0"));
                    tb_AdjustBlackbarRate.Text = "Blackbar detection rate: " + Convert.ToInt32(sldr_AdjustBlackbarRate.Value) + " ms";
                };

                //Save - Blackbar detect range
                sldr_AdjustBlackbarRange.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("AdjustBlackbarRange", sldr_AdjustBlackbarRange.Value.ToString("0"));
                    tb_AdjustBlackbarRange.Text = "Blackbar detection range: " + Convert.ToInt32(sldr_AdjustBlackbarRange.Value) + "%";
                };

                //Save - Adjust Black Bar Level
                sldr_AdjustBlackBarBrightness.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("AdjustBlackBarBrightness", sldr_AdjustBlackBarBrightness.Value.ToString("0"));
                    tb_AdjustBlackBarBrightness.Text = "Blackbar minimum brightness: " + sldr_AdjustBlackBarBrightness.Value.ToString("0") + "%";
                };

                //Save - Led Side Types
                combobox_LedSideFirst.SelectionChanged += async(sender, e) =>
                {
                    await SettingSaveLedSide("LedSideFirst", combobox_LedSideFirst.SelectedIndex.ToString());
                };
                combobox_LedSideSecond.SelectionChanged += async(sender, e) =>
                {
                    await SettingSaveLedSide("LedSideSecond", combobox_LedSideSecond.SelectedIndex.ToString());
                };
                combobox_LedSideThird.SelectionChanged += async(sender, e) =>
                {
                    await SettingSaveLedSide("LedSideThird", combobox_LedSideThird.SelectedIndex.ToString());
                };
                combobox_LedSideFourth.SelectionChanged += async(sender, e) =>
                {
                    await SettingSaveLedSide("LedSideFourth", combobox_LedSideFourth.SelectedIndex.ToString());
                };

                //Save - Led Count
                vDispatcherTimer_SettingLedCount.Tick += SettingSaveLedCount;
                textbox_LedCountFirst.TextChanged     += (sender, e) =>
                {
                    AVFunctions.TimerReset(vDispatcherTimer_SettingLedCount);
                };
                textbox_LedCountSecond.TextChanged += (sender, e) =>
                {
                    AVFunctions.TimerReset(vDispatcherTimer_SettingLedCount);
                };
                textbox_LedCountThird.TextChanged += (sender, e) =>
                {
                    AVFunctions.TimerReset(vDispatcherTimer_SettingLedCount);
                };
                textbox_LedCountFourth.TextChanged += (sender, e) =>
                {
                    AVFunctions.TimerReset(vDispatcherTimer_SettingLedCount);
                };

                //Save - Led Output
                cb_LedOutput.SelectionChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedOutput", cb_LedOutput.SelectedIndex.ToString());
                };

                //Save - Update Rate
                sldr_UpdateRate.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("UpdateRate", sldr_UpdateRate.Value.ToString("0"));
                    int    updateRateMs  = Convert.ToInt32(sldr_UpdateRate.Value);
                    string updateRateFps = Convert.ToInt32(1000 / updateRateMs).ToString();
                    tb_UpdateRate.Text = "Led update rate: " + updateRateMs + " ms (" + updateRateFps + " fps)";
                };

                //Save - Led Smoothing
                sldr_LedSmoothing.ValueChanged += (sender, e) =>
                {
                    SettingsFunction.Save("LedSmoothing", sldr_LedSmoothing.Value.ToString("0"));
                    int smoothingFrames = Convert.ToInt32(sldr_LedSmoothing.Value);
                    tb_LedSmoothing.Text = "Led smoothing: " + smoothingFrames + " frames";
                };

                //Save - Windows Startup
                cb_WindowsStartup.Click += (sender, e) => { ManageShortcutStartup(); };

                //Save - Debug mode
                checkbox_DebugMode.Click += (sender, e) =>
                {
                    if ((bool)checkbox_DebugMode.IsChecked)
                    {
                        SettingsFunction.Save("DebugMode", "True");
                    }
                    else
                    {
                        SettingsFunction.Save("DebugMode", "False");
                    }
                };

                //Save - Debug BlackBar
                checkbox_DebugBlackBar.Click += (sender, e) =>
                {
                    if ((bool)checkbox_DebugBlackBar.IsChecked)
                    {
                        SettingsFunction.Save("DebugBlackBar", "True");
                    }
                    else
                    {
                        SettingsFunction.Save("DebugBlackBar", "False");
                    }
                };

                //Save - Debug color
                checkbox_DebugColor.Click += (sender, e) =>
                {
                    if ((bool)checkbox_DebugColor.IsChecked)
                    {
                        SettingsFunction.Save("DebugColor", "True");
                    }
                    else
                    {
                        SettingsFunction.Save("DebugColor", "False");
                    }
                };

                //Save - Debug Save
                checkbox_DebugSave.Click += (sender, e) =>
                {
                    if ((bool)checkbox_DebugSave.IsChecked)
                    {
                        SettingsFunction.Save("DebugSave", "True");
                    }
                    else
                    {
                        SettingsFunction.Save("DebugSave", "False");
                    }
                };
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to save the settings: " + ex.Message);
            }
        }
コード例 #12
0
        //Load - Application Settings
        public void SettingsLoad()
        {
            try
            {
                Debug.WriteLine("Loading application settings...");

                //Check connected com ports
                foreach (string PortName in SerialPort.GetPortNames())
                {
                    int PortNumberRaw = Convert.ToInt32(PortName.Replace("COM", string.Empty));
                    cb_ComPort.Items[PortNumberRaw - 1] = PortName + " (Connected)";

                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["FirstLaunch2"]))
                    {
                        SettingsFunction.Save("ComPort", PortNumberRaw.ToString());
                    }
                }

                //Load - Com Port
                cb_ComPort.SelectedIndex = (Convert.ToInt32(ConfigurationManager.AppSettings["ComPort"]) - 1);

                //Load - Baud Rate
                textbox_BaudRate.Text = ConfigurationManager.AppSettings["BaudRate"].ToString();

                //Load - Led Automatic Before
                bool LedAutoOnOffBefore = Convert.ToBoolean(ConfigurationManager.AppSettings["LedAutoOnOffBefore"]);
                cb_LedAutoOnOffBefore.IsChecked            = LedAutoOnOffBefore;
                timepicker_LedAutoTimeBefore.IsEnabled     = LedAutoOnOffBefore;
                timepicker_LedAutoTimeBefore.DateTimeValue = DateTime.Parse(ConfigurationManager.AppSettings["LedAutoTimeBefore"], vAppCultureInfo);

                //Load - Led Automatic After
                bool LedAutoOnOffAfter = Convert.ToBoolean(ConfigurationManager.AppSettings["LedAutoOnOffAfter"]);
                cb_LedAutoOnOffAfter.IsChecked            = LedAutoOnOffAfter;
                timepicker_LedAutoTimeAfter.IsEnabled     = LedAutoOnOffAfter;
                timepicker_LedAutoTimeAfter.DateTimeValue = DateTime.Parse(ConfigurationManager.AppSettings["LedAutoTimeAfter"], vAppCultureInfo);

                //Load - Server Port
                tb_ServerPort.Text = ConfigurationManager.AppSettings["ServerPort"].ToString();

                //Load - Monitor Capture
                cb_MonitorCapture.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["MonitorCapture"]);

                //Load - Led Mode
                cb_LedMode.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["LedMode"]);

                //Load - Adjust Black Bars
                cb_AdjustBlackBars.IsChecked = Convert.ToBoolean(ConfigurationManager.AppSettings["AdjustBlackBars"]);

                //Load - Led Bottom Gap
                tb_LedBottomGap.Text    = "Led gap bottom stand: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedBottomGap"]) + " leds";
                sldr_LedBottomGap.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedBottomGap"]);

                //Load - Led contrast level
                tb_LedContrast.Text    = "Contrast level: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedContrast"]);
                sldr_LedContrast.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedContrast"]);

                //Load - Led brightness level
                tb_LedBrightness.Text    = "Brightness level: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedBrightness"]) + "%";
                sldr_LedBrightness.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedBrightness"]);

                //Load - Led Minimum Brightness
                tb_LedMinBrightness.Text    = "Minimum brightness level: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedMinBrightness"]) + "%";
                sldr_LedMinBrightness.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedMinBrightness"]);

                //Load - Led Gamma
                tb_LedGamma.Text    = "Gamma level: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedGamma"]) + "%";
                sldr_LedGamma.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedGamma"]);

                //Load - Led Saturation
                tb_LedSaturation.Text    = "Color saturation: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedSaturation"]) + "%";
                sldr_LedSaturation.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedSaturation"]);

                //Load - Led Temperature
                tb_LedTemperature.Text    = "Color temperature: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedTemperature"]) + "K";
                sldr_LedTemperature.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedTemperature"]);

                //Load - Color Loop Speed
                tb_ColorLoopSpeed.Text    = "Color loop speed: " + Convert.ToInt32(ConfigurationManager.AppSettings["ColorLoopSpeed"]) + " ms";
                sldr_ColorLoopSpeed.Value = Convert.ToInt32(ConfigurationManager.AppSettings["ColorLoopSpeed"]);

                //Load - Spectrum Rotation Speed
                tb_SpectrumRotationSpeed.Text    = "Spectrum rotation speed: " + Convert.ToInt32(ConfigurationManager.AppSettings["SpectrumRotationSpeed"]) + " sec";
                sldr_SpectrumRotationSpeed.Value = Convert.ToInt32(ConfigurationManager.AppSettings["SpectrumRotationSpeed"]);

                //Load - Solid Led Color
                string SolidLedColor = ConfigurationManager.AppSettings["SolidLedColor"].ToString();
                button_ColorPickerSolid.Background = new BrushConverter().ConvertFrom(SolidLedColor) as SolidColorBrush;

                //Load - Led Hue
                tb_LedHue.Text    = "Color hue: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedHue2"]) + "°";
                sldr_LedHue.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedHue2"]);

                //Load - Led Minimum Color
                tb_LedMinColor.Text    = "Minimum color brightness: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedMinColor"]) + "%";
                sldr_LedMinColor.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedMinColor"]);

                //Load - Led Color Red
                tb_LedColorRed.Text    = "Red: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedColorRed"]) + "%";
                sldr_LedColorRed.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedColorRed"]);

                //Load - Led Color Green
                tb_LedColorGreen.Text    = "Green: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedColorGreen"]) + "%";
                sldr_LedColorGreen.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedColorGreen"]);

                //Load - Led Color Blue
                tb_LedColorBlue.Text    = "Blue: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedColorBlue"]) + "%";
                sldr_LedColorBlue.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedColorBlue"]);

                //Load - Led Capture Range
                tb_LedCaptureRange.Text    = "Led capture range: " + Convert.ToInt32(ConfigurationManager.AppSettings["LedCaptureRange"]) + "%";
                sldr_LedCaptureRange.Value = Convert.ToInt32(ConfigurationManager.AppSettings["LedCaptureRange"]);

                //Load - Blackbar detect rate
                tb_AdjustBlackbarRate.Text    = "Blackbar detection rate: " + Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackbarRate"]) + " ms";
                sldr_AdjustBlackbarRate.Value = Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackbarRate"]);

                //Load - Blackbar detect range
                tb_AdjustBlackbarRange.Text    = "Blackbar detection range: " + Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackbarRange"]) + "%";
                sldr_AdjustBlackbarRange.Value = Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackbarRange"]);

                //Load - Adjust Blackbar Brightness
                tb_AdjustBlackBarBrightness.Text    = "Blackbar minimum brightness: " + Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackBarBrightness"]) + "%";
                sldr_AdjustBlackBarBrightness.Value = Convert.ToInt32(ConfigurationManager.AppSettings["AdjustBlackBarBrightness"]);

                //Load - Led Side Types
                combobox_LedSideFirst.SelectedIndex  = Convert.ToInt32(ConfigurationManager.AppSettings["LedSideFirst"]);
                combobox_LedSideSecond.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["LedSideSecond"]);
                combobox_LedSideThird.SelectedIndex  = Convert.ToInt32(ConfigurationManager.AppSettings["LedSideThird"]);
                combobox_LedSideFourth.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["LedSideFourth"]);

                //Load - Led Count
                textbox_LedCountFirst.Text  = Convert.ToString(ConfigurationManager.AppSettings["LedCountFirst"]);
                textbox_LedCountSecond.Text = Convert.ToString(ConfigurationManager.AppSettings["LedCountSecond"]);
                textbox_LedCountThird.Text  = Convert.ToString(ConfigurationManager.AppSettings["LedCountThird"]);
                textbox_LedCountFourth.Text = Convert.ToString(ConfigurationManager.AppSettings["LedCountFourth"]);
                int totalCount = Convert.ToInt32(textbox_LedCountFirst.Text) + Convert.ToInt32(textbox_LedCountSecond.Text) + Convert.ToInt32(textbox_LedCountThird.Text) + Convert.ToInt32(textbox_LedCountFourth.Text);
                textblock_LedCount.Text = "Total led count: " + totalCount + " (must be equal with arduino script)";

                //Load - Led Output
                cb_LedOutput.SelectedIndex = Convert.ToInt32(ConfigurationManager.AppSettings["LedOutput"]);

                //Load - Update Rate
                int    updateRateMs  = Convert.ToInt32(ConfigurationManager.AppSettings["UpdateRate"]);
                string updateRateFps = Convert.ToInt32(1000 / updateRateMs).ToString();
                tb_UpdateRate.Text    = "Led update rate: " + updateRateMs + " ms (" + updateRateFps + " fps)";
                sldr_UpdateRate.Value = updateRateMs;

                //Load - Led Smoothing
                int smoothingFrames = Convert.ToInt32(ConfigurationManager.AppSettings["LedSmoothing"]);
                tb_LedSmoothing.Text    = "Led smoothing: " + smoothingFrames + " frames";
                sldr_LedSmoothing.Value = smoothingFrames;

                //Load - Debug Mode
                checkbox_DebugMode.IsChecked     = Convert.ToBoolean(ConfigurationManager.AppSettings["DebugMode"]);
                checkbox_DebugBlackBar.IsChecked = Convert.ToBoolean(ConfigurationManager.AppSettings["DebugBlackBar"]);
                checkbox_DebugColor.IsChecked    = Convert.ToBoolean(ConfigurationManager.AppSettings["DebugColor"]);
                checkbox_DebugSave.IsChecked     = Convert.ToBoolean(ConfigurationManager.AppSettings["DebugSave"]);

                //Check if application is set to launch on Windows startup
                string targetName         = Assembly.GetEntryAssembly().GetName().Name;
                string targetFileShortcut = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), targetName + ".url");
                if (File.Exists(targetFileShortcut))
                {
                    cb_WindowsStartup.IsChecked = true;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to load the settings: " + ex.Message);
            }
        }