From a7ff2e8903487c3aea66f136f2184693b11219b3 Mon Sep 17 00:00:00 2001 From: Erik Meyer Date: Sat, 27 Dec 2025 17:09:56 -0600 Subject: [PATCH] fix: move isInUpPosition to momvement complete method, remove conditionlal logic on raise/lower commands --- .../Displays/ScreenLiftController.cs | 56 +++++++++++-------- .../Displays/ScreenLiftRelaysConfig.cs | 12 +--- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/PepperDash.Essentials.Devices.Common/Displays/ScreenLiftController.cs b/src/PepperDash.Essentials.Devices.Common/Displays/ScreenLiftController.cs index 459819af..aad8f54a 100644 --- a/src/PepperDash.Essentials.Devices.Common/Displays/ScreenLiftController.cs +++ b/src/PepperDash.Essentials.Devices.Common/Displays/ScreenLiftController.cs @@ -37,6 +37,7 @@ namespace PepperDash.Essentials.Devices.Common.Shades private bool _isMoving; private RequestedState _requestedState; + private RequestedState _currentMovement; private CTimer _movementTimer; /// @@ -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; } /// @@ -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; } /// @@ -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; } } diff --git a/src/PepperDash.Essentials.Devices.Common/Displays/ScreenLiftRelaysConfig.cs b/src/PepperDash.Essentials.Devices.Common/Displays/ScreenLiftRelaysConfig.cs index f39134a4..8890ac95 100644 --- a/src/PepperDash.Essentials.Devices.Common/Displays/ScreenLiftRelaysConfig.cs +++ b/src/PepperDash.Essentials.Devices.Common/Displays/ScreenLiftRelaysConfig.cs @@ -20,15 +20,9 @@ namespace PepperDash.Essentials.Devices.Common.Shades public int PulseTimeInMs { get; set; } /// - /// 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 /// - [JsonProperty("raiseTimeInMs")] - public int RaiseTimeInMs { get; set; } - - /// - /// Gets or sets the LowerTimeInMs - time in milliseconds for the lower movement to complete - /// - [JsonProperty("lowerTimeInMs")] - public int LowerTimeInMs { get; set; } + [JsonProperty("moveTimeInMs")] + public int MoveTimeInMs { get; set; } } } \ No newline at end of file