From 6d913e8a72301cc80766eeb9655f6c484d6519fd Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 5 Apr 2018 17:08:42 -0600 Subject: [PATCH] Updates to LutronQuantum.cs --- .../PepperDashEssentialsBase/Global/Global.cs | 58 +- .../Lighting/LightingBase.cs | 8 +- .../Environment/Lutron/LutronQuantum.cs | 200 +++++++ .../Essentials Devices Common.csproj | 1 + .../UI/EssentialsTouchpanelController.cs | 502 +++++++++--------- 5 files changed, 485 insertions(+), 284 deletions(-) create mode 100644 Essentials Devices Common/Essentials Devices Common/Environment/Lutron/LutronQuantum.cs diff --git a/Essentials Core/PepperDashEssentialsBase/Global/Global.cs b/Essentials Core/PepperDashEssentialsBase/Global/Global.cs index 4d1602e2..74682dd1 100644 --- a/Essentials Core/PepperDashEssentialsBase/Global/Global.cs +++ b/Essentials Core/PepperDashEssentialsBase/Global/Global.cs @@ -1,18 +1,18 @@ -using Crestron.SimplSharp; -using Crestron.SimplSharp.CrestronDataStore; -using Crestron.SimplSharpPro; - -//using PepperDash.Essentials.Core.Http; -using PepperDash.Essentials.License; - - - -namespace PepperDash.Essentials.Core -{ - public static class Global - { - public static CrestronControlSystem ControlSystem { get; set; } - +using Crestron.SimplSharp; +using Crestron.SimplSharp.CrestronDataStore; +using Crestron.SimplSharpPro; + +//using PepperDash.Essentials.Core.Http; +using PepperDash.Essentials.License; + + + +namespace PepperDash.Essentials.Core +{ + public static class Global + { + public static CrestronControlSystem ControlSystem { get; set; } + public static LicenseManager LicenseManager { get; set; } public static string FilePathPrefix { get; private set; } @@ -32,18 +32,18 @@ namespace PepperDash.Essentials.Core public static void SetFilePathPrefix(string prefix) { FilePathPrefix = prefix; - } - - static Global() - { - // Fire up CrestronDataStoreStatic - var err = CrestronDataStoreStatic.InitCrestronDataStore(); - if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) - { - CrestronConsole.PrintLine("Error starting CrestronDataStoreStatic: {0}", err); - return; - } - } - - } + } + + static Global() + { + // Fire up CrestronDataStoreStatic + var err = CrestronDataStoreStatic.InitCrestronDataStore(); + if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS) + { + CrestronConsole.PrintLine("Error starting CrestronDataStoreStatic: {0}", err); + return; + } + } + + } } \ No newline at end of file diff --git a/Essentials Core/PepperDashEssentialsBase/Lighting/LightingBase.cs b/Essentials Core/PepperDashEssentialsBase/Lighting/LightingBase.cs index 88c0661a..0a1f71e6 100644 --- a/Essentials Core/PepperDashEssentialsBase/Lighting/LightingBase.cs +++ b/Essentials Core/PepperDashEssentialsBase/Lighting/LightingBase.cs @@ -11,10 +11,9 @@ namespace PepperDash.Essentials.Core.Lighting { public abstract class LightingBase : Device, ILightingScenes { - #region ILightingScenes Members - event EventHandler ILightingScenes.LightingSceneChange + public event EventHandler LightingSceneChange { add { throw new NotImplementedException(); } remove { throw new NotImplementedException(); } @@ -27,8 +26,8 @@ namespace PepperDash.Essentials.Core.Lighting #endregion - public LightingBase(string key, string name) : - base(key, name) + public LightingBase(string key, string name) + : base(key, name) { LightingScenes = new List(); } @@ -41,5 +40,6 @@ namespace PepperDash.Essentials.Core.Lighting public class LightingScene { public string Name { get; set; } + public object ID { get; set; } } } \ No newline at end of file diff --git a/Essentials Devices Common/Essentials Devices Common/Environment/Lutron/LutronQuantum.cs b/Essentials Devices Common/Essentials Devices Common/Environment/Lutron/LutronQuantum.cs new file mode 100644 index 00000000..fb37831c --- /dev/null +++ b/Essentials Devices Common/Essentials Devices Common/Environment/Lutron/LutronQuantum.cs @@ -0,0 +1,200 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.Lighting; + +namespace PepperDash.Essentials.Devices.Common.Environment.Lutron +{ + public class LutronQuantumArea : LightingBase, ILightingMasterRaiseLower, ICommunicationMonitor + { + public IBasicCommunication Communication { get; private set; } + public CommunicationGather PortGather { get; private set; } + public StatusMonitorBase CommunicationMonitor { get; private set; } + + public int IntegrationId; + public string Password; + + const string Delimiter = "\x0d\x0a"; + const string Set = "#"; + const string Get = "?"; + + public LutronQuantumArea(string key, string name, IBasicCommunication comm, LutronQuantumPropertiesConfig props) + : base(key, name) + { + Communication = comm; + + IntegrationId = props.IntegrationId; + + Password = props.Password; + + LightingScenes = props.Scenes; + + var socket = comm as ISocketStatus; + if (socket != null) + { + // IP Control + socket.ConnectionChange += new EventHandler(socket_ConnectionChange); + } + else + { + // RS-232 Control + } + + PortGather = new CommunicationGather(Communication, Delimiter); + PortGather.LineReceived += new EventHandler(PortGather_LineReceived); + + if (props.CommunicationMonitorProperties != null) + { + CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, props.CommunicationMonitorProperties); + } + else + { + CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 120000, 120000, 300000, "?SYSTEM,1\x0d\x0a"); + } + } + + public override bool CustomActivate() + { + Communication.Connect(); + CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); }; + CommunicationMonitor.Start(); + + return true; + } + + void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e) + { + Debug.Console(2, this, "Socket Status Change: {0}", e.Client.ClientStatus.ToString()); + + if (e.Client.IsConnected) + { + // Tasks on connect + } + } + + void PortGather_LineReceived(object sender, GenericCommMethodReceiveTextArgs args) + { + try + { + if (args.Text.IndexOf("login:") > -1) + { + // Login + SendLine(Password); + } + else if (args.Text.IndexOf("~AREA") > -1) + { + var response = args.Text.Split(','); + + var integrationId = Int32.Parse(response[1]); + + if (integrationId != IntegrationId) + { + Debug.Console(2, this, "Response is not for correct Integration ID"); + return; + } + else + { + var action = Int32.Parse(response[2]); + + switch (action) + { + case (int)eAction.Scene: + { + var scene = Int32.Parse(response[3]); + CurrentLightingScene = LightingScenes.FirstOrDefault(s => s.ID.Equals(scene)); + + var handler = LightingSceneChange; + if (handler != null) + { + handler(this, new LightingSceneChangeEventArgs(CurrentLightingScene)); + } + + break; + } + default: + break; + } + } + } + } + catch (Exception e) + { + Debug.Console(2, this, "Error parsing response:\n{0}", e); + } + } + + /// + /// Recalls the specified scene + /// + /// + public void SelectScene(LightingScene scene) + { + SendLine(string.Format("{0}AREA,{1},{2},{3}", Set, IntegrationId, (int)eAction.Scene, (int)scene.ID)); + } + + /// + /// Begins raising the lights in the area + /// + public void MasterRaise() + { + SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Raise)); + } + + /// + /// Begins lowering the lights in the area + /// + public void MasterLower() + { + SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Lower)); + } + + /// + /// Stops the current raise/lower action + /// + public void MasterRaiseLowerStop() + { + SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Stop)); + } + + /// + /// Appends the delimiter and sends the string + /// + /// + public void SendLine(string s) + { + Debug.Console(1, this, "TX: '{0}'", s); + Communication.SendText(s + Delimiter); + } + } + + public enum eAction + { + SetLevel = 1, + Raise = 2, + Lower = 3, + Stop = 4, + Scene = 6, + DaylightMode = 7, + OccupancyState = 8, + OccupancyMode = 9, + OccupiedLevelOrScene = 12, + UnoccupiedLevelOrScene = 13, + HyperionShaddowSensorOverrideState = 26, + HyperionBrightnessSensorOverrideStatue = 27 + } + + public class LutronQuantumPropertiesConfig + { + public CommunicationMonitorConfig CommunicationMonitorProperties { get; set; } + public ControlPropertiesConfig Control { get; set; } + + public int IntegrationId { get; set; } + public List Scenes{ get; set; } + + public string Password { get; set; } + } +} \ No newline at end of file diff --git a/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj b/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj index 38bc0a3a..e44f2459 100644 --- a/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj +++ b/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj @@ -118,6 +118,7 @@ + diff --git a/Essentials/PepperDashEssentials/UI/EssentialsTouchpanelController.cs b/Essentials/PepperDashEssentials/UI/EssentialsTouchpanelController.cs index 21d81863..826e12f4 100644 --- a/Essentials/PepperDashEssentials/UI/EssentialsTouchpanelController.cs +++ b/Essentials/PepperDashEssentials/UI/EssentialsTouchpanelController.cs @@ -1,260 +1,260 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; -using Crestron.SimplSharp.CrestronIO; -using Crestron.SimplSharpPro; -using Crestron.SimplSharpPro.DeviceSupport; -using Crestron.SimplSharpPro.UI; -using PepperDash.Core; -using PepperDash.Essentials.Core; -using PepperDash.Essentials.Core.PageManagers; - -namespace PepperDash.Essentials -{ - public class EssentialsTouchpanelController : Device - { - public BasicTriListWithSmartObject Panel { get; private set; } - - public PanelDriverBase PanelDriver { get; private set; } - - CTimer BacklightTransitionedOnTimer; - - public EssentialsTouchpanelController(string key, string name, Tswx52ButtonVoiceControl tsw, - string projectName, string sgdPath) - : base(key, name) - { - Panel = tsw; - tsw.LoadSmartObjects(sgdPath); - tsw.SigChange += new Crestron.SimplSharpPro.DeviceSupport.SigEventHandler(Tsw_SigChange); - } - - /// - /// Config constructor - /// - public EssentialsTouchpanelController(string key, string name, string type, CrestronTouchpanelPropertiesConfig props, uint id) - : base(key, name) - { - AddPostActivationAction(() => +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharp.CrestronIO; +using Crestron.SimplSharpPro; +using Crestron.SimplSharpPro.DeviceSupport; +using Crestron.SimplSharpPro.UI; +using PepperDash.Core; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Core.PageManagers; + +namespace PepperDash.Essentials +{ + public class EssentialsTouchpanelController : Device + { + public BasicTriListWithSmartObject Panel { get; private set; } + + public PanelDriverBase PanelDriver { get; private set; } + + CTimer BacklightTransitionedOnTimer; + + public EssentialsTouchpanelController(string key, string name, Tswx52ButtonVoiceControl tsw, + string projectName, string sgdPath) + : base(key, name) + { + Panel = tsw; + tsw.LoadSmartObjects(sgdPath); + tsw.SigChange += new Crestron.SimplSharpPro.DeviceSupport.SigEventHandler(Tsw_SigChange); + } + + /// + /// Config constructor + /// + public EssentialsTouchpanelController(string key, string name, string type, CrestronTouchpanelPropertiesConfig props, uint id) + : base(key, name) + { + AddPostActivationAction(() => { -#warning Temporary Error logging for XiO Edge Debugging - Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Creating touchpanel hardware..."); - type = type.ToLower(); - try - { - if (type == "crestronapp") - { - var app = new CrestronApp(id, Global.ControlSystem); - app.ParameterProjectName.Value = props.ProjectName; - Panel = app; - } - else if (type == "tsw550") - Panel = new Tsw550(id, Global.ControlSystem); - else if (type == "tsw552") - Panel = new Tsw552(id, Global.ControlSystem); - else if (type == "tsw560") - Panel = new Tsw560(id, Global.ControlSystem); - else if (type == "tsw750") - Panel = new Tsw750(id, Global.ControlSystem); - else if (type == "tsw752") - Panel = new Tsw752(id, Global.ControlSystem); - else if (type == "tsw760") - Panel = new Tsw760(id, Global.ControlSystem); - else if (type == "tsw1050") - Panel = new Tsw1050(id, Global.ControlSystem); - else if (type == "tsw1052") - Panel = new Tsw1052(id, Global.ControlSystem); - else if (type == "tsw1060") - Panel = new Tsw1060(id, Global.ControlSystem); +#warning Temporary Error logging for XiO Edge Debugging + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "Creating touchpanel hardware..."); + type = type.ToLower(); + try + { + if (type == "crestronapp") + { + var app = new CrestronApp(id, Global.ControlSystem); + app.ParameterProjectName.Value = props.ProjectName; + Panel = app; + } + else if (type == "tsw550") + Panel = new Tsw550(id, Global.ControlSystem); + else if (type == "tsw552") + Panel = new Tsw552(id, Global.ControlSystem); + else if (type == "tsw560") + Panel = new Tsw560(id, Global.ControlSystem); + else if (type == "tsw750") + Panel = new Tsw750(id, Global.ControlSystem); + else if (type == "tsw752") + Panel = new Tsw752(id, Global.ControlSystem); + else if (type == "tsw760") + Panel = new Tsw760(id, Global.ControlSystem); + else if (type == "tsw1050") + Panel = new Tsw1050(id, Global.ControlSystem); + else if (type == "tsw1052") + Panel = new Tsw1052(id, Global.ControlSystem); + else if (type == "tsw1060") + Panel = new Tsw1060(id, Global.ControlSystem); else { #warning Temporary Error logging for XiO Edge Debugging - Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW controller with type '{0}'", type); - return; - } - } - catch (Exception e) + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW controller with type '{0}'", type); + return; + } + } + catch (Exception e) { #warning Temporary Error logging for XiO Edge Debugging - Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW base class. Panel will not function: {0}", e.Message); - return; - } - - // Reserved sigs - if (Panel is TswFt5ButtonSystem) - { - var tsw = Panel as TswFt5ButtonSystem; - tsw.ExtenderSystemReservedSigs.Use(); - tsw.ExtenderSystemReservedSigs.DeviceExtenderSigChange - += ExtenderSystemReservedSigs_DeviceExtenderSigChange; - } - - //CrestronInvoke.BeginInvoke(o => - // { + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW base class. Panel will not function: {0}", e.Message); + return; + } + + // Reserved sigs + if (Panel is TswFt5ButtonSystem) + { + var tsw = Panel as TswFt5ButtonSystem; + tsw.ExtenderSystemReservedSigs.Use(); + tsw.ExtenderSystemReservedSigs.DeviceExtenderSigChange + += ExtenderSystemReservedSigs_DeviceExtenderSigChange; + } + + //CrestronInvoke.BeginInvoke(o => + // { var regSuccess = Panel.Register(); #warning Temporary Error logging for XiO Edge Debugging - if (regSuccess != eDeviceRegistrationUnRegistrationResponse.Success) - Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Registration failed. Continuing, but panel may not function: {0}", regSuccess); - - // Give up cleanly if SGD is not present. - var sgdName = Global.FilePathPrefix - + Global.DirectorySeparator + "sgd" + Global.DirectorySeparator + props.SgdFile; - if (!File.Exists(sgdName)) - { - Debug.Console(0, this, "ERROR: Smart object file '{0}' not present. Exiting TSW load", sgdName); - return; - } - - Panel.LoadSmartObjects(sgdName); - Panel.SigChange += Tsw_SigChange; - - var mainDriver = new EssentialsPanelMainInterfaceDriver(Panel, props); - // Then the AV driver - - // spin up different room drivers depending on room type - var room = DeviceManager.GetDeviceForKey(props.DefaultRoomKey); - if (room is EssentialsHuddleSpaceRoom) - { - Debug.Console(0, this, "Adding huddle space driver"); - var avDriver = new EssentialsHuddlePanelAvFunctionsDriver(mainDriver, props); - avDriver.CurrentRoom = room as EssentialsHuddleSpaceRoom; - avDriver.DefaultRoomKey = props.DefaultRoomKey; - mainDriver.AvDriver = avDriver; - LoadAndShowDriver(mainDriver); // This is a little convoluted. - - if (Panel is TswFt5ButtonSystem) - { - var tsw = Panel as TswFt5ButtonSystem; - // Wire up hard keys - tsw.Power.UserObject = new Action(b => { if (!b) avDriver.PowerButtonPressed(); }); - //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); - tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); - tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); - tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); - } - } - else if (room is EssentialsPresentationRoom) - { - Debug.Console(0, this, "Adding presentation room driver"); - var avDriver = new EssentialsPresentationPanelAvFunctionsDriver(mainDriver, props); - avDriver.CurrentRoom = room as EssentialsPresentationRoom; - avDriver.DefaultRoomKey = props.DefaultRoomKey; - mainDriver.AvDriver = avDriver; - LoadAndShowDriver(mainDriver); - - if (Panel is TswFt5ButtonSystem) - { - var tsw = Panel as TswFt5ButtonSystem; - // Wire up hard keys - tsw.Power.UserObject = new Action(b => { if (!b) avDriver.PowerButtonPressed(); }); - //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); - tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); - tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); - tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); - } - } - else if (room is EssentialsHuddleVtc1Room) - { - Debug.Console(0, this, "Adding huddle space driver"); - var avDriver = new EssentialsHuddleVtc1PanelAvFunctionsDriver(mainDriver, props); - var codecDriver = new PepperDash.Essentials.UIDrivers.VC.EssentialsVideoCodecUiDriver(Panel, avDriver, - (room as EssentialsHuddleVtc1Room).VideoCodec); - avDriver.SetVideoCodecDriver(codecDriver); - avDriver.CurrentRoom = room as EssentialsHuddleVtc1Room; - avDriver.DefaultRoomKey = props.DefaultRoomKey; - mainDriver.AvDriver = avDriver; - LoadAndShowDriver(mainDriver); // This is a little convoluted. - - if (Panel is TswFt5ButtonSystem) - { - var tsw = Panel as TswFt5ButtonSystem; - // Wire up hard keys - tsw.Power.UserObject = new Action(b => { if (!b) avDriver.EndMeetingPress(); }); - //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); - tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); - tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); - tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); - } - } - else - { - Debug.Console(0, this, "ERROR: Cannot load AvFunctionsDriver for room '{0}'", props.DefaultRoomKey); - } - //}, 0); - }); - } - - public void LoadAndShowDriver(PanelDriverBase driver) - { - PanelDriver = driver; - driver.Show(); - } - - void HomePressed() - { - if (BacklightTransitionedOnTimer == null) - PanelDriver.BackButtonPressed(); - } - - - void ExtenderSystemReservedSigs_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender, SigEventArgs args) - { - // If the sig is transitioning on, mark it in case it was home button that transitioned it - var blOnSig = (Panel as TswFt5ButtonSystem).ExtenderSystemReservedSigs.BacklightOnFeedback; - if (args.Sig == blOnSig && blOnSig.BoolValue) - { - BacklightTransitionedOnTimer = new CTimer(o => - { - BacklightTransitionedOnTimer = null; - }, 200); - } - } - - public void PulseBool(uint join) - { - var act = Panel.BooleanInput[join].UserObject as Action; - if (act != null) - { - act(true); - act(false); - } - } - - public void SetBoolSig(uint join, bool value) - { - var act = Panel.BooleanInput[join].UserObject as Action; - if (act != null) - act(value); - } - - public void SetIntSig(uint join, ushort value) - { - var act = Panel.BooleanInput[join].UserObject as Action; - if (act != null) - { - act(value); - } - } - - void Tsw_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args) - { - if (Debug.Level == 2) - Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); - var uo = args.Sig.UserObject; - if (uo is Action) - (uo as Action)(args.Sig.BoolValue); - else if (uo is Action) - (uo as Action)(args.Sig.UShortValue); - else if (uo is Action) - (uo as Action)(args.Sig.StringValue); - } - - void Tsw_ButtonStateChange(GenericBase device, ButtonEventArgs args) - { - var uo = args.Button.UserObject; - if(uo is Action) - (uo as Action)(args.Button.State == eButtonState.Pressed); - } - } + if (regSuccess != eDeviceRegistrationUnRegistrationResponse.Success) + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Registration failed. Continuing, but panel may not function: {0}", regSuccess); + + // Give up cleanly if SGD is not present. + var sgdName = Global.FilePathPrefix + + Global.DirectorySeparator + "sgd" + Global.DirectorySeparator + props.SgdFile; + if (!File.Exists(sgdName)) + { + Debug.Console(0, this, "ERROR: Smart object file '{0}' not present. Exiting TSW load", sgdName); + return; + } + + Panel.LoadSmartObjects(sgdName); + Panel.SigChange += Tsw_SigChange; + + var mainDriver = new EssentialsPanelMainInterfaceDriver(Panel, props); + // Then the AV driver + + // spin up different room drivers depending on room type + var room = DeviceManager.GetDeviceForKey(props.DefaultRoomKey); + if (room is EssentialsHuddleSpaceRoom) + { + Debug.Console(0, this, "Adding huddle space driver"); + var avDriver = new EssentialsHuddlePanelAvFunctionsDriver(mainDriver, props); + avDriver.CurrentRoom = room as EssentialsHuddleSpaceRoom; + avDriver.DefaultRoomKey = props.DefaultRoomKey; + mainDriver.AvDriver = avDriver; + LoadAndShowDriver(mainDriver); // This is a little convoluted. + + if (Panel is TswFt5ButtonSystem) + { + var tsw = Panel as TswFt5ButtonSystem; + // Wire up hard keys + tsw.Power.UserObject = new Action(b => { if (!b) avDriver.PowerButtonPressed(); }); + //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); + tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); + tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); + tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); + } + } + else if (room is EssentialsPresentationRoom) + { + Debug.Console(0, this, "Adding presentation room driver"); + var avDriver = new EssentialsPresentationPanelAvFunctionsDriver(mainDriver, props); + avDriver.CurrentRoom = room as EssentialsPresentationRoom; + avDriver.DefaultRoomKey = props.DefaultRoomKey; + mainDriver.AvDriver = avDriver; + LoadAndShowDriver(mainDriver); + + if (Panel is TswFt5ButtonSystem) + { + var tsw = Panel as TswFt5ButtonSystem; + // Wire up hard keys + tsw.Power.UserObject = new Action(b => { if (!b) avDriver.PowerButtonPressed(); }); + //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); + tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); + tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); + tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); + } + } + else if (room is EssentialsHuddleVtc1Room) + { + Debug.Console(0, this, "Adding huddle space driver"); + var avDriver = new EssentialsHuddleVtc1PanelAvFunctionsDriver(mainDriver, props); + var codecDriver = new PepperDash.Essentials.UIDrivers.VC.EssentialsVideoCodecUiDriver(Panel, avDriver, + (room as EssentialsHuddleVtc1Room).VideoCodec); + avDriver.SetVideoCodecDriver(codecDriver); + avDriver.CurrentRoom = room as EssentialsHuddleVtc1Room; + avDriver.DefaultRoomKey = props.DefaultRoomKey; + mainDriver.AvDriver = avDriver; + LoadAndShowDriver(mainDriver); // This is a little convoluted. + + if (Panel is TswFt5ButtonSystem) + { + var tsw = Panel as TswFt5ButtonSystem; + // Wire up hard keys + tsw.Power.UserObject = new Action(b => { if (!b) avDriver.EndMeetingPress(); }); + //tsw.Home.UserObject = new Action(b => { if (!b) HomePressed(); }); + tsw.Up.UserObject = new Action(avDriver.VolumeUpPress); + tsw.Down.UserObject = new Action(avDriver.VolumeDownPress); + tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); + } + } + else + { + Debug.Console(0, this, "ERROR: Cannot load AvFunctionsDriver for room '{0}'", props.DefaultRoomKey); + } + //}, 0); + }); + } + + public void LoadAndShowDriver(PanelDriverBase driver) + { + PanelDriver = driver; + driver.Show(); + } + + void HomePressed() + { + if (BacklightTransitionedOnTimer == null) + PanelDriver.BackButtonPressed(); + } + + + void ExtenderSystemReservedSigs_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender, SigEventArgs args) + { + // If the sig is transitioning on, mark it in case it was home button that transitioned it + var blOnSig = (Panel as TswFt5ButtonSystem).ExtenderSystemReservedSigs.BacklightOnFeedback; + if (args.Sig == blOnSig && blOnSig.BoolValue) + { + BacklightTransitionedOnTimer = new CTimer(o => + { + BacklightTransitionedOnTimer = null; + }, 200); + } + } + + public void PulseBool(uint join) + { + var act = Panel.BooleanInput[join].UserObject as Action; + if (act != null) + { + act(true); + act(false); + } + } + + public void SetBoolSig(uint join, bool value) + { + var act = Panel.BooleanInput[join].UserObject as Action; + if (act != null) + act(value); + } + + public void SetIntSig(uint join, ushort value) + { + var act = Panel.BooleanInput[join].UserObject as Action; + if (act != null) + { + act(value); + } + } + + void Tsw_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args) + { + if (Debug.Level == 2) + Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); + var uo = args.Sig.UserObject; + if (uo is Action) + (uo as Action)(args.Sig.BoolValue); + else if (uo is Action) + (uo as Action)(args.Sig.UShortValue); + else if (uo is Action) + (uo as Action)(args.Sig.StringValue); + } + + void Tsw_ButtonStateChange(GenericBase device, ButtonEventArgs args) + { + var uo = args.Button.UserObject; + if(uo is Action) + (uo as Action)(args.Button.State == eButtonState.Pressed); + } + } } \ No newline at end of file