diff --git a/Meade.net.Setup/Config.wxi b/Meade.net.Setup/Config.wxi index aed1c3c..c82ae63 100644 --- a/Meade.net.Setup/Config.wxi +++ b/Meade.net.Setup/Config.wxi @@ -11,7 +11,7 @@ UpgradeCode must be unique to this product and should not be changed for the product lifetime. --> - + diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index ec57f83..6f0f5d0 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -31,6 +31,7 @@ namespace Meade.net.Telescope.UnitTests _profileProperties.TraceLogger = false; _profileProperties.ComPort = "TestCom1"; _profileProperties.GuideRateArcSecondsPerSecond = 1.23; + _profileProperties.Precision = "Unchanged"; _utilMock = new Mock(); _utilExtraMock = new Mock(); @@ -734,6 +735,42 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.True); } + [Test] + public void Precision_Set_WhenConnectedAndPrecisionSetUnChanged_ThenDoesNotSetPrecision() + { + _telescope.Connected = true; + + _sharedResourcesWrapperMock.Verify( x => x.SendString(":P#"), Times.Never); + } + + [TestCase("High", false, true)] + [TestCase("High", true, true)] + [TestCase("Low", false, false)] + [TestCase("Low", true, false)] + public void Precision_Set_WhenConnectedAndPrecisionSetHighScopeIsLow_ThenTelescopePrecisionChanged(string desiredPresision, bool telescopePrecision, bool finalPrecision) + { + _profileProperties.Precision = desiredPresision; + var currentPrecision = telescopePrecision; + + _sharedResourcesWrapperMock.Setup(x => x.SendChar(":P#")).Returns(() => + { + currentPrecision = !currentPrecision; + + switch (currentPrecision) + { + case true: + return "H"; + default: + return "L"; + } + }); + + _telescope.Connected = true; + + Assert.That(currentPrecision, Is.EqualTo(finalPrecision)); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.AtLeastOnce); + } + [Test] public void CanSetPark_Get_ReturnsFalse() { diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index a88b23d..913033e 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -243,6 +243,8 @@ namespace ASCOM.Meade.net var parames = actionParameters.ToLower().Split(' '); switch (parames[0]) { + case "count": + return "4"; case "select": switch (parames[1]) { @@ -391,6 +393,7 @@ namespace ASCOM.Meade.net SetNewGuideRate( _guideRate, "Connect" ); } + SetTelescopePrecision("Connect"); } catch (Exception) { @@ -412,6 +415,24 @@ namespace ASCOM.Meade.net } } + private void SetTelescopePrecision(string propertyName) + { + switch (_precision.ToLower()) + { + case "high": + TelescopePointingPrecision(true); + LogMessage(propertyName, $"High precision slewing selected"); + break; + case "low": + TelescopePointingPrecision(false); + LogMessage(propertyName, $"Low precision slewing selected"); + break; + default: + LogMessage(propertyName, $"Precision slewing unchanged"); + break; + } + } + public bool IsNewPulseGuidingSupported() { if (_sharedResourcesWrapper.ProductName == TelescopeList.Autostar497) @@ -466,6 +487,45 @@ namespace ASCOM.Meade.net }); } + private bool TogglePrecision() + { + LogMessage("TogglePrecision", $"Toggling slewing precision"); + var result = _sharedResourcesWrapper.SendChar(":P#"); + //:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target. + //Returns: + //“HIGH PRECISION” Current setting after this command. + //“LOW PRECISION” Current setting after this command. + + int throwAwayCharacters = "LOW PRECISION".Length - 1; + + LogMessage("TogglePrecision", $"Result: {result}"); + bool highPrecision = false; + switch (result) + { + case "H": + highPrecision = true; + throwAwayCharacters = "HIGH PRECISION".Length - 1; + break; + } + + _sharedResourcesWrapper.ReadCharacters(throwAwayCharacters); + + //Make sure that the buffers are cleared out. + _sharedResourcesWrapper.SendBlind("#"); + + return highPrecision; + } + + public void TelescopePointingPrecision(bool high) + { + var currentPrecision = TogglePrecision(); + + while (currentPrecision != high) + { + currentPrecision = TogglePrecision(); + } + } + public void SelectSite(int site) { CheckConnected("SelectSite"); @@ -1963,6 +2023,7 @@ namespace ASCOM.Meade.net } private DriveRates _trackingRate = DriveRates.driveSidereal; + private string _precision; public DriveRates TrackingRate { @@ -2249,10 +2310,12 @@ namespace ASCOM.Meade.net _tl.Enabled = profileProperties.TraceLogger; _comPort = profileProperties.ComPort; _guideRate = profileProperties.GuideRateArcSecondsPerSecond; + _precision = profileProperties.Precision; LogMessage("ReadProfile", $"Trace logger enabled: {_tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {_comPort}"); LogMessage("ReadProfile", $"Guide Rate: {_guideRate}"); + LogMessage("ReadProfile", $"Precision: {_precision}"); } internal void WriteProfile() diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index 6614cc8..02f047a 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -6,5 +6,6 @@ namespace ASCOM.Meade.net public string ComPort { get; set; } public bool TraceLogger { get; set; } public double GuideRateArcSecondsPerSecond { get; set; } + public string Precision { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 36c8dac..874ecbc 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -49,15 +49,24 @@ namespace ASCOM.Meade.net } txtGuideRate.Text = profileProperties.GuideRateArcSecondsPerSecond.ToString(); + try + { + cboPrecision.SelectedItem = profileProperties.Precision; + } + catch (Exception e) + { + cboPrecision.SelectedItem = "Unchanged"; + } } - public ProfileProperties GetProfile() + public ProfileProperties GetProfile() { var profileProperties = new ProfileProperties { TraceLogger = chkTrace.Checked, ComPort = comboBoxComPort.SelectedItem.ToString(), - GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim()) + GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim()), + Precision = cboPrecision.SelectedItem.ToString() }; return profileProperties; diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index a714e67..0f875dd 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -40,6 +40,8 @@ namespace ASCOM.Meade.net this.txtGuideRate = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.lblPercentOfSiderealRate = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.cboPrecision = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); this.SuspendLayout(); // @@ -112,10 +114,28 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.lblPercentOfSiderealRate, "lblPercentOfSiderealRate"); this.lblPercentOfSiderealRate.Name = "lblPercentOfSiderealRate"; // + // label5 + // + resources.ApplyResources(this.label5, "label5"); + this.label5.Name = "label5"; + // + // cboPrecision + // + this.cboPrecision.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cboPrecision.FormattingEnabled = true; + this.cboPrecision.Items.AddRange(new object[] { + resources.GetString("cboPrecision.Items"), + resources.GetString("cboPrecision.Items1"), + resources.GetString("cboPrecision.Items2")}); + resources.ApplyResources(this.cboPrecision, "cboPrecision"); + this.cboPrecision.Name = "cboPrecision"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.cboPrecision); + this.Controls.Add(this.label5); this.Controls.Add(this.lblPercentOfSiderealRate); this.Controls.Add(this.label4); this.Controls.Add(this.txtGuideRate); @@ -152,5 +172,7 @@ namespace ASCOM.Meade.net private System.Windows.Forms.TextBox txtGuideRate; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label lblPercentOfSiderealRate; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.ComboBox cboPrecision; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 99399de..fd6059a 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 10 + 12 Bottom, Right @@ -172,7 +172,7 @@ $this - 9 + 11 12, 9 @@ -196,7 +196,7 @@ $this - 8 + 10 Top, Right @@ -223,7 +223,7 @@ $this - 7 + 9 True @@ -250,13 +250,13 @@ $this - 6 + 8 True - 77, 118 + 77, 136 69, 17 @@ -277,7 +277,7 @@ $this - 5 + 7 77, 87 @@ -298,13 +298,13 @@ $this - 4 + 6 True - 13, 225 + 10, 162 61, 13 @@ -325,10 +325,10 @@ $this - 3 + 5 - 80, 222 + 77, 159 46, 20 @@ -349,13 +349,13 @@ $this - 2 + 4 True - 132, 225 + 129, 162 122, 13 @@ -376,13 +376,13 @@ $this - 1 + 3 True - 132, 238 + 129, 175 105, 13 @@ -403,6 +403,63 @@ $this + 2 + + + True + + + 13, 194 + + + 50, 13 + + + 12 + + + Precision + + + label5 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + Unchanged + + + Low + + + High + + + 77, 191 + + + 90, 21 + + + 13 + + + cboPrecision + + + System.Windows.Forms.ComboBox, 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 1e79de9..8d27adb 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -116,6 +116,14 @@ namespace ASCOM.Meade.net } } + public static string ReadCharacters(int throwAwayCharacters) + { + lock (LockObject) + { + return SharedSerial.ReceiveCounted(throwAwayCharacters); + } + } + /// /// Example of handling connecting to and disconnection from the /// shared serial port. @@ -159,6 +167,7 @@ namespace ASCOM.Meade.net private const string ComPortProfileName = "COM Port"; private const string TraceStateProfileName = "Trace Level"; private const string GuideRateProfileName = "Guide Rate Arc Seconds Per Second"; + private const string PrecisionProfileName = "Precision"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -170,6 +179,7 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString()); driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort); driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString()); + driverProfile.WriteValue(DriverId, PrecisionProfileName, profileProperties.Precision); } } } @@ -177,6 +187,7 @@ namespace ASCOM.Meade.net private const string ComPortDefault = "COM1"; private const string TraceStateDefault = "false"; private const string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate + private const string PrecisionDefault = "Unchanged"; public static ProfileProperties ReadProfile() { @@ -189,6 +200,7 @@ namespace ASCOM.Meade.net profileProperties.ComPort = driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault); profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(DriverId, TraceStateProfileName, string.Empty, TraceStateDefault)); profileProperties.GuideRateArcSecondsPerSecond = double.Parse(driverProfile.GetValue(DriverId, GuideRateProfileName, string.Empty, GuideRateProfileNameDefault)); + profileProperties.Precision = driverProfile.GetValue(DriverId, PrecisionProfileName, string.Empty, PrecisionDefault); } return profileProperties; diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index c2fda79..3417ce6 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -24,6 +24,7 @@ namespace ASCOM.Meade.net.Wrapper void SetupDialog(); void WriteProfile(ProfileProperties profileProperties); + string ReadCharacters(int throwAwayCharacters); } public class SharedResourcesWrapper : ISharedResourcesWrapper @@ -72,6 +73,11 @@ namespace ASCOM.Meade.net.Wrapper return SharedResources.ReadTerminated(); } + public string ReadCharacters(int throwAwayCharacters) + { + return SharedResources.ReadCharacters(throwAwayCharacters); + } + public ProfileProperties ReadProfile() { return SharedResources.ReadProfile();