mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-11 19:44:52 +00:00
fix: register panel in post phase rather than activation cycle
This commit is contained in:
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for Touchpanel devices
|
||||
/// </summary>
|
||||
public abstract class TouchpanelBase : EssentialsDevice, IHasBasicTriListWithSmartObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the configuration for the Crestron touchpanel.
|
||||
/// </summary>
|
||||
protected CrestronTouchpanelPropertiesConfig _config;
|
||||
/// <summary>
|
||||
/// Gets or sets the Panel
|
||||
@@ -28,9 +30,8 @@ namespace PepperDash.Essentials.Core.UI
|
||||
/// </summary>
|
||||
/// <param name="key">Essentials Device Key</param>
|
||||
/// <param name="name">Essentials Device Name</param>
|
||||
/// <param name="type">Touchpanel Type to build</param>
|
||||
/// <param name="panel">Crestron Touchpanel Device</param>
|
||||
/// <param name="config">Touchpanel Configuration</param>
|
||||
/// <param name="id">IP-ID to use for touch panel</param>
|
||||
protected TouchpanelBase(string key, string name, BasicTriListWithSmartObject panel, CrestronTouchpanelPropertiesConfig config)
|
||||
: base(key, name)
|
||||
{
|
||||
@@ -57,21 +58,19 @@ namespace PepperDash.Essentials.Core.UI
|
||||
|
||||
_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);
|
||||
|
||||
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<EventArgs>(roomCombiner_RoomCombinationScenarioChanged);
|
||||
roomCombiner.RoomCombinationScenarioChanged += new EventHandler<EventArgs>(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
|
||||
/// <param name="roomKey">Room Key for this panel</param>
|
||||
protected abstract void SetupPanelDrivers(string roomKey);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Event handler for System Extender Events
|
||||
@@ -129,7 +140,7 @@ namespace PepperDash.Essentials.Core.UI
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected virtual void roomCombiner_RoomCombinationScenarioChanged(object sender, EventArgs e)
|
||||
protected virtual void RoomCombiner_RoomCombinationScenarioChanged(object sender, EventArgs e)
|
||||
{
|
||||
var roomCombiner = sender as IEssentialsRoomCombiner;
|
||||
|
||||
@@ -156,9 +167,9 @@ namespace PepperDash.Essentials.Core.UI
|
||||
SetupPanelDrivers(newRoomKey);
|
||||
}
|
||||
|
||||
private void Panel_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args)
|
||||
private void Panel_SigChange(object currentDevice, SigEventArgs args)
|
||||
{
|
||||
Debug.LogMessage(LogEventLevel.Verbose, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
|
||||
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<bool>)
|
||||
(uo as Action<bool>)(args.Sig.BoolValue);
|
||||
|
||||
@@ -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) =>
|
||||
{
|
||||
if (args.Connected)
|
||||
{
|
||||
this.LogVerbose("Connection from IP: {ip}", args.DeviceIpAddress);
|
||||
this.LogInformation("Sending {appUrl} on join 1", AppUrlFeedback.StringValue);
|
||||
Panel.IpInformationChange -= Panel_IpInformationChange;
|
||||
Panel.IpInformationChange += Panel_IpInformationChange;
|
||||
|
||||
var appUrl = GetUrlWithCorrectIp(_appUrl);
|
||||
Panel.StringInput[1].StringValue = appUrl;
|
||||
|
||||
SetAppUrl(appUrl);
|
||||
Panel.OnlineStatusChange -= Panel_OnlineChange;
|
||||
Panel.OnlineStatusChange += Panel_OnlineChange;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LogVerbose("Disconnection from IP: {ip}", args.DeviceIpAddress);
|
||||
}
|
||||
};
|
||||
|
||||
Panel.OnlineStatusChange += (sender, args) =>
|
||||
private void Panel_OnlineChange(GenericBase sender, OnlineOfflineEventArgs args)
|
||||
{
|
||||
this.LogInformation("Sending {appUrl} on join 1", AppUrlFeedback.StringValue);
|
||||
try
|
||||
{
|
||||
if (!args.DeviceOnLine)
|
||||
{
|
||||
this.LogInformation("panel is offline");
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user