From d01be57f814ad69f7b1456f3da8b556c5881c757 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 2 Sep 2022 13:54:34 -0600 Subject: [PATCH 1/4] feat: add TouchpanelBase class and initial implementation --- .../UI/EssentialsTouchpanelController.cs | 199 +------------ .../PepperDash_Essentials_Core.csproj | 1 + .../UI/TouchpanelBase.cs | 270 ++++++++++++++++++ 3 files changed, 278 insertions(+), 192 deletions(-) create mode 100644 essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs diff --git a/PepperDashEssentials/UI/EssentialsTouchpanelController.cs b/PepperDashEssentials/UI/EssentialsTouchpanelController.cs index 441381bd..24bc33db 100644 --- a/PepperDashEssentials/UI/EssentialsTouchpanelController.cs +++ b/PepperDashEssentials/UI/EssentialsTouchpanelController.cs @@ -11,10 +11,11 @@ using PepperDash.Core; using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.PageManagers; +using PepperDash.Essentials.Core.UI; namespace PepperDash.Essentials { - public class EssentialsTouchpanelController : EssentialsDevice, IHasBasicTriListWithSmartObject + public class EssentialsTouchpanelController : TouchpanelBase { private CrestronTouchpanelPropertiesConfig _propertiesConfig; @@ -26,189 +27,29 @@ namespace PepperDash.Essentials public EssentialsTouchpanelController(string key, string name, Tswx52ButtonVoiceControl tsw, string projectName, string sgdPath) - : base(key, name) + : base(key, name, tsw, sgdPath) { - Panel = tsw; - - if (!string.IsNullOrEmpty(sgdPath)) - Panel.LoadSmartObjects(sgdPath); - else - Debug.Console(1, this, "No SGD file path defined"); - - - - tsw.SigChange += Panel_SigChange; } public EssentialsTouchpanelController(string key, string name, Dge100 dge, string projectName, string sgdPath) - : base(key, name) + : base(key, name, dge, sgdPath) { - Panel = dge; - - if (!string.IsNullOrEmpty(sgdPath)) - Panel.LoadSmartObjects(sgdPath); - else - Debug.Console(1, this, "No SGD file path defined"); - - dge.SigChange += Panel_SigChange; } /// /// Config constructor /// public EssentialsTouchpanelController(string key, string name, string type, CrestronTouchpanelPropertiesConfig props, uint id) - : base(key, name) + : base(key, name, type, props, id) { - _propertiesConfig = props; - - 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 == "xpanel") - Panel = new XpanelForSmartGraphics(id, Global.ControlSystem); - 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 if (type == "tsw570") - Panel = new Tsw570(id, Global.ControlSystem); - else if (type == "tsw770") - Panel = new Tsw770(id, Global.ControlSystem); - else if (type == "ts770") - Panel = new Ts770(id, Global.ControlSystem); - else if (type == "tsw1070") - Panel = new Tsw1070(id, Global.ControlSystem); - else if (type == "ts1070") - Panel = new Ts1070(id, Global.ControlSystem); - else - { - 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 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; - - tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); - - } - - if (Panel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) - Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Registration failed. Continuing, but panel may not function: {0}", Panel.RegistrationFailureReason); - - // Give up cleanly if SGD is not present. - var sgdName = Global.FilePathPrefix + "sgd" + Global.DirectorySeparator + props.SgdFile; - if (!File.Exists(sgdName)) - { - Debug.Console(0, this, "Smart object file '{0}' not present in User folder. Looking for embedded file", sgdName); - - sgdName = Global.ApplicationDirectoryPathPrefix + Global.DirectorySeparator + "SGD" + Global.DirectorySeparator + props.SgdFile; - - if (!File.Exists(sgdName)) - { - Debug.Console(0, this, "Unable to find SGD file '{0}' in User sgd or application SGD folder. Exiting touchpanel load.", sgdName); - return; - } - } - - Panel.LoadSmartObjects(sgdName); - Panel.SigChange += Panel_SigChange; - - AddPostActivationAction(() => - { - // Check for IEssentialsRoomCombiner in DeviceManager and if found, subscribe to its event - var roomCombiner = DeviceManager.AllDevices.FirstOrDefault((d) => d is IEssentialsRoomCombiner) as IEssentialsRoomCombiner; - - if (roomCombiner != null) - { - // Subscribe to the even - roomCombiner.RoomCombinationScenarioChanged += new EventHandler(roomCombiner_RoomCombinationScenarioChanged); - - // Connect to the initial roomKey - if (roomCombiner.CurrentScenario != null) - { - // Use the current scenario - DetermineRoomKeyFromScenario(roomCombiner.CurrentScenario); - } - else - { - // Current Scenario not yet set. Use default - SetupPanelDrivers(_propertiesConfig.DefaultRoomKey); - } - } - else - { - // No room combiner, use the default key - SetupPanelDrivers(_propertiesConfig.DefaultRoomKey); - } - }); } - void roomCombiner_RoomCombinationScenarioChanged(object sender, EventArgs e) - { - var roomCombiner = sender as IEssentialsRoomCombiner; - - DetermineRoomKeyFromScenario(roomCombiner.CurrentScenario); - } - - /// - /// Determines the room key to use based on the scenario - /// - /// - void DetermineRoomKeyFromScenario(IRoomCombinationScenario scenario) - { - string newRoomKey = null; - - if (scenario.UiMap.ContainsKey(Key)) - { - newRoomKey = scenario.UiMap[Key]; - } - else if (scenario.UiMap.ContainsKey(_propertiesConfig.DefaultRoomKey)) - { - newRoomKey = scenario.UiMap[_propertiesConfig.DefaultRoomKey]; - } - - SetupPanelDrivers(newRoomKey); - } - /// /// Sets up drivers and links them to the room specified /// /// key of room to link the drivers to - void SetupPanelDrivers(string roomKey) + protected override void SetupPanelDrivers(string roomKey) { // Clear out any existing actions Panel.ClearAllSigActions(); @@ -338,13 +179,7 @@ namespace PepperDash.Essentials driver.Show(); } - void HomePressed() - { - if (BacklightTransitionedOnTimer == null) - PanelDriver.BackButtonPressed(); - } - - void ExtenderSystemReservedSigs_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender, SigEventArgs args) + protected override 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; @@ -382,26 +217,6 @@ namespace PepperDash.Essentials act(value); } } - - void Panel_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); - } } public class EssentialsTouchpanelControllerFactory : EssentialsDeviceFactory diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj index 9bf1f8ca..b2a3b363 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.csproj @@ -366,6 +366,7 @@ + diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs new file mode 100644 index 00000000..01409cf4 --- /dev/null +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs @@ -0,0 +1,270 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using PepperDash.Essentials.Core; +using Crestron.SimplSharpPro.DeviceSupport; +using PepperDash.Core; +using Crestron.SimplSharpPro.UI; +using Crestron.SimplSharp.CrestronIO; +using Crestron.SimplSharpPro; + +namespace PepperDash.Essentials.Core.UI +{ + public abstract class TouchpanelBase: EssentialsDevice, IHasBasicTriListWithSmartObject + { + protected CrestronTouchpanelPropertiesConfig _config; + public BasicTriListWithSmartObject Panel { get; private set; } + + /// + /// Constructor for pre-created Panel. This constructor attempts to load the SGD file from the provided SGD path and subscribes to the + /// `SigChange` event for the provided panel. + /// + /// Essentials Device Key + /// Essentials Device Name + /// Provided TSW Panel + /// Path to SGD file + protected TouchpanelBase(string key, string name, Tswx52ButtonVoiceControl tsw, string sgdPath) + :base(key, name) + { + Panel = tsw; + + //moving loading of SGD to preactivation action...should make creation quicker + AddPreActivationAction(() => { + if(!string.IsNullOrEmpty(sgdPath)) + { + Debug.Console(1, this, "Loading sgd file from {0}", sgdPath); + Panel.LoadSmartObjects(sgdPath); + return; + } + + Debug.Console(1, this, "No SGD file path defined"); + }); + + Panel.SigChange += Panel_SigChange; + } + + /// + /// Constructor for use with DGE panels. This constructor attempts to load the provided SGD file from the provided SGD path and subscribes to the + /// `SigChange` event for the provided DGE. + /// + /// Essentials Device Key + /// Essentials Device Name + /// Provided DGE + /// Path to SGD file + protected TouchpanelBase(string key, string name, Dge100 dge, string sgdPath):base(key, name) + { + Panel = dge; + + AddPreActivationAction(() => + { + if (!string.IsNullOrEmpty(sgdPath)) + { + Debug.Console(1, this, "Loading sgd file from {0}", sgdPath); + Panel.LoadSmartObjects(sgdPath); + return; + } + + Debug.Console(1, this, "No SGD file path defined"); + }); + + Panel.SigChange += Panel_SigChange; + } + + /// + /// Constructor for use with device Factory. A touch panel device will be created based on the provided IP-ID and the + /// type of the panel. The SGD File path can be specified using the config property, or a default one located in the program directory if none + /// is provided. + /// + /// Essentials Device Key + /// Essentials Device Name + /// Touchpanel Type to build + /// Touchpanel Configuration + /// IP-ID to use for touch panel + protected TouchpanelBase(string key, string name, string type, CrestronTouchpanelPropertiesConfig config, uint id) + :base(key, name) + { + var panel = GetPanelForType(type, id); + if(panel != null) + { + Panel = panel; + } + + if (Panel is TswFt5ButtonSystem) + { + var tsw = Panel as TswFt5ButtonSystem; + tsw.ExtenderSystemReservedSigs.Use(); + tsw.ExtenderSystemReservedSigs.DeviceExtenderSigChange + += ExtenderSystemReservedSigs_DeviceExtenderSigChange; + + tsw.ButtonStateChange += Tsw_ButtonStateChange; + } + + + AddPreActivationAction(() => { + if (Panel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Registration failed. Continuing, but panel may not function: {0}", Panel.RegistrationFailureReason); + + // Give up cleanly if SGD is not present. + var sgdName = Global.FilePathPrefix + "sgd" + Global.DirectorySeparator + _config.SgdFile; + if (!File.Exists(sgdName)) + { + Debug.Console(0, this, "Smart object file '{0}' not present in User folder. Looking for embedded file", sgdName); + + sgdName = Global.ApplicationDirectoryPathPrefix + Global.DirectorySeparator + "SGD" + Global.DirectorySeparator + config.SgdFile; + + if (!File.Exists(sgdName)) + { + Debug.Console(0, this, "Unable to find SGD file '{0}' in User sgd or application SGD folder. Exiting touchpanel load.", sgdName); + return; + } + } + }); + + AddPostActivationAction(() => + { + // Check for IEssentialsRoomCombiner in DeviceManager and if found, subscribe to its event + var roomCombiner = DeviceManager.AllDevices.FirstOrDefault((d) => d is IEssentialsRoomCombiner) as IEssentialsRoomCombiner; + + if (roomCombiner != null) + { + // Subscribe to the even + roomCombiner.RoomCombinationScenarioChanged += new EventHandler(roomCombiner_RoomCombinationScenarioChanged); + + // Connect to the initial roomKey + if (roomCombiner.CurrentScenario != null) + { + // Use the current scenario + DetermineRoomKeyFromScenario(roomCombiner.CurrentScenario); + } + else + { + // Current Scenario not yet set. Use default + SetupPanelDrivers(_config.DefaultRoomKey); + } + } + else + { + // No room combiner, use the default key + SetupPanelDrivers(_config.DefaultRoomKey); + } + }); + } + + /// + /// Setup Panel operation + /// + /// Room Key for this panel + protected abstract void SetupPanelDrivers(string roomKey); + + + /// + /// + /// + /// + /// + protected virtual void roomCombiner_RoomCombinationScenarioChanged(object sender, EventArgs e) + { + var roomCombiner = sender as IEssentialsRoomCombiner; + + DetermineRoomKeyFromScenario(roomCombiner.CurrentScenario); + } + + /// + /// Determines the room key to use based on the scenario + /// + /// + protected virtual void DetermineRoomKeyFromScenario(IRoomCombinationScenario scenario) + { + string newRoomKey = null; + + if (scenario.UiMap.ContainsKey(Key)) + { + newRoomKey = scenario.UiMap[Key]; + } + else if (scenario.UiMap.ContainsKey(_config.DefaultRoomKey)) + { + newRoomKey = scenario.UiMap[_config.DefaultRoomKey]; + } + + SetupPanelDrivers(newRoomKey); + } + + private BasicTriListWithSmartObject GetPanelForType(string type, uint id) + { + type = type.ToLower(); + try + { + if (type == "crestronapp") + { + var app = new CrestronApp(id, Global.ControlSystem); + app.ParameterProjectName.Value = _config.ProjectName; + return app; + } + else if (type == "xpanel") + return new XpanelForSmartGraphics(id, Global.ControlSystem); + else if (type == "tsw550") + return new Tsw550(id, Global.ControlSystem); + else if (type == "tsw552") + return new Tsw552(id, Global.ControlSystem); + else if (type == "tsw560") + return new Tsw560(id, Global.ControlSystem); + else if (type == "tsw750") + return new Tsw750(id, Global.ControlSystem); + else if (type == "tsw752") + return new Tsw752(id, Global.ControlSystem); + else if (type == "tsw760") + return new Tsw760(id, Global.ControlSystem); + else if (type == "tsw1050") + return new Tsw1050(id, Global.ControlSystem); + else if (type == "tsw1052") + return new Tsw1052(id, Global.ControlSystem); + else if (type == "tsw1060") + return new Tsw1060(id, Global.ControlSystem); + else if (type == "tsw570") + return new Tsw570(id, Global.ControlSystem); + else if (type == "tsw770") + return new Tsw770(id, Global.ControlSystem); + else if (type == "ts770") + return new Ts770(id, Global.ControlSystem); + else if (type == "tsw1070") + return new Tsw1070(id, Global.ControlSystem); + else if (type == "ts1070") + return new Ts1070(id, Global.ControlSystem); + else + { + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW controller with type '{0}'", type); + return null; + } + } + catch (Exception e) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW base class. Panel will not function: {0}", e.Message); + return null; + } + } + + private void Panel_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); + } + + private void Tsw_ButtonStateChange(GenericBase device, ButtonEventArgs args) + { + var uo = args.Button.UserObject; + if(uo is Action) + (uo as Action)(args.Button.State == eButtonState.Pressed); + } + + protected abstract void ExtenderSystemReservedSigs_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender, SigEventArgs args); + } +} \ No newline at end of file From 88a16b577b46778606f88b183ef6eb667e3a9418 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 2 Sep 2022 14:35:06 -0600 Subject: [PATCH 2/4] refactor: update constructors for touchpanel controller and base class --- .../UI/EssentialsTouchpanelController.cs | 100 +++++++++++----- .../UI/TouchpanelBase.cs | 109 +----------------- 2 files changed, 77 insertions(+), 132 deletions(-) diff --git a/PepperDashEssentials/UI/EssentialsTouchpanelController.cs b/PepperDashEssentials/UI/EssentialsTouchpanelController.cs index 24bc33db..34d5e11a 100644 --- a/PepperDashEssentials/UI/EssentialsTouchpanelController.cs +++ b/PepperDashEssentials/UI/EssentialsTouchpanelController.cs @@ -12,35 +12,21 @@ using PepperDash.Essentials.Core; using PepperDash.Essentials.Core.Config; using PepperDash.Essentials.Core.PageManagers; using PepperDash.Essentials.Core.UI; +using Newtonsoft.Json; namespace PepperDash.Essentials { public class EssentialsTouchpanelController : TouchpanelBase - { - private CrestronTouchpanelPropertiesConfig _propertiesConfig; - - 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, tsw, sgdPath) - { - } - - public EssentialsTouchpanelController(string key, string name, Dge100 dge, string projectName, string sgdPath) - : base(key, name, dge, sgdPath) - { - } - /// /// Config constructor /// - public EssentialsTouchpanelController(string key, string name, string type, CrestronTouchpanelPropertiesConfig props, uint id) - : base(key, name, type, props, id) + public EssentialsTouchpanelController(string key, string name, BasicTriListWithSmartObject panel, CrestronTouchpanelPropertiesConfig config) + : base(key, name, panel, config) { } @@ -56,7 +42,7 @@ namespace PepperDash.Essentials Debug.Console(0, this, "Linking TP '{0}' to Room '{1}'", Key, roomKey); - var mainDriver = new EssentialsPanelMainInterfaceDriver(Panel, _propertiesConfig); + var mainDriver = new EssentialsPanelMainInterfaceDriver(Panel, _config); // Then the sub drivers // spin up different room drivers depending on room type @@ -65,15 +51,15 @@ namespace PepperDash.Essentials { // Screen Saver Driver - mainDriver.ScreenSaverController = new ScreenSaverController(mainDriver, _propertiesConfig); + mainDriver.ScreenSaverController = new ScreenSaverController(mainDriver, _config); // Header Driver Debug.Console(0, this, "Adding header driver"); - mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, _propertiesConfig); + mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, _config); // AV Driver Debug.Console(0, this, "Adding huddle space AV driver"); - var avDriver = new EssentialsHuddlePanelAvFunctionsDriver(mainDriver, _propertiesConfig); + var avDriver = new EssentialsHuddlePanelAvFunctionsDriver(mainDriver, _config); avDriver.DefaultRoomKey = roomKey; mainDriver.AvDriver = avDriver; avDriver.CurrentRoom = room as IEssentialsHuddleSpaceRoom; @@ -82,7 +68,7 @@ namespace PepperDash.Essentials if (avDriver.CurrentRoom.PropertiesConfig.Environment != null && avDriver.CurrentRoom.PropertiesConfig.Environment.DeviceKeys.Count > 0) { Debug.Console(0, this, "Adding environment driver"); - mainDriver.EnvironmentDriver = new EssentialsEnvironmentDriver(mainDriver, _propertiesConfig); + mainDriver.EnvironmentDriver = new EssentialsEnvironmentDriver(mainDriver, _config); mainDriver.EnvironmentDriver.GetDevicesFromConfig(avDriver.CurrentRoom.PropertiesConfig.Environment); } @@ -111,13 +97,13 @@ namespace PepperDash.Essentials Debug.Console(0, this, "Adding huddle space VTC AV driver"); // Screen Saver Driver - mainDriver.ScreenSaverController = new ScreenSaverController(mainDriver, _propertiesConfig); + mainDriver.ScreenSaverController = new ScreenSaverController(mainDriver, _config); // Header Driver - mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, _propertiesConfig); + mainDriver.HeaderDriver = new EssentialsHeaderDriver(mainDriver, _config); // AV Driver - var avDriver = new EssentialsHuddleVtc1PanelAvFunctionsDriver(mainDriver, _propertiesConfig); + var avDriver = new EssentialsHuddleVtc1PanelAvFunctionsDriver(mainDriver, _config); var codecDriver = new PepperDash.Essentials.UIDrivers.VC.EssentialsVideoCodecUiDriver(Panel, avDriver, (room as IEssentialsHuddleVtc1Room).VideoCodec, mainDriver.HeaderDriver); @@ -130,7 +116,7 @@ namespace PepperDash.Essentials if (avDriver.CurrentRoom.PropertiesConfig.Environment != null && avDriver.CurrentRoom.PropertiesConfig.Environment.DeviceKeys.Count > 0) { Debug.Console(0, this, "Adding environment driver"); - mainDriver.EnvironmentDriver = new EssentialsEnvironmentDriver(mainDriver, _propertiesConfig); + mainDriver.EnvironmentDriver = new EssentialsEnvironmentDriver(mainDriver, _config); mainDriver.EnvironmentDriver.GetDevicesFromConfig(avDriver.CurrentRoom.PropertiesConfig.Environment); } @@ -229,13 +215,69 @@ namespace PepperDash.Essentials public override EssentialsDevice BuildDevice(DeviceConfig dc) { var comm = CommFactory.GetControlPropertiesConfig(dc); - var props = Newtonsoft.Json.JsonConvert.DeserializeObject(dc.Properties.ToString()); + var props = JsonConvert.DeserializeObject(dc.Properties.ToString()); + + var panel = GetPanelForType(dc.Type, comm.IpIdInt, props.ProjectName); Debug.Console(1, "Factory Attempting to create new EssentialsTouchpanelController"); - var panelController = new EssentialsTouchpanelController(dc.Key, dc.Name, dc.Type, props, comm.IpIdInt); + var panelController = new EssentialsTouchpanelController(dc.Key, dc.Name, panel, props); return panelController; } + + private BasicTriListWithSmartObject GetPanelForType(string type, uint id, string projectName) + { + type = type.ToLower(); + try + { + if (type == "crestronapp") + { + var app = new CrestronApp(id, Global.ControlSystem); + app.ParameterProjectName.Value = projectName; + return app; + } + else if (type == "xpanel") + return new XpanelForSmartGraphics(id, Global.ControlSystem); + else if (type == "tsw550") + return new Tsw550(id, Global.ControlSystem); + else if (type == "tsw552") + return new Tsw552(id, Global.ControlSystem); + else if (type == "tsw560") + return new Tsw560(id, Global.ControlSystem); + else if (type == "tsw750") + return new Tsw750(id, Global.ControlSystem); + else if (type == "tsw752") + return new Tsw752(id, Global.ControlSystem); + else if (type == "tsw760") + return new Tsw760(id, Global.ControlSystem); + else if (type == "tsw1050") + return new Tsw1050(id, Global.ControlSystem); + else if (type == "tsw1052") + return new Tsw1052(id, Global.ControlSystem); + else if (type == "tsw1060") + return new Tsw1060(id, Global.ControlSystem); + else if (type == "tsw570") + return new Tsw570(id, Global.ControlSystem); + else if (type == "tsw770") + return new Tsw770(id, Global.ControlSystem); + else if (type == "ts770") + return new Ts770(id, Global.ControlSystem); + else if (type == "tsw1070") + return new Tsw1070(id, Global.ControlSystem); + else if (type == "ts1070") + return new Ts1070(id, Global.ControlSystem); + else + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW controller with type '{0}'", type); + return null; + } + } + catch (Exception e) + { + Debug.Console(0, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW base class. Panel will not function: {0}", e.Message); + return null; + } + } } } \ No newline at end of file diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs index 01409cf4..806431ec 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs @@ -28,49 +28,9 @@ namespace PepperDash.Essentials.Core.UI protected TouchpanelBase(string key, string name, Tswx52ButtonVoiceControl tsw, string sgdPath) :base(key, name) { - Panel = tsw; - //moving loading of SGD to preactivation action...should make creation quicker - AddPreActivationAction(() => { - if(!string.IsNullOrEmpty(sgdPath)) - { - Debug.Console(1, this, "Loading sgd file from {0}", sgdPath); - Panel.LoadSmartObjects(sgdPath); - return; - } - - Debug.Console(1, this, "No SGD file path defined"); - }); - - Panel.SigChange += Panel_SigChange; } - /// - /// Constructor for use with DGE panels. This constructor attempts to load the provided SGD file from the provided SGD path and subscribes to the - /// `SigChange` event for the provided DGE. - /// - /// Essentials Device Key - /// Essentials Device Name - /// Provided DGE - /// Path to SGD file - protected TouchpanelBase(string key, string name, Dge100 dge, string sgdPath):base(key, name) - { - Panel = dge; - - AddPreActivationAction(() => - { - if (!string.IsNullOrEmpty(sgdPath)) - { - Debug.Console(1, this, "Loading sgd file from {0}", sgdPath); - Panel.LoadSmartObjects(sgdPath); - return; - } - - Debug.Console(1, this, "No SGD file path defined"); - }); - - Panel.SigChange += Panel_SigChange; - } /// /// Constructor for use with device Factory. A touch panel device will be created based on the provided IP-ID and the @@ -82,14 +42,10 @@ namespace PepperDash.Essentials.Core.UI /// Touchpanel Type to build /// Touchpanel Configuration /// IP-ID to use for touch panel - protected TouchpanelBase(string key, string name, string type, CrestronTouchpanelPropertiesConfig config, uint id) + protected TouchpanelBase(string key, string name, BasicTriListWithSmartObject panel, CrestronTouchpanelPropertiesConfig config) :base(key, name) - { - var panel = GetPanelForType(type, id); - if(panel != null) - { - Panel = panel; - } + { + Panel = panel; if (Panel is TswFt5ButtonSystem) { @@ -100,7 +56,8 @@ namespace PepperDash.Essentials.Core.UI tsw.ButtonStateChange += Tsw_ButtonStateChange; } - + + _config = config; AddPreActivationAction(() => { if (Panel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) @@ -112,7 +69,7 @@ namespace PepperDash.Essentials.Core.UI { Debug.Console(0, this, "Smart object file '{0}' not present in User folder. Looking for embedded file", sgdName); - sgdName = Global.ApplicationDirectoryPathPrefix + Global.DirectorySeparator + "SGD" + Global.DirectorySeparator + config.SgdFile; + sgdName = Global.ApplicationDirectoryPathPrefix + Global.DirectorySeparator + "SGD" + Global.DirectorySeparator + _config.SgdFile; if (!File.Exists(sgdName)) { @@ -191,60 +148,6 @@ namespace PepperDash.Essentials.Core.UI SetupPanelDrivers(newRoomKey); } - private BasicTriListWithSmartObject GetPanelForType(string type, uint id) - { - type = type.ToLower(); - try - { - if (type == "crestronapp") - { - var app = new CrestronApp(id, Global.ControlSystem); - app.ParameterProjectName.Value = _config.ProjectName; - return app; - } - else if (type == "xpanel") - return new XpanelForSmartGraphics(id, Global.ControlSystem); - else if (type == "tsw550") - return new Tsw550(id, Global.ControlSystem); - else if (type == "tsw552") - return new Tsw552(id, Global.ControlSystem); - else if (type == "tsw560") - return new Tsw560(id, Global.ControlSystem); - else if (type == "tsw750") - return new Tsw750(id, Global.ControlSystem); - else if (type == "tsw752") - return new Tsw752(id, Global.ControlSystem); - else if (type == "tsw760") - return new Tsw760(id, Global.ControlSystem); - else if (type == "tsw1050") - return new Tsw1050(id, Global.ControlSystem); - else if (type == "tsw1052") - return new Tsw1052(id, Global.ControlSystem); - else if (type == "tsw1060") - return new Tsw1060(id, Global.ControlSystem); - else if (type == "tsw570") - return new Tsw570(id, Global.ControlSystem); - else if (type == "tsw770") - return new Tsw770(id, Global.ControlSystem); - else if (type == "ts770") - return new Ts770(id, Global.ControlSystem); - else if (type == "tsw1070") - return new Tsw1070(id, Global.ControlSystem); - else if (type == "ts1070") - return new Ts1070(id, Global.ControlSystem); - else - { - Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW controller with type '{0}'", type); - return null; - } - } - catch (Exception e) - { - Debug.Console(0, this, Debug.ErrorLogLevel.Notice, "WARNING: Cannot create TSW base class. Panel will not function: {0}", e.Message); - return null; - } - } - private void Panel_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args) { if (Debug.Level == 2) From 1b9f16ea744874eea21a2e9fc0ef3a590cc492f1 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 2 Sep 2022 14:44:15 -0600 Subject: [PATCH 3/4] fix: add missing event registration --- .../UI/TouchpanelBase.cs | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs index 806431ec..fbb7cd32 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs @@ -17,21 +17,6 @@ namespace PepperDash.Essentials.Core.UI protected CrestronTouchpanelPropertiesConfig _config; public BasicTriListWithSmartObject Panel { get; private set; } - /// - /// Constructor for pre-created Panel. This constructor attempts to load the SGD file from the provided SGD path and subscribes to the - /// `SigChange` event for the provided panel. - /// - /// Essentials Device Key - /// Essentials Device Name - /// Provided TSW Panel - /// Path to SGD file - protected TouchpanelBase(string key, string name, Tswx52ButtonVoiceControl tsw, string sgdPath) - :base(key, name) - { - - } - - /// /// Constructor for use with device Factory. A touch panel device will be created based on the provided IP-ID and the /// type of the panel. The SGD File path can be specified using the config property, or a default one located in the program directory if none @@ -45,7 +30,9 @@ namespace PepperDash.Essentials.Core.UI protected TouchpanelBase(string key, string name, BasicTriListWithSmartObject panel, CrestronTouchpanelPropertiesConfig config) :base(key, name) { - Panel = panel; + Panel = panel; + + Panel.SigChange += Panel_SigChange; if (Panel is TswFt5ButtonSystem) { @@ -116,6 +103,14 @@ namespace PepperDash.Essentials.Core.UI protected abstract void SetupPanelDrivers(string roomKey); + /// + /// Event handler for System Extender Events + /// + /// + /// + protected abstract void ExtenderSystemReservedSigs_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender, SigEventArgs args); + + /// /// /// @@ -167,7 +162,5 @@ namespace PepperDash.Essentials.Core.UI if(uo is Action) (uo as Action)(args.Button.State == eButtonState.Pressed); } - - protected abstract void ExtenderSystemReservedSigs_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender, SigEventArgs args); } } \ No newline at end of file From 9b2611be02040b1f4c7e6a02e96b12e94e056b23 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Fri, 2 Sep 2022 15:00:00 -0600 Subject: [PATCH 4/4] refactor: add error handling for cases where type isn't found --- .../UI/EssentialsTouchpanelController.cs | 5 +++++ .../PepperDashEssentialsBase/UI/TouchpanelBase.cs | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/PepperDashEssentials/UI/EssentialsTouchpanelController.cs b/PepperDashEssentials/UI/EssentialsTouchpanelController.cs index 34d5e11a..67f25f42 100644 --- a/PepperDashEssentials/UI/EssentialsTouchpanelController.cs +++ b/PepperDashEssentials/UI/EssentialsTouchpanelController.cs @@ -219,6 +219,11 @@ namespace PepperDash.Essentials var panel = GetPanelForType(dc.Type, comm.IpIdInt, props.ProjectName); + if (panel == null) + { + Debug.Console(0, "Unable to create Touchpanel for type {0}. Touchpanel Controller WILL NOT function correctly", dc.Type); + } + Debug.Console(1, "Factory Attempting to create new EssentialsTouchpanelController"); var panelController = new EssentialsTouchpanelController(dc.Key, dc.Name, panel, props); diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs index fbb7cd32..36e0342e 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/UI/TouchpanelBase.cs @@ -29,7 +29,14 @@ namespace PepperDash.Essentials.Core.UI /// IP-ID to use for touch panel protected TouchpanelBase(string key, string name, BasicTriListWithSmartObject panel, CrestronTouchpanelPropertiesConfig config) :base(key, name) - { + { + + if (Panel == null) + { + Debug.Console(0, this, "Panel is not valid. Touchpanel class WILL NOT work correctly"); + return; + } + Panel = panel; Panel.SigChange += Panel_SigChange;