Updated to allow for middle shade button to have label driven from config.

This commit is contained in:
Neil Dorin
2018-06-05 16:47:07 -06:00
parent 3cf188f820
commit fbe5df84be
7 changed files with 120 additions and 111 deletions

View File

@@ -23,11 +23,11 @@ namespace PepperDash.Essentials.Core.Shades
} }
/// <summary> /// <summary>
/// Requirements for a device that implements basic Open/Close/Stop shade control /// Requirements for a device that implements basic Open/Close/Stop shade control (Uses 3 relays)
/// </summary> /// </summary>
public interface IShadesOpenCloseStop : IShadesOpenClose public interface IShadesOpenCloseStop : IShadesOpenClose
{ {
void Stop(); void StopOrPreset();
} }
/// <summary> /// <summary>

View File

@@ -23,6 +23,7 @@ namespace PepperDash.Essentials.Core.Shades
#region iShadesOpenClose Members #region iShadesOpenClose Members
public abstract void Open(); public abstract void Open();
public abstract void StopOrPreset();
public abstract void Close(); public abstract void Close();
#endregion #endregion

View File

@@ -19,11 +19,13 @@ namespace PepperDash.Essentials.Devices.Common.Environment.Somfy
RelayControlledShadeConfigProperties Config; RelayControlledShadeConfigProperties Config;
ISwitchedOutput OpenRelay; ISwitchedOutput OpenRelay;
ISwitchedOutput StopRelay; ISwitchedOutput StopOrPresetRelay;
ISwitchedOutput CloseRelay; ISwitchedOutput CloseRelay;
int RelayPulseTime; int RelayPulseTime;
public string StopOrPresetButtonLabel { get; set; }
public RelayControlledShade(string key, string name, RelayControlledShadeConfigProperties config) public RelayControlledShade(string key, string name, RelayControlledShadeConfigProperties config)
: base(key, name) : base(key, name)
{ {
@@ -31,13 +33,15 @@ namespace PepperDash.Essentials.Devices.Common.Environment.Somfy
RelayPulseTime = Config.RelayPulseTime; RelayPulseTime = Config.RelayPulseTime;
StopOrPresetButtonLabel = Config.StopOrPresetLabel;
} }
public override bool CustomActivate() public override bool CustomActivate()
{ {
//Create ISwitchedOutput objects based on props //Create ISwitchedOutput objects based on props
OpenRelay = GetSwitchedOutputFromDevice(Config.Relays.Open); OpenRelay = GetSwitchedOutputFromDevice(Config.Relays.Open);
StopRelay = GetSwitchedOutputFromDevice(Config.Relays.Stop); StopOrPresetRelay = GetSwitchedOutputFromDevice(Config.Relays.StopOrPreset);
CloseRelay = GetSwitchedOutputFromDevice(Config.Relays.Close); CloseRelay = GetSwitchedOutputFromDevice(Config.Relays.Close);
@@ -47,29 +51,28 @@ namespace PepperDash.Essentials.Devices.Common.Environment.Somfy
public override void Open() public override void Open()
{ {
Debug.Console(1, this, "Opening Shade: '{0}'", this.Name); Debug.Console(1, this, "Opening Shade: '{0}'", this.Name);
StopRelay.Off();
CloseRelay.Off();
OpenRelay.On(); PulseOutput(OpenRelay, RelayPulseTime);
} }
public void Stop() public override void StopOrPreset()
{ {
Debug.Console(1, this, "Stopping Shade: '{0}'", this.Name); Debug.Console(1, this, "Stopping or recalling preset on Shade: '{0}'", this.Name);
OpenRelay.Off();
CloseRelay.Off();
StopRelay.On(); PulseOutput(StopOrPresetRelay, RelayPulseTime);
CTimer stopTimer = new CTimer(new CTimerCallbackFunction((o) => StopRelay.Off()), RelayPulseTime);
} }
public override void Close() public override void Close()
{ {
Debug.Console(1, this, "Closing Shade: '{0}'", this.Name); Debug.Console(1, this, "Closing Shade: '{0}'", this.Name);
OpenRelay.Off();
StopRelay.Off();
CloseRelay.On(); PulseOutput(CloseRelay, RelayPulseTime);
}
void PulseOutput(ISwitchedOutput output, int pulseTime)
{
output.On();
CTimer pulseTimer = new CTimer(new CTimerCallbackFunction((o) => output.Off()), pulseTime);
} }
/// <summary> /// <summary>
@@ -98,11 +101,12 @@ namespace PepperDash.Essentials.Devices.Common.Environment.Somfy
{ {
public int RelayPulseTime { get; set; } public int RelayPulseTime { get; set; }
public ShadeRelaysConfig Relays { get; set; } public ShadeRelaysConfig Relays { get; set; }
public string StopOrPresetLabel { get; set; }
public class ShadeRelaysConfig public class ShadeRelaysConfig
{ {
public IOPortConfig Open { get; set; } public IOPortConfig Open { get; set; }
public IOPortConfig Stop { get; set; } public IOPortConfig StopOrPreset { get; set; }
public IOPortConfig Close { get; set; } public IOPortConfig Close { get; set; }
} }
} }

View File

@@ -8,6 +8,7 @@ using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Shades; using PepperDash.Essentials.Core.Shades;
using PepperDash.Essentials.Devices.Common.Environment.Somfy;
namespace PepperDash.Essentials namespace PepperDash.Essentials
{ {
@@ -88,7 +89,7 @@ namespace PepperDash.Essentials
{ {
if(DeviceType == eShadeDeviceType.OpenClose) if(DeviceType == eShadeDeviceType.OpenClose)
{ {
TriList.SetSigFalseAction(ButtonPressJoinBase + 1, ShadeDevice.Open); TriList.SetSigTrueAction(ButtonPressJoinBase + 1, ShadeDevice.Open);
TriList.SetSigFalseAction(ButtonPressJoinBase + 2, ShadeDevice.Close); TriList.SetSigFalseAction(ButtonPressJoinBase + 2, ShadeDevice.Close);
} }
@@ -96,8 +97,11 @@ namespace PepperDash.Essentials
{ {
TriList.SetSigFalseAction(ButtonPressJoinBase + 1, ShadeDevice.Open); TriList.SetSigFalseAction(ButtonPressJoinBase + 1, ShadeDevice.Open);
TriList.SetSigFalseAction(ButtonPressJoinBase + 2, (ShadeDevice as IShadesOpenCloseStop).Stop); TriList.SetSigFalseAction(ButtonPressJoinBase + 2, (ShadeDevice as IShadesOpenCloseStop).StopOrPreset);
if(ShadeDevice is RelayControlledShade)
TriList.SetString(StringJoinBase + 2, (ShadeDevice as RelayControlledShade).StopOrPresetButtonLabel);
TriList.SetSigFalseAction(ButtonPressJoinBase + 3, ShadeDevice.Close); TriList.SetSigFalseAction(ButtonPressJoinBase + 3, ShadeDevice.Close);
} }
} }

View File

@@ -1,19 +1,19 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
namespace PepperDash.Essentials namespace PepperDash.Essentials
{ {
public class JoinedSigInterlock public class JoinedSigInterlock
{ {
public uint CurrentJoin { get; private set; } public uint CurrentJoin { get; private set; }
BasicTriList TriList; BasicTriList TriList;
public BoolFeedback IsShownFeedback; public BoolFeedback IsShownFeedback;
@@ -33,97 +33,97 @@ namespace PepperDash.Essentials
} }
} }
//public BoolFeedback ShownFeedback { get; private set; } //public BoolFeedback ShownFeedback { get; private set; }
public JoinedSigInterlock(BasicTriList triList) public JoinedSigInterlock(BasicTriList triList)
{ {
TriList = triList; TriList = triList;
IsShownFeedback = new BoolFeedback(new Func<bool>( () => _IsShown)); IsShownFeedback = new BoolFeedback(new Func<bool>( () => _IsShown));
} }
/// <summary> /// <summary>
/// Hides CurrentJoin and shows join. Will check and re-set signal if join /// Hides CurrentJoin and shows join. Will check and re-set signal if join
/// equals CurrentJoin /// equals CurrentJoin
/// </summary> /// </summary>
public void ShowInterlocked(uint join) public void ShowInterlocked(uint join)
{ {
Debug.Console(2, "Trilist {0:X2}, interlock swapping {1} for {2}", TriList.ID, CurrentJoin, join); Debug.Console(2, "Trilist {0:X2}, interlock swapping {1} for {2}", TriList.ID, CurrentJoin, join);
if (CurrentJoin == join && TriList.BooleanInput[join].BoolValue) if (CurrentJoin == join && TriList.BooleanInput[join].BoolValue)
return; return;
SetButDontShow(join); SetButDontShow(join);
TriList.SetBool(CurrentJoin, true); TriList.SetBool(CurrentJoin, true);
IsShown = true; IsShown = true;
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="join"></param> /// <param name="join"></param>
public void ShowInterlockedWithToggle(uint join) public void ShowInterlockedWithToggle(uint join)
{ {
Debug.Console(2, "Trilist {0:X2}, interlock swapping {1} for {2}", TriList.ID, CurrentJoin, join); Debug.Console(2, "Trilist {0:X2}, interlock swapping {1} for {2}", TriList.ID, CurrentJoin, join);
if (CurrentJoin == join) if (CurrentJoin == join)
HideAndClear(); HideAndClear();
else else
{ {
if (CurrentJoin > 0) if (CurrentJoin > 0)
TriList.BooleanInput[CurrentJoin].BoolValue = false; TriList.BooleanInput[CurrentJoin].BoolValue = false;
CurrentJoin = join; CurrentJoin = join;
TriList.BooleanInput[CurrentJoin].BoolValue = true; TriList.BooleanInput[CurrentJoin].BoolValue = true;
IsShown = true; IsShown = true;
} }
} }
/// <summary> /// <summary>
/// Hides current join and clears CurrentJoin /// Hides current join and clears CurrentJoin
/// </summary> /// </summary>
public void HideAndClear() public void HideAndClear()
{ {
Debug.Console(2, "Trilist {0:X2}, interlock hiding {1}", TriList.ID, CurrentJoin); Debug.Console(2, "Trilist {0:X2}, interlock hiding {1}", TriList.ID, CurrentJoin);
Hide(); Hide();
CurrentJoin = 0; CurrentJoin = 0;
} }
/// <summary> /// <summary>
/// Hides the current join but does not clear the selected join in case /// Hides the current join but does not clear the selected join in case
/// it needs to be reshown /// it needs to be reshown
/// </summary> /// </summary>
public void Hide() public void Hide()
{ {
Debug.Console(2, "Trilist {0:X2}, interlock hiding {1}", TriList.ID, CurrentJoin); Debug.Console(2, "Trilist {0:X2}, interlock hiding {1}", TriList.ID, CurrentJoin);
if (CurrentJoin > 0) if (CurrentJoin > 0)
{ {
TriList.BooleanInput[CurrentJoin].BoolValue = false; TriList.BooleanInput[CurrentJoin].BoolValue = false;
IsShown = false; IsShown = false;
} }
} }
/// <summary> /// <summary>
/// If CurrentJoin is set, it restores that join /// If CurrentJoin is set, it restores that join
/// </summary> /// </summary>
public void Show() public void Show()
{ {
Debug.Console(2, "Trilist {0:X2}, interlock showing {1}", TriList.ID, CurrentJoin); Debug.Console(2, "Trilist {0:X2}, interlock showing {1}", TriList.ID, CurrentJoin);
if (CurrentJoin > 0) if (CurrentJoin > 0)
{ {
TriList.BooleanInput[CurrentJoin].BoolValue = true; TriList.BooleanInput[CurrentJoin].BoolValue = true;
IsShown = true; IsShown = true;
} }
} }
/// <summary> /// <summary>
/// Useful for pre-setting the interlock but not enabling it. Sets CurrentJoin /// Useful for pre-setting the interlock but not enabling it. Sets CurrentJoin
/// </summary> /// </summary>
/// <param name="join"></param> /// <param name="join"></param>
public void SetButDontShow(uint join) public void SetButDontShow(uint join)
{ {
if (CurrentJoin > 0) if (CurrentJoin > 0)
{ {
TriList.BooleanInput[CurrentJoin].BoolValue = false; TriList.BooleanInput[CurrentJoin].BoolValue = false;
IsShown = false; IsShown = false;
} }
CurrentJoin = join; CurrentJoin = join;
} }
} }
} }