From c4cf8f13e918323b62cc945b8dea2e9515b0dd58 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Thu, 30 Oct 2025 15:56:28 -0500 Subject: [PATCH] fix: register panel in post phase rather than activation cycle --- .../UI/TouchpanelBase.cs | 95 +++++++++++-------- .../MobileControlTouchpanelController.cs | 93 +++++++++++++----- 2 files changed, 122 insertions(+), 66 deletions(-) diff --git a/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs b/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs index 3ffed9fc..8d3f0b1d 100644 --- a/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs +++ b/src/PepperDash.Essentials.Core/UI/TouchpanelBase.cs @@ -1,20 +1,22 @@ 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; +using Crestron.SimplSharpPro.DeviceSupport; +using PepperDash.Core; +using PepperDash.Core.Logging; using Serilog.Events; namespace PepperDash.Essentials.Core.UI { - public abstract class TouchpanelBase: EssentialsDevice, IHasBasicTriListWithSmartObject + /// + /// Base class for Touchpanel devices + /// + public abstract class TouchpanelBase : EssentialsDevice, IHasBasicTriListWithSmartObject { + /// + /// Gets or sets the configuration for the Crestron touchpanel. + /// protected CrestronTouchpanelPropertiesConfig _config; /// /// Gets or sets the Panel @@ -27,12 +29,11 @@ namespace PepperDash.Essentials.Core.UI /// is provided. /// /// Essentials Device Key - /// Essentials Device Name - /// Touchpanel Type to build - /// Touchpanel Configuration - /// IP-ID to use for touch panel + /// Essentials Device Name + /// Crestron Touchpanel Device + /// Touchpanel Configuration protected TouchpanelBase(string key, string name, BasicTriListWithSmartObject panel, CrestronTouchpanelPropertiesConfig config) - :base(key, name) + : base(key, name) { if (panel == null) @@ -55,23 +56,21 @@ namespace PepperDash.Essentials.Core.UI tsw.ButtonStateChange += Tsw_ButtonStateChange; } - _config = config; - - AddPreActivationAction(() => { - if (Panel.Register() != eDeviceRegistrationUnRegistrationResponse.Success) - Debug.LogMessage(LogEventLevel.Information, this, "WARNING: Registration failed. Continuing, but panel may not function: {0}", Panel.RegistrationFailureReason); + _config = config; + AddPreActivationAction(() => + { // Give up cleanly if SGD is not present. var sgdName = Global.FilePathPrefix + "sgd" + Global.DirectorySeparator + _config.SgdFile; if (!File.Exists(sgdName)) { - Debug.LogMessage(LogEventLevel.Information, this, "Smart object file '{0}' not present in User folder. Looking for embedded file", sgdName); + this.LogInformation("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.LogMessage(LogEventLevel.Information, this, "Unable to find SGD file '{0}' in User sgd or application SGD folder. Exiting touchpanel load.", sgdName); + this.LogWarning("Unable to find SGD file '{0}' in User sgd or application SGD folder. Exiting touchpanel load.", sgdName); return; } } @@ -82,12 +81,11 @@ namespace PepperDash.Essentials.Core.UI 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) + if (DeviceManager.AllDevices.FirstOrDefault((d) => d is IEssentialsRoomCombiner) is IEssentialsRoomCombiner roomCombiner) { // Subscribe to the even - roomCombiner.RoomCombinationScenarioChanged += new EventHandler(roomCombiner_RoomCombinationScenarioChanged); + roomCombiner.RoomCombinationScenarioChanged += new EventHandler(RoomCombiner_RoomCombinationScenarioChanged); // Connect to the initial roomKey if (roomCombiner.CurrentScenario != null) @@ -106,6 +104,11 @@ namespace PepperDash.Essentials.Core.UI // No room combiner, use the default key SetupPanelDrivers(_config.DefaultRoomKey); } + + var panelRegistrationResponse = Panel.Register(); + + if (panelRegistrationResponse != eDeviceRegistrationUnRegistrationResponse.Success) + this.LogInformation("WARNING: Registration failed. Continuing, but panel may not function: {0}", Panel.RegistrationFailureReason); }); } @@ -115,6 +118,14 @@ namespace PepperDash.Essentials.Core.UI /// Room Key for this panel protected abstract void SetupPanelDrivers(string roomKey); + /// + public override void Initialize() + { + base.Initialize(); + + + } + /// /// Event handler for System Extender Events @@ -129,7 +140,7 @@ namespace PepperDash.Essentials.Core.UI /// /// /// - protected virtual void roomCombiner_RoomCombinationScenarioChanged(object sender, EventArgs e) + protected virtual void RoomCombiner_RoomCombinationScenarioChanged(object sender, EventArgs e) { var roomCombiner = sender as IEssentialsRoomCombiner; @@ -156,23 +167,23 @@ namespace PepperDash.Essentials.Core.UI SetupPanelDrivers(newRoomKey); } - private void Panel_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args) - { - Debug.LogMessage(LogEventLevel.Verbose, 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); - } + private void Panel_SigChange(object currentDevice, SigEventArgs args) + { + this.LogVerbose("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); + } } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.cs b/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.cs index c1743d40..5830782d 100644 --- a/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.cs +++ b/src/PepperDash.Essentials.MobileControl/Touchpanel/MobileControlTouchpanelController.cs @@ -252,6 +252,7 @@ namespace PepperDash.Essentials.Touchpanel if (!x70Panel.ExtenderApplicationControlReservedSigs.HideOpenedApplicationFeedback.BoolValue) { x70Panel.ExtenderButtonToolbarReservedSigs.ShowButtonToolbar(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button2On(); } else @@ -294,17 +295,16 @@ namespace PepperDash.Essentials.Touchpanel handler(this, new DeviceInfoEventArgs(DeviceInfo)); }; + x70Panel.ExtenderButtonToolbarReservedSigs.DeviceExtenderSigChange += (o, a) => + { + this.LogVerbose("X70 Button Toolbar Device Extender args: {event}:{sig}:{name}:{type}:{boolValue}:{ushortValue}:{stringValue}", a.Event, a.Sig, a.Sig.Name, a.Sig.Type, a.Sig.BoolValue, a.Sig.UShortValue, a.Sig.StringValue); + }; + x70Panel.ExtenderApplicationControlReservedSigs.Use(); x70Panel.ExtenderZoomRoomAppReservedSigs.Use(); x70Panel.ExtenderEthernetReservedSigs.Use(); x70Panel.ExtenderButtonToolbarReservedSigs.Use(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button1Off(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button3Off(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button4Off(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button5Off(); - x70Panel.ExtenderButtonToolbarReservedSigs.Button6Off(); - return; } @@ -414,34 +414,79 @@ namespace PepperDash.Essentials.Touchpanel McServerUrlFeedback.LinkInputSig(Panel.StringInput[3]); UserCodeFeedback.LinkInputSig(Panel.StringInput[4]); - Panel.IpInformationChange += (sender, args) => + Panel.IpInformationChange -= Panel_IpInformationChange; + Panel.IpInformationChange += Panel_IpInformationChange; + + Panel.OnlineStatusChange -= Panel_OnlineChange; + Panel.OnlineStatusChange += Panel_OnlineChange; + } + + private void Panel_OnlineChange(GenericBase sender, OnlineOfflineEventArgs args) + { + try { - if (args.Connected) + if (!args.DeviceOnLine) { - this.LogVerbose("Connection from IP: {ip}", args.DeviceIpAddress); - this.LogInformation("Sending {appUrl} on join 1", AppUrlFeedback.StringValue); - - var appUrl = GetUrlWithCorrectIp(_appUrl); - Panel.StringInput[1].StringValue = appUrl; - - SetAppUrl(appUrl); + this.LogInformation("panel is offline"); + return; } - else - { - this.LogVerbose("Disconnection from IP: {ip}", args.DeviceIpAddress); - } - }; - Panel.OnlineStatusChange += (sender, args) => - { - this.LogInformation("Sending {appUrl} on join 1", AppUrlFeedback.StringValue); + this.LogDebug("panel is online"); UpdateFeedbacks(); Panel.StringInput[1].StringValue = _appUrl; Panel.StringInput[2].StringValue = QrCodeUrlFeedback.StringValue; Panel.StringInput[3].StringValue = McServerUrlFeedback.StringValue; Panel.StringInput[4].StringValue = UserCodeFeedback.StringValue; - }; + + if (Panel is TswXX70Base x70Panel) + { + this.LogDebug("setting buttons off"); + + x70Panel.ExtenderButtonToolbarReservedSigs.Button1Off(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button3Off(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button4Off(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button5Off(); + x70Panel.ExtenderButtonToolbarReservedSigs.Button6Off(); + } + + SendUrlToPanel(); + } + catch (Exception ex) + { + this.LogError("Exception in panel online: {message}", ex.Message); + this.LogDebug(ex, "Stack Trace: "); + } + } + + private void SendUrlToPanel() + { + var appUrl = GetUrlWithCorrectIp(_appUrl); + + this.LogInformation("Sending {appUrl} on join 1", AppUrlFeedback.StringValue); + + if (Panel.StringInput[1].StringValue == appUrl) + { + this.LogInformation("App URL already set to {appUrl}, no update needed", AppUrlFeedback.StringValue); + return; + } + + Panel.StringInput[1].StringValue = appUrl; + + SetAppUrl(appUrl); + } + + private void Panel_IpInformationChange(GenericBase sender, ConnectedIpEventArgs args) + { + if (args.Connected) + { + this.LogVerbose("Connection from IP: {ip}", args.DeviceIpAddress); + SendUrlToPanel(); + } + else + { + this.LogVerbose("Disconnection from IP: {ip}", args.DeviceIpAddress); + } } ///