Skip to content

Commit

Permalink
Maximale position: fixup, set buttopn code missed.
Browse files Browse the repository at this point in the history
  • Loading branch information
stroblhofwarte committed May 26, 2022
1 parent 220ca34 commit f0e8bc9
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 16 deletions.
28 changes: 28 additions & 0 deletions ASCOM.Stroblhofwarte.Rotator/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public class Rotator : IRotatorV3
internal static string _speedName = "Speed";
private float _speed = 1.0f;

internal static string _maxMovementName = "MaxMovement";
private float _maxMovement = 350.0f;

private object _lock = new object();
/// <summary>
/// Private variable to hold the connected state
Expand Down Expand Up @@ -348,6 +351,7 @@ public bool Connected
SetPark(_parkPosition);
InitSpeed = _initSpeed;
Speed = _speed;
MaxMovement = _maxMovement;
string inf = GetInfoString();
if(inf == "Not initialized yet.")
{
Expand Down Expand Up @@ -489,6 +493,22 @@ public float Speed
return _speed;
}
}

public float MaxMovement
{
set
{
if (!connectedState) return;
_maxMovement = value;
if (value > 359) _maxMovement = 359;
if (value < 0) _maxMovement = 0;
WriteProfile();
}
get
{
return _maxMovement;
}
}
public void Halt()
{
if (!connectedState) return;
Expand All @@ -513,6 +533,8 @@ public void Move(float pos)
{
if (!connectedState) return;
_targetPosition = Position + pos;
// Check if the maximal rotation value is exceeded:
if (FromSyncPositionToMechanicalPosition(_targetPosition) > _maxMovement) return;
lock (_lock)
{
tl.LogMessage("Move", pos.ToString()); // Move by this amount
Expand All @@ -534,6 +556,8 @@ public void MoveAbsolute(float pos)
{
if (!connectedState) return;
_targetPosition = pos;
// Check if the maximal rotation value is exceeded:
if (FromSyncPositionToMechanicalPosition(_targetPosition) > _maxMovement) return;
float truePos = FromSyncPositionToMechanicalPosition(pos);
lock (_lock)
{
Expand Down Expand Up @@ -636,6 +660,8 @@ public float MechanicalPosition
public void MoveMechanical(float pos)
{
if (!connectedState) return;
// Check if the maximal rotation value is exceeded:
if (pos > _maxMovement) return;
lock (_lock)
{
tl.LogMessage("MoveAbsolute", pos.ToString()); // Move to this position
Expand Down Expand Up @@ -786,6 +812,7 @@ internal void ReadProfile()
_parkPosition = (float)Convert.ToDouble(driverProfile.GetValue(driverID, _parkPositionName, string.Empty, "0.0"));
_initSpeed = (float)Convert.ToDouble(driverProfile.GetValue(driverID, _initSpeedName, string.Empty, "1.0"));
_speed = (float)Convert.ToDouble(driverProfile.GetValue(driverID, _speedName, string.Empty, "1.0"));
_maxMovement = (float)Convert.ToDouble(driverProfile.GetValue(driverID, _maxMovementName, string.Empty, "350.0"));

}
}
Expand All @@ -805,6 +832,7 @@ internal void WriteProfile()
driverProfile.WriteValue(driverID, _parkPositionName, _parkPosition.ToString(CultureInfo.InvariantCulture));
driverProfile.WriteValue(driverID, _initSpeedName, _initSpeed.ToString(CultureInfo.InvariantCulture));
driverProfile.WriteValue(driverID, _speedName, _speed.ToString(CultureInfo.InvariantCulture));
driverProfile.WriteValue(driverID, _maxMovementName, _maxMovement.ToString(CultureInfo.InvariantCulture));
}
}

Expand Down
17 changes: 15 additions & 2 deletions ASCOM.Stroblhofwarte.Rotator/SetupDialogForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void buttonSetSpeed_Click(object sender, EventArgs e)
}
catch (Exception ex)
{
textBoxSync.Text = "0.0";
textBoxSpeed.Text = "0.0";
}
}

Expand All @@ -168,7 +168,20 @@ private void buttonSetInitSpeed_Click(object sender, EventArgs e)
}
catch (Exception ex)
{
textBoxSync.Text = "0.0";
textBoxInitSpeed.Text = "0.0";
}
}

private void buttonSetMaxMovement_Click(object sender, EventArgs e)
{
try
{
float maxMovement = (float)Convert.ToDouble(txtMaxMove.Text, CultureInfo.InvariantCulture);
_driver.MaxMovement = maxMovement;
}
catch (Exception ex)
{
txtMaxMove.Text = "0.0";
}
}
}
Expand Down
71 changes: 57 additions & 14 deletions ASCOM.Stroblhofwarte.Rotator/SetupDialogForm.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified StroblRotator Setup.exe
Binary file not shown.

0 comments on commit f0e8bc9

Please sign in to comment.