Skip to content

Commit

Permalink
fix: modify power on/off routines
Browse files Browse the repository at this point in the history
To keep things from happening multiple times, the backing power on/off variable is set prior to the timers ending and updating the feedbacks.
  • Loading branch information
Andrew Welker committed Jul 22, 2024
1 parent 700e7c2 commit ea94cfd
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions src/SamsungMdc.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// For Basic SIMPL# Classes
// For Basic SIMPL# Classes
// For Basic SIMPL#Pro classes

using Crestron.SimplSharp;
Expand Down Expand Up @@ -818,19 +818,31 @@ public void StatusGet()
public override void PowerOn()
{
_isPoweringOnIgnorePowerFb = true;

if (_powerIsOn || _isWarmingUp || _isCoolingDown)
{
return;
}

_powerIsOn = true;

SendBytes(new byte[] { SamsungMdcCommands.Header, SamsungMdcCommands.PowerControl, 0x00, 0x01, SamsungMdcCommands.PowerOn, 0x00 });

if (PowerIsOnFeedback.BoolValue || _isWarmingUp || _isCoolingDown)

if (WarmupTimer != null || WarmupTime == 0)
{
PowerIsOnFeedback.FireUpdate();
return;
}

_isWarmingUp = true;
IsWarmingUpFeedback.FireUpdate();

// Fake power-up cycle
WarmupTimer = new CTimer(o =>
{
_isWarmingUp = false;
_powerIsOn = true;
IsWarmingUpFeedback.FireUpdate();
PowerIsOnFeedback.FireUpdate();
}, WarmupTime);
Expand All @@ -845,24 +857,37 @@ public override void PowerOff()
_isPoweringOnIgnorePowerFb = false;
// If a display has unreliable-power off feedback, just override this and
// remove this check.
if (!_isWarmingUp && !_isCoolingDown && _powerIsOn) // PowerIsOnFeedback.BoolValue &&
if (!_powerIsOn || _isWarmingUp || _isCoolingDown)
{
SendBytes(new byte[] { SamsungMdcCommands.Header, SamsungMdcCommands.PowerControl, 0x00, 0x01, SamsungMdcCommands.PowerOff, 0x00 });
_isCoolingDown = true;
CurrentInputNumber = 0;
return;
}

InputNumberFeedback.FireUpdate();
_powerIsOn = false;

IsCoolingDownFeedback.FireUpdate();
// Fake cool-down cycle
CooldownTimer = new CTimer(o =>
{
_isCoolingDown = false;
_powerIsOn = false;
PowerIsOnFeedback.FireUpdate();
IsCoolingDownFeedback.FireUpdate();
}, CooldownTime);
SendBytes(new byte[] { SamsungMdcCommands.Header, SamsungMdcCommands.PowerControl, 0x00, 0x01, SamsungMdcCommands.PowerOff, 0x00 });

CurrentInputNumber = 0;

InputNumberFeedback.FireUpdate();

if (CooldownTimer != null || CooldownTime == 0)
{
PowerIsOnFeedback.FireUpdate();
return;
}

_isCoolingDown = true;

IsCoolingDownFeedback.FireUpdate();

// Fake cool-down cycle
CooldownTimer = new CTimer(o =>
{
_isCoolingDown = false;
PowerIsOnFeedback.FireUpdate();
IsCoolingDownFeedback.FireUpdate();
}, CooldownTime);

}

/// <summary>
Expand Down

0 comments on commit ea94cfd

Please sign in to comment.