diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 472d80c..7a803b8 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -127,6 +127,8 @@ namespace Meade.net.UnitTests profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Guide Rate Arc Seconds Per Second", profileProperties.GuideRateArcSecondsPerSecond.ToString(CultureInfo.CurrentCulture)), Times.Once); profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Precision", profileProperties.Precision), Times.Once); profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Guiding Style", profileProperties.GuidingStyle), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Backlash Compensation", profileProperties.BacklashCompensation.ToString(CultureInfo.CurrentCulture)), Times.Once); + profileWrapperMock.Verify(x => x.WriteValue(DriverId, "Reverse Focuser Direction", profileProperties.ReverseFocusDirection.ToString()), Times.Once); } [Test] @@ -140,12 +142,14 @@ namespace Meade.net.UnitTests string PrecisionDefault = "Unchanged"; string GuidingStyleDefault = "Auto"; string BacklashCompensationDefault = "3000"; + string ReverseFocuserDiectionDefault = "true"; Mock profileWrapperMock = new Mock(); profileWrapperMock.SetupAllProperties(); profileWrapperMock.Setup(x => x.GetValue(DriverId, "Trace Level", string.Empty, TraceStateDefault)) - .Returns(TraceStateDefault); + .Returns(() => + TraceStateDefault); profileWrapperMock.Setup(x => x.GetValue(DriverId, "COM Port", string.Empty, ComPortDefault)) .Returns(ComPortDefault); profileWrapperMock @@ -155,8 +159,12 @@ namespace Meade.net.UnitTests .Returns(PrecisionDefault); profileWrapperMock.Setup(x => x.GetValue(DriverId, "Guiding Style", string.Empty, GuidingStyleDefault)) .Returns(GuidingStyleDefault); - profileWrapperMock.Setup(x => x.GetValue(DriverId, "Backlash Compensation", string.Empty, BacklashCompensationDefault)) + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Backlash Compensation", string.Empty, BacklashCompensationDefault)) .Returns(BacklashCompensationDefault); + profileWrapperMock.Setup(x => + x.GetValue(DriverId, "Reverse Focuser Direction", string.Empty, ReverseFocuserDiectionDefault)) + .Returns(() => ReverseFocuserDiectionDefault); IProfileWrapper profeWrapper = profileWrapperMock.Object; @@ -175,6 +183,7 @@ namespace Meade.net.UnitTests Assert.That(profileProperties.Precision, Is.EqualTo(PrecisionDefault)); Assert.That(profileProperties.GuidingStyle, Is.EqualTo(GuidingStyleDefault)); Assert.That(profileProperties.BacklashCompensation, Is.EqualTo(int.Parse(BacklashCompensationDefault))); + Assert.That(profileProperties.ReverseFocusDirection, Is.EqualTo(bool.Parse(ReverseFocuserDiectionDefault))); } [TestCase("TCP")] diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index 9cbc786..224e4c6 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -47,6 +47,9 @@ namespace ASCOM.Meade.net private static string _comPort; // Variables to hold the currrent device configuration private static int _backlashCompensation; + + private static bool _reverseFocusDirection; + /// /// Private variable to hold an ASCOM Utilities object /// @@ -339,7 +342,6 @@ namespace ASCOM.Meade.net _tl.LogMessage("Move", position.ToString()); CheckConnected("Move"); - //todo implement direction reverse //todo implement dynamic braking if (position < -MaxIncrement || position > MaxIncrement) @@ -350,10 +352,14 @@ namespace ASCOM.Meade.net if (position == 0) return; + var direction = position > 0; + if (_reverseFocusDirection) + direction = !direction; + _sharedResourcesWrapper.Lock(() => { - MoveFocuser(position > 0, Math.Abs(position)); - ApplyBacklashCompensation(position > 0); + MoveFocuser(direction, Math.Abs(position)); + ApplyBacklashCompensation(direction); //This gives the focuser time to physically stop. _utilities.WaitForMilliseconds(1000); }); @@ -559,6 +565,7 @@ namespace ASCOM.Meade.net _tl.Enabled = profileProperties.TraceLogger; _comPort = profileProperties.ComPort; _backlashCompensation = profileProperties.BacklashCompensation; + _reverseFocusDirection = profileProperties.ReverseFocusDirection; LogMessage("ReadProfile", $"Trace logger enabled: {_tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {_comPort}"); diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index a469d6f..91ec357 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -9,5 +9,6 @@ namespace ASCOM.Meade.net public string Precision { get; set; } public string GuidingStyle { get; set; } public int BacklashCompensation { get; set; } + public bool ReverseFocusDirection { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 2366268..3e46acd 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -82,6 +82,8 @@ namespace ASCOM.Meade.net } txtBacklashSteps.Text = profileProperties.BacklashCompensation.ToString(CultureInfo.CurrentCulture); + + cbxReverseDirection.Checked = profileProperties.ReverseFocusDirection; } public ProfileProperties GetProfile() @@ -93,7 +95,8 @@ namespace ASCOM.Meade.net GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim()), Precision = cboPrecision.SelectedItem.ToString(), GuidingStyle = cboGuidingStyle.SelectedItem.ToString(), - BacklashCompensation = int.Parse(txtBacklashSteps.Text) + BacklashCompensation = int.Parse(txtBacklashSteps.Text), + ReverseFocusDirection = cbxReverseDirection.Checked }; return profileProperties; diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 38678e2..fec612a 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -53,6 +53,7 @@ namespace ASCOM.Meade.net this.label9 = new System.Windows.Forms.Label(); this.label10 = new System.Windows.Forms.Label(); this.label11 = new System.Windows.Forms.Label(); + this.cbxReverseDirection = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); this.SuspendLayout(); // @@ -187,10 +188,17 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label11, "label11"); this.label11.Name = "label11"; // + // cbxReverseDirection + // + resources.ApplyResources(this.cbxReverseDirection, "cbxReverseDirection"); + this.cbxReverseDirection.Name = "cbxReverseDirection"; + this.cbxReverseDirection.UseVisualStyleBackColor = true; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.cbxReverseDirection); this.Controls.Add(this.label11); this.Controls.Add(this.label10); this.Controls.Add(this.txtBacklashSteps); @@ -248,5 +256,6 @@ namespace ASCOM.Meade.net private Label label9; private Label label10; private Label label11; + private CheckBox cbxReverseDirection; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index 40dc2b0..6618668 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 20 + 21 Bottom, Right @@ -172,7 +172,7 @@ $this - 19 + 20 12, 9 @@ -196,7 +196,7 @@ $this - 18 + 19 Top, Right @@ -223,7 +223,7 @@ $this - 17 + 18 True @@ -250,7 +250,7 @@ $this - 16 + 17 True @@ -277,7 +277,7 @@ $this - 15 + 16 97, 87 @@ -298,7 +298,7 @@ $this - 14 + 15 True @@ -325,7 +325,7 @@ $this - 13 + 14 97, 199 @@ -349,7 +349,7 @@ $this - 12 + 13 True @@ -376,7 +376,7 @@ $this - 11 + 12 True @@ -403,7 +403,7 @@ $this - 10 + 11 True @@ -430,7 +430,7 @@ $this - 9 + 10 Unchanged @@ -460,7 +460,7 @@ $this - 8 + 9 True @@ -490,7 +490,7 @@ $this - 7 + 8 Auto @@ -520,7 +520,7 @@ $this - 6 + 7 True @@ -550,7 +550,7 @@ $this - 5 + 6 True @@ -583,7 +583,7 @@ $this - 4 + 5 97, 335 @@ -607,7 +607,7 @@ $this - 2 + 3 True @@ -637,7 +637,7 @@ $this - 3 + 4 True @@ -667,7 +667,7 @@ $this - 1 + 2 True @@ -700,6 +700,33 @@ $this + 1 + + + True + + + 97, 361 + + + 109, 17 + + + 22 + + + Reverse direction + + + cbxReverseDirection + + + System.Windows.Forms.CheckBox, 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 731d491..e7e89a8 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -142,6 +142,7 @@ namespace ASCOM.Meade.net private const string PrecisionProfileName = "Precision"; private const string GuidingStyleProfileName = "Guiding Style"; private const string BacklashCompensationName = "Backlash Compensation"; + private const string ReverseFocusDirectionName = "Reverse Focuser Direction"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -156,6 +157,7 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, PrecisionProfileName, profileProperties.Precision); driverProfile.WriteValue(DriverId, GuidingStyleProfileName, profileProperties.GuidingStyle); driverProfile.WriteValue(DriverId, BacklashCompensationName, profileProperties.BacklashCompensation.ToString()); + driverProfile.WriteValue(DriverId, ReverseFocusDirectionName, profileProperties.ReverseFocusDirection.ToString()); } } } @@ -166,8 +168,7 @@ namespace ASCOM.Meade.net private const string PrecisionDefault = "Unchanged"; private const string GuidingStyleDefault = "Auto"; private const string BacklashCompensationDefault = "3000"; - - + private const string ReverseFocuserDiectionDefault = "true"; public static ProfileProperties ReadProfile() { @@ -183,6 +184,7 @@ namespace ASCOM.Meade.net profileProperties.Precision = driverProfile.GetValue(DriverId, PrecisionProfileName, string.Empty, PrecisionDefault); profileProperties.GuidingStyle = driverProfile.GetValue(DriverId, GuidingStyleProfileName, string.Empty, GuidingStyleDefault); profileProperties.BacklashCompensation = Convert.ToInt32(driverProfile.GetValue(DriverId, BacklashCompensationName, string.Empty, BacklashCompensationDefault)); + profileProperties.ReverseFocusDirection = Convert.ToBoolean(driverProfile.GetValue(DriverId, ReverseFocusDirectionName, string.Empty, ReverseFocuserDiectionDefault)); } return profileProperties;