Skip to content

Commit

Permalink
feat: adds 4 series solution and implements IHasInputs. Needs to be r…
Browse files Browse the repository at this point in the history
…evisited for correct solution and nuget build
  • Loading branch information
ndorin committed Apr 26, 2024
1 parent c555415 commit 1654c93
Show file tree
Hide file tree
Showing 16 changed files with 2,068 additions and 0 deletions.
206 changes: 206 additions & 0 deletions epi-sony-bravia.4Series/DebugLevels.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
using System;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;

namespace SonyBraviaEpi
{
/// <summary>
/// Has debug levels interface
/// </summary>
public interface IHasDebugLevels
{
// LogLevel enum
// - https://docs.microsoft.com/en-us/javascript/api/@aspnet/signalr/loglevel?view=signalr-js-latest

/// <summary>
/// Trace level (0)
/// </summary>
/// <remarks>
/// Log level for very low severity diagnostic messages.
/// </remarks>
uint TraceLevel { get; set; }

/// <summary>
/// Debug level (1)
/// </summary>
/// <remarks>
/// Log level for low severity diagnostic messages.
/// </remarks>
uint DebugLevel { get; set; }

/// <summary>
/// Error Level (2)
/// </summary>
/// <remarks>
/// Log level for diagnostic messages that indicate a failure in the current operation.
/// </remarks>
uint ErrorLevel { get; set; }

/// <summary>
/// Sets the device debug levels to the value
/// </summary>
/// <param name="value">uint value</param>
void SetDebugLevels(uint value);

/// <summary>
/// Resets the device debug levels to the standard values
/// </summary>
void ResetDebugLevels();


}

/// <summary>
/// Debug level
/// </summary>
static public class DebugLevels
{
private const string ConsoleCommand = "setplugindebuglevel";
private const string ConsoleHelpMessage = "set plugin debug level [deviceKey] [off | on] ([minutes])";
private const string ConsoleHelpMessageExtended = @"SETPLUGINDEBUGLEVEL [{devicekey}] [OFF | ON] [timeOutInMinutes]
{deviceKey} [OFF | ON] [timeOutInMinutes] - Device to set plugin debug level
timeOutInMinutes - Set timeout for plugin debug level. Default is 15 minutes
";
private const long DebugTimerDefaultMs = 90000; // 15-minutes (90,000-ms)

/// <summary>
/// Key of this instance
/// </summary>
public static string Key { get; set; }

/// <summary>
/// Trace level (0)
/// </summary>
/// <remarks>
/// Log level for very low severity diagnostic messages.
/// </remarks>
public static uint TraceLevel { get; private set; }

/// <summary>
/// Debug level (1)
/// </summary>
/// <remarks>
/// Log level for low severity diagnostic messages.
/// </remarks>
public static uint DebugLevel { get; private set; }

/// <summary>
/// Error Level (2)
/// </summary>
/// <remarks>
/// Log level for diagnostic messages that indicate a failure in the current operation.
/// </remarks>
public static uint ErrorLevel { get; private set; }


private static CTimer _debugTimer;
private static bool _timerActive;

private static void ResetDebugLevels()
{
CrestronConsole.ConsoleCommandResponse(@"SETPLUGINDEBUGLEVEL level defaults set");
TraceLevel = Convert.ToUInt16(Debug.ErrorLogLevel.Error);
DebugLevel = Convert.ToUInt16(Debug.ErrorLogLevel.Warning);
ErrorLevel = Convert.ToUInt16(Debug.ErrorLogLevel.Notice);
}

private static void SetDebugLevels(uint value)
{
if (value > 2)
{
CrestronConsole.ConsoleCommandResponse(@"SETPLUGINDEBUGLEVEL level '{0}' invalid", value);
return;
}

CrestronConsole.ConsoleCommandResponse(@"SETPLUGINDEBUGLEVEL level '{0}' set", value);

TraceLevel = value;
DebugLevel = value;
ErrorLevel = value;
}

/// <summary>
/// Constructor
/// </summary>
static DebugLevels()
{
// set the default values
ResetDebugLevels();

CrestronConsole.AddNewConsoleCommand(
ProcessConsoleCommand,
ConsoleCommand,
ConsoleHelpMessage,
ConsoleAccessLevelEnum.AccessOperator);
}

/// <summary>
/// Sets the plugin debug level
/// </summary>
/// <example>
/// SETPLUGINDEBUGLEVEL [{devicekey}] [OFF | ON] [timeOutInMinutes]
/// </example>
/// <param name="command">command parameters in string format, not including the command</param>
public static void ProcessConsoleCommand(string command)
{
var data = command.Split(' ');

if (data == null || data.Length == 0 || string.IsNullOrEmpty(data[0]) || data[0].Contains("?"))
{
CrestronConsole.ConsoleCommandResponse(ConsoleHelpMessageExtended);
return;
}

var key = string.IsNullOrEmpty(data[0]) ? string.Empty : data[0];
var param = string.IsNullOrEmpty(data[1]) ? string.Empty : data[1];
var timerLen = (long) ((data.Length < 3 || data[2] == null) ? DebugTimerDefaultMs : TimeSpan.FromMinutes(Convert.ToUInt16(data[2])).TotalMilliseconds);

if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(param))
return;

var device = DeviceManager.GetDeviceForKey(key);
if (device == null)
{
CrestronConsole.ConsoleCommandResponse("SETPLUGINDEBUGLEVEL unable to get device with key: '{0}'", key);
return;
}

switch (param)
{
case "off":
{
if (!_timerActive) break;

_debugTimer.Stop();
if (!_debugTimer.Disposed)
_debugTimer.Dispose();

_timerActive = false;

ResetDebugLevels();

break;
}
case "on":
{
if (_debugTimer == null)
_debugTimer = new CTimer(t => ResetDebugLevels(), timerLen);
else
_debugTimer.Reset();

_timerActive = true;

SetDebugLevels(0);

break;
}
default:
{
CrestronConsole.ConsoleCommandResponse("SETPLUGINDEBUGLEVEL invalid parameter: '{0}'", param);
break;
}
}
}
}
}
21 changes: 21 additions & 0 deletions epi-sony-bravia.4Series/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project>
<PropertyGroup>
<Version>1.0.0-local</Version>
<InformationalVersion>$(Version)</InformationalVersion>
<Authors>PepperDash Technologies</Authors>
<Company>PepperDash Technologies</Company>
<Product>PepperDash Sony Bravia Display</Product>
<Copyright>Copyright © 2023</Copyright>
<RepositoryUrl>https://github.com/PepperDash/epi-mobile-control</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Crestron; 4series</PackageTags>
<PackageOutputPath>../output</PackageOutputPath>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\LICENSE.md" Pack="true" PackagePath=""/>
<None Include="..\README.md" Pack="true" PackagePath=""/>
</ItemGroup>
</Project>
28 changes: 28 additions & 0 deletions epi-sony-bravia.4Series/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project>
<ItemGroup>
<None Include="$(TargetDir)\$(TargetName).$(Version).cpz" Condition="$(ProjectType) == 'Program'">
<Pack>true</Pack>
<PackagePath>content;</PackagePath>
</None>
<None Include="$(PackageOutputPath)\$(TargetName).$(Version).cplz" Condition="$(ProjectType) == 'ProgramLibrary'">
<Pack>true</Pack>
<PackagePath>content;</PackagePath>
</None>
</ItemGroup>
<Target Name="Create CPLZ" AfterTargets="Build; Rebuild" Condition="$(ProjectType) == 'ProgramLibrary'">
<Message Text="Creating CPLZ"></Message>
<MakeDir Directories="$(PackageOutputPath)" Condition="!Exists($(PackageOutputPath))"></MakeDir>
<ZipDirectory SourceDirectory="$(TargetDir)" DestinationFile="$(PackageOutputPath)\$(TargetName).$(Version).cplz" Overwrite="true"/>
</Target>
<Target Name="Clean CPLZ" AfterTargets="AfterClean" Condition="$(ProjectType) == 'ProgramLibrary'">
<Delete Files="$(PackageOutputPath)\$(TargetName).$(Version).cplz"/>
</Target>
<Target Name="Copy CPZ" AfterTargets="SimplSharpPostProcess" Condition="$(ProjectType) == 'Program'">
<Message Text="Copying CPZ"></Message>
<Move SourceFiles="$(TargetDir)$(TargetName).cpz" DestinationFiles="$(TargetDir)$(TargetName).$(Version).cpz" />
<Copy SourceFiles="$(TargetDir)$(TargetName).$(Version).cpz" DestinationFiles="$(PackageOutputPath)\$(TargetName).$(Version).cpz"/>
</Target>
<Target Name="Clean CPZ" AfterTargets="AfterClean" Condition="$(ProjectType) == 'Program'">
<Delete Files="$(PackageOutputPath)\$(TargetName).$(Version).cpz"/>
</Target>
</Project>
36 changes: 36 additions & 0 deletions epi-sony-bravia.4Series/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("epi-sony-bravia.4Series")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("epi-sony-bravia.4Series")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("aac28a64-228b-46e2-85d7-4f20c8107ed2")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 1654c93

Please sign in to comment.