Files
Essentials/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs
2019-12-17 10:58:17 -07:00

101 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Essentials.Core.Config;
using Newtonsoft.Json;
namespace PepperDash.Essentials.Core
{
public static class JoinMapHelper
{
/// <summary>
/// Attempts to get the serialized join map from config
/// </summary>
/// <param name="joinMapKey"></param>
/// <returns></returns>
public static string GetJoinMapForDevice(string joinMapKey)
{
if (string.IsNullOrEmpty(joinMapKey))
return null;
var joinMap = ConfigReader.ConfigObject.JoinMaps[joinMapKey];
if (joinMap != null)
{
return joinMap;
}
else
return null;
}
}
public abstract class JoinMapBase
{
/// <summary>
/// Modifies all the join numbers by adding the offset. This should never be called twice
/// </summary>
/// <param name="joinStart"></param>
public abstract void OffsetJoinNumbers(uint joinStart);
public Dictionary<string, JoinMetadata> Joins { get; set; }
}
/// <summary>
/// Read = Provides feedback to SIMPL
/// Write = Responds to sig values from SIMPL
/// </summary>
public enum eJoinCapabilities
{
Read = 1,
Write = 2
}
public enum eJoinType
{
Digital = 1,
Analog = 2,
Serial = 4
}
/// <summary>
/// Data describing the join
/// </summary>
public class JoinMetadata
{
/// <summary>
/// A label for the join to better describe it's usage
/// </summary>
[JsonProperty("label")]
public string Label { get; set; }
/// <summary>
/// Signal type(s)
/// </summary>
[JsonProperty("joinType")]
public eJoinType JoinType { get; set; }
/// <summary>
/// Join number (based on join offset value)
/// </summary>
[JsonProperty("joinNumber")]
public uint JoinNumber { get; set; }
/// <summary>
/// Join range span. If join indicates the start of a range of joins, this indicated the maximum number of joins in the range
/// </summary>
[JsonProperty("joinSpan")]
public uint JoinSpan { get; set; }
/// <summary>
/// Indicates whether the join is read and/or write
/// </summary>
[JsonProperty("joinCapabilities")]
public eJoinCapabilities JoinCapabilities { get; set; }
}
}