fix: move isInUpPosition to momvement complete method, remove conditionlal logic on raise/lower commands

This commit is contained in:
Erik Meyer
2025-12-27 17:09:56 -06:00
parent ae0b2fe086
commit a7ff2e8903
2 changed files with 35 additions and 33 deletions

View File

@@ -37,6 +37,7 @@ namespace PepperDash.Essentials.Devices.Common.Shades
private bool _isMoving;
private RequestedState _requestedState;
private RequestedState _currentMovement;
private CTimer _movementTimer;
/// <summary>
@@ -188,7 +189,7 @@ namespace PepperDash.Essentials.Devices.Common.Shades
}
Debug.LogMessage(LogEventLevel.Debug, this, $"Raising {Type}");
switch (Mode)
{
case eScreenLiftControlMode.momentary:
@@ -196,21 +197,26 @@ namespace PepperDash.Essentials.Devices.Common.Shades
PulseOutput(RaiseRelay, RaiseRelayConfig.PulseTimeInMs);
// Set moving flag and start timer if movement time is configured
if (RaiseRelayConfig.RaiseTimeInMs > 0)
if (RaiseRelayConfig.MoveTimeInMs > 0)
{
_isMoving = true;
_currentMovement = RequestedState.Raise;
DisposeMovementTimer();
_movementTimer = new CTimer(OnMovementComplete, RaiseRelayConfig.RaiseTimeInMs);
_movementTimer = new CTimer(OnMovementComplete, RaiseRelayConfig.MoveTimeInMs);
}
else
{
InUpPosition = true;
}
break;
}
case eScreenLiftControlMode.latched:
{
LatchedRelay.Off();
InUpPosition = true;
break;
}
}
InUpPosition = true;
}
/// <summary>
@@ -221,7 +227,7 @@ namespace PepperDash.Essentials.Devices.Common.Shades
if (LowerRelay == null && LatchedRelay == null) return;
Debug.LogMessage(LogEventLevel.Debug, this, $"Lower called for {Type}");
// If device is moving, bank the command
if (_isMoving)
{
@@ -239,21 +245,26 @@ namespace PepperDash.Essentials.Devices.Common.Shades
PulseOutput(LowerRelay, LowerRelayConfig.PulseTimeInMs);
// Set moving flag and start timer if movement time is configured
if (LowerRelayConfig.LowerTimeInMs > 0)
if (LowerRelayConfig.MoveTimeInMs > 0)
{
_isMoving = true;
_currentMovement = RequestedState.Lower;
DisposeMovementTimer();
_movementTimer = new CTimer(OnMovementComplete, LowerRelayConfig.LowerTimeInMs);
_movementTimer = new CTimer(OnMovementComplete, LowerRelayConfig.MoveTimeInMs);
}
else
{
InUpPosition = false;
}
break;
}
case eScreenLiftControlMode.latched:
{
LatchedRelay.On();
InUpPosition = false;
break;
}
}
InUpPosition = false;
}
/// <summary>
@@ -276,7 +287,18 @@ namespace PepperDash.Essentials.Devices.Common.Shades
{
Debug.LogMessage(LogEventLevel.Debug, this, $"Movement complete");
// Update position based on completed movement
if (_currentMovement == RequestedState.Raise)
{
InUpPosition = true;
}
else if (_currentMovement == RequestedState.Lower)
{
InUpPosition = false;
}
_isMoving = false;
_currentMovement = RequestedState.None;
// Execute banked command if one exists
if (_requestedState != RequestedState.None)
@@ -290,25 +312,11 @@ namespace PepperDash.Essentials.Devices.Common.Shades
switch (commandToExecute)
{
case RequestedState.Raise:
if (InUpPosition)
{
Debug.LogMessage(LogEventLevel.Debug, this, $"Already in up position, ignoring banked Raise command");
}
else
{
Raise();
}
Raise();
break;
case RequestedState.Lower:
if (!InUpPosition)
{
Debug.LogMessage(LogEventLevel.Debug, this, $"Already in down position, ignoring banked Lower command");
}
else
{
Lower();
}
Lower();
break;
}
}

View File

@@ -20,15 +20,9 @@ namespace PepperDash.Essentials.Devices.Common.Shades
public int PulseTimeInMs { get; set; }
/// <summary>
/// Gets or sets the RaiseTimeInMs - time in milliseconds for the raise movement to complete
/// Gets or sets the MoveTimeInMs - time in milliseconds for the movement to complete
/// </summary>
[JsonProperty("raiseTimeInMs")]
public int RaiseTimeInMs { get; set; }
/// <summary>
/// Gets or sets the LowerTimeInMs - time in milliseconds for the lower movement to complete
/// </summary>
[JsonProperty("lowerTimeInMs")]
public int LowerTimeInMs { get; set; }
[JsonProperty("moveTimeInMs")]
public int MoveTimeInMs { get; set; }
}
}