diff --git a/GPSDOTimeSync/App.config b/GPSDOTimeSync/App.config index 88fa402..71ec018 100644 --- a/GPSDOTimeSync/App.config +++ b/GPSDOTimeSync/App.config @@ -1,6 +1,33 @@  + + +
+ + + + + + 10 + + + False + + + 1 + + + 0 + + + + + + + + + \ No newline at end of file diff --git a/GPSDOTimeSync/FormMain.cs b/GPSDOTimeSync/FormMain.cs index 179e277..a8917a9 100644 --- a/GPSDOTimeSync/FormMain.cs +++ b/GPSDOTimeSync/FormMain.cs @@ -42,10 +42,15 @@ namespace GPSDOTimeSync { private int lastSystemTimeUpdate; private ITimeProvider timeProvider; + Properties.Settings settings; + public FormMain() { InitializeComponent(); PopulateDropDowns(); + settings = Properties.Settings.Default; + LoadSettings(); + lastSystemTimeUpdate = 0; statusStrip.Renderer = new TruncatedTextEllipsisRenderer(); @@ -146,7 +151,7 @@ namespace GPSDOTimeSync { string serialPortName = (string) comboBoxSerialPortNames.SelectedItem; string deviceName = (string) comboBoxDeviceNames.SelectedItem; - SerialPort serialPort = new SerialPort(serialPortName); + SerialPort serialPort = new SerialPort(serialPortName); timeProvider = TIME_PROVIDER_CONSTRUCTORS[deviceName](serialPort); ConfigureTimeProvider(); @@ -181,6 +186,75 @@ namespace GPSDOTimeSync { DateTime systemTime = SystemTimeUtils.GetSystemTime(); labelCurrentDateTime.Text = systemTime.ToString("HH:mm:ss\ndd\\/MM\\/yyyy\nUTC"); } + + #region Settings Management + private int GetIndexOfComboBoxStringItem(ComboBox comboBox, string itemText) { + for (int i = 0; i < comboBox.Items.Count; ++i) { + if ((string) comboBox.Items[i] == itemText) { + return i; + } + } + + return 0; + } + + private void LoadSettings() { + // Populate values + comboBoxDeviceNames.SelectedIndex = GetIndexOfComboBoxStringItem(comboBoxDeviceNames, settings.deviceName); + comboBoxSerialPortNames.SelectedIndex = GetIndexOfComboBoxStringItem(comboBoxSerialPortNames, settings.serialPortName); + + checkBoxMaximumCorrectionEnabled.Checked = settings.maximumCorrectionEnabled; + numericUpDownMaximumCorrection.Value = settings.maximumCorrection; + comboBoxMaximumCorrectionUnit.SelectedIndex = GetIndexOfComboBoxStringItem(comboBoxMaximumCorrectionUnit, settings.maximumCorrectionUnit); + + numericUpDownMimimumUpdateInterval.Value = settings.minimumUpdateInterval; + + // Add event listeners + comboBoxDeviceNames.SelectedIndexChanged += comboBoxDeviceNames_SelectedIndexChanged_UpdateSettings; + comboBoxSerialPortNames.SelectedIndexChanged += comboBoxSerialPortNames_SelectedIndexChanged_UpdateSettings; + + checkBoxMaximumCorrectionEnabled.CheckedChanged += checkBoxMaximumCorrectionEnabled_CheckedChanged_UpdateSettings; + numericUpDownMaximumCorrection.ValueChanged += numericUpDownMaximumCorrection_ValueChanged_UpdateSettings; + comboBoxMaximumCorrectionUnit.SelectedIndexChanged += comboBoxMaximumCorrectionUnit_SelectedIndexChanged_UpdateSettings; + + numericUpDownMimimumUpdateInterval.ValueChanged += numericUpDownMimimumUpdateInterval_ValueChanged_UpdateSettings; + + // Push possible changes through + comboBoxDeviceNames_SelectedIndexChanged_UpdateSettings(null, null); + comboBoxSerialPortNames_SelectedIndexChanged_UpdateSettings(null, null); + comboBoxMaximumCorrectionUnit_SelectedIndexChanged_UpdateSettings(null, null); + } + + private void comboBoxDeviceNames_SelectedIndexChanged_UpdateSettings(object sender, EventArgs e) { + settings.deviceName = (string) comboBoxDeviceNames.SelectedItem; + settings.Save(); + } + + private void comboBoxSerialPortNames_SelectedIndexChanged_UpdateSettings(object sender, EventArgs e) { + settings.serialPortName = (string) comboBoxSerialPortNames.SelectedItem; + settings.Save(); + } + + private void checkBoxMaximumCorrectionEnabled_CheckedChanged_UpdateSettings(object sender, EventArgs e) { + settings.maximumCorrectionEnabled = checkBoxMaximumCorrectionEnabled.Checked; + settings.Save(); + } + + private void numericUpDownMaximumCorrection_ValueChanged_UpdateSettings(object sender, EventArgs e) { + settings.maximumCorrection = numericUpDownMaximumCorrection.Value; + settings.Save(); + } + + private void comboBoxMaximumCorrectionUnit_SelectedIndexChanged_UpdateSettings(object sender, EventArgs e) { + settings.maximumCorrectionUnit = (string) comboBoxMaximumCorrectionUnit.SelectedItem; + settings.Save(); + } + + private void numericUpDownMimimumUpdateInterval_ValueChanged_UpdateSettings(object sender, EventArgs e) { + settings.minimumUpdateInterval = numericUpDownMimimumUpdateInterval.Value; + settings.Save(); + } + #endregion } public class TruncatedTextEllipsisRenderer : ToolStripProfessionalRenderer { diff --git a/GPSDOTimeSync/Properties/Settings.Designer.cs b/GPSDOTimeSync/Properties/Settings.Designer.cs index 58bc091..01d5c9a 100644 --- a/GPSDOTimeSync/Properties/Settings.Designer.cs +++ b/GPSDOTimeSync/Properties/Settings.Designer.cs @@ -9,18 +9,90 @@ //------------------------------------------------------------------------------ namespace GPSDOTimeSync.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings) (global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - } + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("10")] + public decimal minimumUpdateInterval { + get { + return ((decimal)(this["minimumUpdateInterval"])); + } + set { + this["minimumUpdateInterval"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool maximumCorrectionEnabled { + get { + return ((bool)(this["maximumCorrectionEnabled"])); + } + set { + this["maximumCorrectionEnabled"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("1")] + public decimal maximumCorrection { + get { + return ((decimal)(this["maximumCorrection"])); + } + set { + this["maximumCorrection"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public string maximumCorrectionUnit { + get { + return ((string)(this["maximumCorrectionUnit"])); + } + set { + this["maximumCorrectionUnit"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string deviceName { + get { + return ((string)(this["deviceName"])); + } + set { + this["deviceName"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string serialPortName { + get { + return ((string)(this["serialPortName"])); + } + set { + this["serialPortName"] = value; + } + } + } } diff --git a/GPSDOTimeSync/Properties/Settings.settings b/GPSDOTimeSync/Properties/Settings.settings index 3964565..ff86dae 100644 --- a/GPSDOTimeSync/Properties/Settings.settings +++ b/GPSDOTimeSync/Properties/Settings.settings @@ -1,7 +1,24 @@  - - - - - - + + + + + 10 + + + False + + + 1 + + + 0 + + + + + + + + + \ No newline at end of file