From db06002ebf44d462169452e32b2a32c578bd1e16 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 26 Feb 2021 00:11:44 +0000 Subject: [PATCH] Added support for SlewSettleTime --- .../TelescopeUnitTests.cs | 48 +++++-- Meade.net.Telescope/Telescope.cs | 10 +- Meade.net/MeadeTelescopeBase.cs | 3 + Meade.net/ProfileProperties.cs | 1 + Meade.net/SetupDialogForm.cs | 6 +- Meade.net/SetupDialogForm.designer.cs | 31 +++++ Meade.net/SetupDialogForm.resx | 127 ++++++++++++++---- Meade.net/SharedResources.cs | 4 + 8 files changed, 189 insertions(+), 41 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 1afc3e7..7989e84 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1633,25 +1633,55 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void SlewSettleTime_Get_ThenThrowsException() + public void SlewSettleTime_Get_WhenNotConnected_ThenThrowsException() { - var excpetion = Assert.Throws(() => + var exception = Assert.Throws(() => { var result = _telescope.SlewSettleTime; Assert.Fail($"{result} should not have returned"); }); - - Assert.That(excpetion.Property, Is.EqualTo("SlewSettleTime")); - Assert.That(excpetion.AccessorSet, Is.False); + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Get")); } [Test] - public void SlewSettleTime_Set_ThenThrowsException() + public void SlewSettleTime_Set_WhenNotConnected_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.SlewSettleTime = 0; }); + var exception = Assert.Throws(() => + { + _telescope.SlewSettleTime = 13; + Assert.Fail($"should not have returned"); + }); + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Set")); + } - Assert.That(excpetion.Property, Is.EqualTo("SlewSettleTime")); - Assert.That(excpetion.AccessorSet, Is.True); + [TestCase(5)] + [TestCase(10)] + [TestCase(2)] + public void SlewSettleTime_Get_ReturnsExpectedValue(short settleTime) + { + _profileProperties.SettleTime = settleTime; + + ConnectTelescope(); + + var result = _telescope.SlewSettleTime; + + Assert.That(result, Is.EqualTo(settleTime)); + } + + [TestCase(8)] + [TestCase(12)] + [TestCase(3)] + public void SlewSettleTime_Set_ThenReturnsNewSettleTime(short settleTime) + { + _profileProperties.SettleTime = 0; + + ConnectTelescope(); + + _telescope.SlewSettleTime = settleTime; + + var result = _telescope.SlewSettleTime; + + Assert.That(result, Is.EqualTo(settleTime)); } [Test] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index bf06b16..b1fe144 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1774,14 +1774,16 @@ namespace ASCOM.Meade.net { get { - LogMessage("SlewSettleTime Get", "Not implemented"); - throw new PropertyNotImplementedException("SlewSettleTime", false); + CheckConnected("SlewSettleTime Get"); + LogMessage("SlewSettleTime Get", $"{SettleTime} Seconds"); + return SettleTime; } // ReSharper disable once ValueParameterNotUsed set { - LogMessage("SlewSettleTime Set", "Not implemented"); - throw new PropertyNotImplementedException("SlewSettleTime", true); + CheckConnected("SlewSettleTime Set"); + LogMessage("SlewSettleTime Set", $"Setting from {SettleTime} to {value}"); + SettleTime = value; } } diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index 1250461..6fd1d53 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -27,6 +27,7 @@ namespace ASCOM.Meade.net protected string Precision; protected string GuidingStyle; protected double SiteElevation; + protected short SettleTime; protected readonly ISharedResourcesWrapper SharedResourcesWrapper; @@ -67,6 +68,7 @@ namespace ASCOM.Meade.net Precision = profileProperties.Precision; GuidingStyle = profileProperties.GuidingStyle.ToLower(); SiteElevation = profileProperties.SiteElevation; + SettleTime = profileProperties.SettleTime; LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {ComPort}"); @@ -76,6 +78,7 @@ namespace ASCOM.Meade.net LogMessage("ReadProfile", $"Precision: {Precision}"); LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}"); LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}"); + LogMessage("ReadProfile", $"Settle Time after slew: {SettleTime}"); } /// diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index f5155c4..b4f11cc 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -13,5 +13,6 @@ namespace ASCOM.Meade.net public bool DynamicBreaking { get; set; } public bool RtsDtrEnabled { get; set; } public double SiteElevation { get; set; } + public short SettleTime { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index b6a7208..52d1e90 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -88,6 +88,7 @@ namespace ASCOM.Meade.net cbxReverseDirection.Checked = profileProperties.ReverseFocusDirection; cbxDynamicBreaking.Checked = profileProperties.DynamicBreaking; + nudSettleTime.Value = profileProperties.SettleTime; } public ProfileProperties GetProfile() @@ -103,8 +104,9 @@ namespace ASCOM.Meade.net BacklashCompensation = int.Parse(txtBacklashSteps.Text), ReverseFocusDirection = cbxReverseDirection.Checked, DynamicBreaking = cbxDynamicBreaking.Checked, - SiteElevation = double.Parse(txtElevation.Text) - }; + SiteElevation = double.Parse(txtElevation.Text), + SettleTime = Convert.ToInt16(nudSettleTime.Value) + }; return profileProperties; } diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 4d23524..d0858bd 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -61,7 +61,11 @@ namespace ASCOM.Meade.net this.label12 = new System.Windows.Forms.Label(); this.txtElevation = new System.Windows.Forms.TextBox(); this.label13 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.nudSettleTime = new System.Windows.Forms.NumericUpDown(); + this.label15 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); this.SuspendLayout(); // // cmdOK @@ -231,10 +235,33 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label13, "label13"); this.label13.Name = "label13"; // + // label14 + // + resources.ApplyResources(this.label14, "label14"); + this.label14.Name = "label14"; + // + // nudSettleTime + // + resources.ApplyResources(this.nudSettleTime, "nudSettleTime"); + this.nudSettleTime.Maximum = new decimal(new int[] { + 32767, + 0, + 0, + 0}); + this.nudSettleTime.Name = "nudSettleTime"; + // + // label15 + // + resources.ApplyResources(this.label15, "label15"); + this.label15.Name = "label15"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label15); + this.Controls.Add(this.nudSettleTime); + this.Controls.Add(this.label14); this.Controls.Add(this.label13); this.Controls.Add(this.txtElevation); this.Controls.Add(this.label12); @@ -270,6 +297,7 @@ namespace ASCOM.Meade.net this.TopMost = true; this.Shown += new System.EventHandler(this.SetupDialogForm_Shown); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -305,5 +333,8 @@ namespace ASCOM.Meade.net private Label label12; private TextBox txtElevation; private Label label13; + private Label label14; + private NumericUpDown nudSettleTime; + private Label label15; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index a71d20e..73de650 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 26 + 29 Bottom, Right @@ -172,7 +172,7 @@ $this - 25 + 28 12, 9 @@ -196,7 +196,7 @@ $this - 24 + 27 Top, Right @@ -223,7 +223,7 @@ $this - 23 + 26 True @@ -250,7 +250,7 @@ $this - 22 + 25 True @@ -277,7 +277,7 @@ $this - 21 + 24 97, 87 @@ -298,7 +298,7 @@ $this - 20 + 23 True @@ -325,7 +325,7 @@ $this - 19 + 22 97, 275 @@ -349,7 +349,7 @@ $this - 18 + 21 True @@ -376,7 +376,7 @@ $this - 17 + 20 True @@ -403,7 +403,7 @@ $this - 16 + 19 True @@ -430,7 +430,7 @@ $this - 15 + 18 Unchanged @@ -460,7 +460,7 @@ $this - 14 + 17 True @@ -490,7 +490,7 @@ $this - 13 + 16 Auto @@ -520,7 +520,7 @@ $this - 12 + 15 True @@ -550,7 +550,7 @@ $this - 11 + 14 True @@ -583,7 +583,7 @@ $this - 10 + 13 97, 411 @@ -607,7 +607,7 @@ $this - 8 + 11 True @@ -637,7 +637,7 @@ $this - 9 + 12 True @@ -667,7 +667,7 @@ $this - 7 + 10 True @@ -700,7 +700,7 @@ $this - 6 + 9 True @@ -727,7 +727,7 @@ $this - 5 + 8 True @@ -754,7 +754,7 @@ $this - 4 + 7 17, 17 @@ -790,7 +790,7 @@ $this - 3 + 6 17, 17 @@ -820,7 +820,7 @@ $this - 2 + 5 97, 202 @@ -841,7 +841,7 @@ $this - 1 + 4 True @@ -868,6 +868,81 @@ $this + 3 + + + True + + + 12, 236 + + + 56, 13 + + + 25 + + + Settle time + + + label14 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + 97, 234 + + + 120, 20 + + + 26 + + + nudSettleTime + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + 223, 236 + + + 47, 13 + + + 27 + + + seconds + + + label15 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 625e9ed..691e28d 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -146,6 +146,7 @@ namespace ASCOM.Meade.net private const string ReverseFocusDirectionName = "Reverse Focuser Direction"; private const string DynamicBreakingName = "Dynamic Breaking"; private const string SiteElevationName = "Site Elevation"; + private const string SettleTimeName = "Settle Time"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -164,6 +165,7 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, ReverseFocusDirectionName, profileProperties.ReverseFocusDirection.ToString()); driverProfile.WriteValue(DriverId, DynamicBreakingName, profileProperties.DynamicBreaking.ToString()); driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString()); + driverProfile.WriteValue(DriverId, SettleTimeName, profileProperties.SettleTime.ToString()); } } } @@ -178,6 +180,7 @@ namespace ASCOM.Meade.net private const string ReverseFocuserDiectionDefault = "true"; private const string DynamicBreakingDefault = "true"; private const string SiteElevationDefault = "0"; + private const string SettleTimeDefault = "2"; public static ProfileProperties ReadProfile() { @@ -197,6 +200,7 @@ namespace ASCOM.Meade.net profileProperties.ReverseFocusDirection = Convert.ToBoolean(driverProfile.GetValue(DriverId, ReverseFocusDirectionName, string.Empty, ReverseFocuserDiectionDefault)); profileProperties.DynamicBreaking = Convert.ToBoolean(driverProfile.GetValue(DriverId, DynamicBreakingName, string.Empty, DynamicBreakingDefault)); profileProperties.SiteElevation = Convert.ToInt32(driverProfile.GetValue(DriverId, SiteElevationName, string.Empty, SiteElevationDefault)); + profileProperties.SettleTime = Convert.ToInt16(driverProfile.GetValue(DriverId, SettleTimeName, string.Empty, SettleTimeDefault)); } return profileProperties;