diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 1ebef48..b2565f0 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1154,33 +1154,33 @@ namespace Meade.net.Telescope.UnitTests switch (axis) { case TelescopeAxes.axisPrimary: - if (rate == 0) + switch (rate.Compare(0)) { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qe#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qw#"), Times.Once); - } - else if (rate > 0) - { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Me#"), Times.Once); - } - else - { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mw#"), Times.Once); + case ComparisonResult.Equals: + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qe#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qw#"), Times.Once); + break; + case ComparisonResult.Greater: + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Me#"), Times.Once); + break; + case ComparisonResult.Lower: + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mw#"), Times.Once); + break; } break; case TelescopeAxes.axisSecondary: - if (rate == 0) + switch (rate.Compare(0)) { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qn#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qs#"), Times.Once); - } - else if (rate > 0) - { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mn#"), Times.Once); - } - else - { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Ms#"), Times.Once); + case ComparisonResult.Equals: + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qn#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qs#"), Times.Once); + break; + case ComparisonResult.Greater: + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mn#"), Times.Once); + break; + case ComparisonResult.Lower: + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Ms#"), Times.Once); + break; } break; default: diff --git a/Meade.net.Telescope/ComparisonResult.cs b/Meade.net.Telescope/ComparisonResult.cs new file mode 100644 index 0000000..7997a47 --- /dev/null +++ b/Meade.net.Telescope/ComparisonResult.cs @@ -0,0 +1,9 @@ +namespace ASCOM.Meade.net +{ + public enum ComparisonResult + { + Lower, + Equals, + Greater + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/DoubleExtensions.cs b/Meade.net.Telescope/DoubleExtensions.cs index 958400c..29ba8fa 100644 --- a/Meade.net.Telescope/DoubleExtensions.cs +++ b/Meade.net.Telescope/DoubleExtensions.cs @@ -10,5 +10,18 @@ namespace ASCOM.Meade.net return false; return true; } + + public static ComparisonResult Compare(this double value, double comparison) + { + var result = value.CompareTo(comparison); + + if (result < 0) + return ComparisonResult.Lower; + + if (result == 0) + return ComparisonResult.Equals; + + return ComparisonResult.Greater; + } } } \ No newline at end of file diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index 4d1c796..6b35df9 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -118,6 +118,7 @@ + diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index e86b9bf..5325dc2 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1290,56 +1290,57 @@ namespace ASCOM.Meade.net switch (axis) { case TelescopeAxes.axisPrimary: - if (rate == 0) + switch (rate.Compare(0)) { - _movingPrimary = false; - _sharedResourcesWrapper.SendBlind("#:Qe#"); - //:Qe# Halt eastward Slews - //Returns: Nothing - _sharedResourcesWrapper.SendBlind("#:Qw#"); - //:Qw# Halt westward Slews - //Returns: Nothing - } - else if (rate > 0) - { - _sharedResourcesWrapper.SendBlind("#:Me#"); - //:Me# Move Telescope East at current slew rate - //Returns: Nothing - _movingPrimary = true; - } - else - { - _sharedResourcesWrapper.SendBlind("#:Mw#"); - //:Mw# Move Telescope West at current slew rate - //Returns: Nothing - _movingPrimary = true; - } + case ComparisonResult.Equals: + _movingPrimary = false; + _sharedResourcesWrapper.SendBlind("#:Qe#"); + //:Qe# Halt eastward Slews + //Returns: Nothing + _sharedResourcesWrapper.SendBlind("#:Qw#"); + //:Qw# Halt westward Slews + //Returns: Nothing + break; + case ComparisonResult.Greater: + _sharedResourcesWrapper.SendBlind("#:Me#"); + //:Me# Move Telescope East at current slew rate + //Returns: Nothing + _movingPrimary = true; + break; + case ComparisonResult.Lower: + _sharedResourcesWrapper.SendBlind("#:Mw#"); + //:Mw# Move Telescope West at current slew rate + //Returns: Nothing + _movingPrimary = true; + break; + } break; case TelescopeAxes.axisSecondary: - if (rate == 0) + switch (rate.Compare(0)) { - _movingSecondary = false; - _sharedResourcesWrapper.SendBlind("#:Qn#"); - //:Qn# Halt northward Slews - //Returns: Nothing - _sharedResourcesWrapper.SendBlind("#:Qs#"); - //:Qs# Halt southward Slews - //Returns: Nothing - } - else if (rate > 0) - { - _sharedResourcesWrapper.SendBlind("#:Mn#"); - //:Mn# Move Telescope North at current slew rate - //Returns: Nothing - _movingSecondary = true; - } - else - { - _sharedResourcesWrapper.SendBlind("#:Ms#"); - //:Ms# Move Telescope South at current slew rate - //Returns: Nothing - _movingSecondary = true; + case ComparisonResult.Equals: + _movingSecondary = false; + _sharedResourcesWrapper.SendBlind("#:Qn#"); + //:Qn# Halt northward Slews + //Returns: Nothing + _sharedResourcesWrapper.SendBlind("#:Qs#"); + //:Qs# Halt southward Slews + //Returns: Nothing + break; + case ComparisonResult.Greater: + _sharedResourcesWrapper.SendBlind("#:Mn#"); + //:Mn# Move Telescope North at current slew rate + //Returns: Nothing + _movingSecondary = true; + break; + case ComparisonResult.Lower: + _sharedResourcesWrapper.SendBlind("#:Ms#"); + //:Ms# Move Telescope South at current slew rate + //Returns: Nothing + _movingSecondary = true; + break; + } break; @@ -1857,7 +1858,7 @@ namespace ASCOM.Meade.net { CheckConnected("SlewToTargetAsync"); - if (TargetDeclination == InvalidParameter || TargetRightAscension == InvalidParameter) + if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter)) throw new InvalidOperationException("No target selected to slew to."); DoSlewAsync(true); @@ -1938,7 +1939,7 @@ namespace ASCOM.Meade.net { get { - if (_targetDeclination == InvalidParameter) + if (_targetDeclination.Equals(InvalidParameter)) throw new InvalidOperationException("Target not set"); //var result = SerialPort.CommandTerminated("#:Gd#", "#"); @@ -1993,7 +1994,7 @@ namespace ASCOM.Meade.net { get { - if (_targetRightAscension == InvalidParameter) + if (_targetRightAscension.Equals(InvalidParameter)) throw new InvalidOperationException("Target not set"); //var result = SerialPort.CommandTerminated("#:Gr#", "#"); diff --git a/Meade.net.v3.ncrunchsolution.user b/Meade.net.v3.ncrunchsolution.user index 24ce899..cd10274 100644 --- a/Meade.net.v3.ncrunchsolution.user +++ b/Meade.net.v3.ncrunchsolution.user @@ -11,6 +11,6 @@ true false - 451 + 544 \ No newline at end of file