Skip to content

Commit

Permalink
feat: add #if wrapper to debug statements
Browse files Browse the repository at this point in the history
Added `#if SERIES4` directives to impelment 4-series
`Debug.LogMessage` while maintaining existing 3-series
`Debug.Console` statements.
  • Loading branch information
jkdevito committed Oct 1, 2024
1 parent c72ad23 commit 9304975
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
59 changes: 51 additions & 8 deletions src/PanasonicProjectorController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Cryptography;
Expand All @@ -8,10 +7,13 @@
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Core.Queues;
using PepperDash.Essentials.Core.Routing;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;

#if SERIES4
using System.Collections.Generic;
using PepperDash.Essentials.Core.DeviceTypeInterfaces;
using TwoWayDisplayBase = PepperDash.Essentials.Devices.Common.Displays.TwoWayDisplayBase;
#else
using PepperDash.Essentials.Core.Routing;
#endif

namespace PepperDash.Essentials.Plugins.Display.Panasonic.Projector
Expand Down Expand Up @@ -76,11 +78,14 @@ public BoolFeedback OnlineFeedback
/// <param name="config"></param>
/// <param name="comms"></param>
public PanasonicProjectorController(string key, string name, PanasonicProjectorConfig config,
IBasicCommunication comms)
IBasicCommunication comms)
: base(key, name)
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"Constructing new {this.Name} instance", this);
#else
Debug.Console(0, this, "Constructing new {0} instance", name);

#endif
_rxQueue = new GenericQueue(String.Format("{0}-rxQueue", Key));
_txQueue = new CrestronQueue<string>(50);

Expand All @@ -96,8 +101,12 @@ public PanasonicProjectorController(string key, string name, PanasonicProjectorC

if (_commandBuilder == null)
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Error, "Command builder not created. Unable to continue. Please correct the configuration to use either 'com' or 'tcpip' as the control method", this);
#else
Debug.Console(0, Debug.ErrorLogLevel.Error,
"Command builder not created. Unable to continue. Please correct the configuration to use either 'com' or 'tcpip' as the control method");
#endif
return;
}

Expand Down Expand Up @@ -136,7 +145,11 @@ public override void Initialize()
}
catch (Exception ex)
{
#if SERIES4
Debug.LogMessage(ex, $"Caught an exception in the poll: {ex.Message}", this);
#else
Debug.Console(1, this, Debug.ErrorLogLevel.Notice, "Caught an exception in the poll:{0}", ex.Message);
#endif
throw;
}
}, null, 50000, 50000);
Expand Down Expand Up @@ -172,9 +185,12 @@ private ICommandBuilder GetCommandBuilder(PanasonicProjectorConfig config)
{
return new IpCommandBuilder();
}

#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"Control method {config.Control.Method} isn't valid for this plugin.", this);
#else
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Control method {0} isn't valid for this plugin.",
config.Control.Method);
#endif
return null;
}

Expand Down Expand Up @@ -217,16 +233,23 @@ private object DequeueAndSend(object notUsed)

if (_txQueue.IsEmpty)
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, $"Queue is empty we're out!", this);
#else
Debug.Console(1, this, "Queue is empty we're out!");
#endif
return null;
}

var cmdToSend = _txQueue.Dequeue(10);

if (String.IsNullOrEmpty(cmdToSend))
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, $"Unable to get command to send", this);
#else
Debug.Console(1, this, "Unable to get command to send");

#endif
}

_currentCommand = cmdToSend;
Expand Down Expand Up @@ -315,7 +338,11 @@ public void SendText(string text)
{

_txQueue.Enqueue(text);
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, $"Queue isn't empty and client isn't connected, connecting...", this);
#else
Debug.Console(1, this, "Queue isn't empty and client isn't connected, connecting...");
#endif
CrestronInvoke.BeginInvoke(_ => _comms.Connect());
}
}
Expand Down Expand Up @@ -346,7 +373,11 @@ public bool Connect

public void Poll()
{
Debug.Console(1, this, "Sending poll...");
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, $"Sending poll...", this);
#else
Debug.Console(1, this, "Sending poll...");
#endif
SendText(_commandBuilder.GetCommand("QPW"));
}

Expand Down Expand Up @@ -406,7 +437,11 @@ public bool PowerIsOn
get { return _powerIsOn; }
set
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, $"Setting PowerIsOn to {value} from {_powerIsOn}", this);
#else
Debug.Console(1, this, "Setting powerIsOn to {0} from {1}", value, _powerIsOn);
#endif

if (value == _powerIsOn)
{
Expand All @@ -425,7 +460,11 @@ protected override Func<bool> PowerIsOnFeedbackFunc
{
return () =>
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, $"Updating PowerIsOnFeedback to {_powerIsOn}", this);
#else
Debug.Console(1, this, "Updating PowerIsOnFeedback to {0}", PowerIsOn);
#endif
return PowerIsOn;
};
}
Expand Down Expand Up @@ -603,7 +642,11 @@ public override void ExecuteSwitch(object selector)

if (handler == null)
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Debug, $"Unable to switch using selector {selector}", this);
#else
Debug.Console(1, this, "Unable to switch using selector {0}", selector);
#endif
return;
}

Expand Down
14 changes: 12 additions & 2 deletions src/PanasonicProjectorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ public PanasonicProjectorFactory()
/// <param name="dc">device configuration</param>
public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"[{dc.Key}] Factory Attempting to create new device from type: {dc.Type}", null, null);
#else
Debug.Console(1, "[{0}] Factory Attempting to create new device from type: {1}", dc.Key, dc.Type);

#endif
// get the plugin device properties configuration object & check for null
var propertiesConfig = dc.Properties.ToObject<PanasonicProjectorConfig>();
if (propertiesConfig == null)
{
#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"[{dc.Key}] Factory: failed to read properties config for {dc.Name}", null, null);
#else
Debug.Console(0, "[{0}] Factory: failed to read properties config for {1}", dc.Key, dc.Name);
#endif
return null;
}

Expand All @@ -45,8 +52,11 @@ public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
return new PanasonicProjectorController(dc.Key, dc.Name, propertiesConfig, comms);
}

#if SERIES4
Debug.LogMessage(Serilog.Events.LogEventLevel.Verbose, $"[{dc.Key}] Factory Notice: No control object present for device {dc.Name}", null, null);
#else
Debug.Console(1, "[{0}] Factory Notice: No control object present for device {1}", dc.Key, dc.Name);
#endif
return null;
}
}
Expand Down

0 comments on commit 9304975

Please sign in to comment.