diff --git a/src/JsonObjects/ApiObjects.cs b/src/JsonObjects/ApiObjects.cs index 6cb7b43..7cea0e7 100644 --- a/src/JsonObjects/ApiObjects.cs +++ b/src/JsonObjects/ApiObjects.cs @@ -15,6 +15,8 @@ public class DevObject { [JsonProperty("display")] public DisplayObject Display { get; set; } + [JsonProperty("ingest")] + public IngestObject Ingest { get; set; } } public class DisplayObject @@ -22,10 +24,28 @@ public class DisplayObject [JsonProperty("blackout", NullValueHandling = NullValueHandling.Ignore)] public bool? Blackout { get; set; } - [JsonProperty("redundancy")] + [JsonProperty("brightness", NullValueHandling = NullValueHandling.Ignore)] + public int? Brightness { get; set; } + + [JsonProperty("redundancy", NullValueHandling = NullValueHandling.Ignore)] public Redundancy Redundancy { get; set; } } + public class IngestObject + { + [JsonProperty("testPattern")] + public TestPatternObject TestPattern { get; set; } + } + + + public class TestPatternObject + { + [JsonProperty("enabled")] + public bool Enabled { get; set; } + [JsonProperty("type")] + public string Type { get; set; } + } + public class Redundancy { [JsonProperty("state")] diff --git a/src/MegapixelHelioBridgeJoinMap.cs b/src/MegapixelHelioBridgeJoinMap.cs index 2862715..2b154e3 100644 --- a/src/MegapixelHelioBridgeJoinMap.cs +++ b/src/MegapixelHelioBridgeJoinMap.cs @@ -66,6 +66,78 @@ public class MegapixelHeliosBridgeJoinMap : JoinMapBaseAdvanced JoinType = eJoinType.Digital }); + [JoinName("TestPatternOn")] + public JoinDataComplete TestPatternOn = new JoinDataComplete( + new JoinData + { + JoinNumber = 31, + JoinSpan = 1 + }, + new JoinMetadata + { + Description = "Test Pattern On set & get", + JoinCapabilities = eJoinCapabilities.ToFromSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("TestPatternOff")] + public JoinDataComplete TestPatternOff = new JoinDataComplete( + new JoinData + { + JoinNumber = 32, + JoinSpan = 1 + }, + new JoinMetadata + { + Description = "Test Pattern Off set & get", + JoinCapabilities = eJoinCapabilities.ToFromSIMPL, + JoinType = eJoinType.Digital + }); + + + + [JoinName("BrightnessHigh")] + public JoinDataComplete BrightnessHigh = new JoinDataComplete( + new JoinData + { + JoinNumber = 33, + JoinSpan = 1 + }, + new JoinMetadata + { + Description = "Set Brightness High", + JoinCapabilities = eJoinCapabilities.ToFromSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("BrightnessMedium")] + public JoinDataComplete BrightnessMedium = new JoinDataComplete( + new JoinData + { + JoinNumber = 34, + JoinSpan = 1 + }, + new JoinMetadata + { + Description = "Set Brightness Medium", + JoinCapabilities = eJoinCapabilities.ToFromSIMPL, + JoinType = eJoinType.Digital + }); + + [JoinName("BrightnessLow")] + public JoinDataComplete BrightnessLow = new JoinDataComplete( + new JoinData + { + JoinNumber = 35, + JoinSpan = 1 + }, + new JoinMetadata + { + Description = "Set Brightness Low", + JoinCapabilities = eJoinCapabilities.ToFromSIMPL, + JoinType = eJoinType.Digital + }); + [JoinName("IsOnline")] public JoinDataComplete IsOnline = new JoinDataComplete( @@ -114,6 +186,20 @@ public class MegapixelHeliosBridgeJoinMap : JoinMapBaseAdvanced JoinType = eJoinType.Analog }); + [JoinName("Brightness")] + public JoinDataComplete Brightness = new JoinDataComplete( + new JoinData + { + JoinNumber = 33, + JoinSpan = 1 + }, + new JoinMetadata + { + Description = "Set Brightness", + JoinCapabilities = eJoinCapabilities.ToFromSIMPL, + JoinType = eJoinType.Analog + }); + #endregion diff --git a/src/MegapixelHeliosController.cs b/src/MegapixelHeliosController.cs index ba66626..98d5828 100644 --- a/src/MegapixelHeliosController.cs +++ b/src/MegapixelHeliosController.cs @@ -4,6 +4,7 @@ using Crestron.SimplSharpPro.DeviceSupport; using MegapixelHelios.GenericClient; using MegapixelHelios.JsonObjects; +using MegapixelHelios.Parameters; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using PepperDash.Core; @@ -86,6 +87,35 @@ public bool PowerIsOn public BoolFeedback PowerIsOnFeedback { get; set; } + private bool _testPatternIsOn; + public bool TestPatternIsOn + { + get { return _testPatternIsOn; } + set + { + if (_testPatternIsOn == value) return; + _testPatternIsOn = value; + TestPatternIsOnFeedback.FireUpdate(); + } + } + + public BoolFeedback TestPatternIsOnFeedback { get; set; } + + + private int _brightness; + public int Brightness + { + get { return _brightness; } + set + { + if (_brightness == value) return; + _brightness = value; + BrightnessFeedback.FireUpdate(); + } + } + + public IntFeedback BrightnessFeedback { get; set; } + private int _currentPresetId; public int CurrentPresetId @@ -130,8 +160,24 @@ public bool RedundancyOnMain public BoolFeedback RedundancyOnMainFeedback { get; set; } + private List _presets; + + private CTimer _pollTimer; + private bool _isOnline; + public bool IsOnline + { + get { return _isOnline; } + set + { + _isOnline = value; + IsOnlineFeedback.FireUpdate(); + } + } + + public BoolFeedback IsOnlineFeedback; + /// /// Reports online feedback through the bridge @@ -178,15 +224,26 @@ public MegapixelHeliosController(string key, string name, MegapixelHeliosPropert //OnlineFeedback = new BoolFeedback(() => _commsMonitor.IsOnline); //StatusFeedback = new IntFeedback(() => (int)_commsMonitor.Status); + BrightnessLevel.High = propertiesConfig.Brightness.High; + BrightnessLevel.Medium = propertiesConfig.Brightness.Medium; + BrightnessLevel.Low = propertiesConfig.Brightness.Low; + PowerIsOnFeedback = new BoolFeedback(() => PowerIsOn); CurrentPresetIdFeedback = new IntFeedback(() => CurrentPresetId); CurrentPresetNameFeedback = new StringFeedback(() => CurrentPresetName); + TestPatternIsOnFeedback = new BoolFeedback(() => TestPatternIsOn); + BrightnessFeedback = new IntFeedback(() => Brightness); + IsOnlineFeedback = new BoolFeedback(() => IsOnline); + + ResponseCodeFeedback = new IntFeedback(() => ResponseCode); ResponseContentFeedback = new StringFeedback(() => ResponseContent); ResponseErrorFeedback = new StringFeedback(() => ResponseError); RedundancyOnMainFeedback = new BoolFeedback(() => RedundancyOnMain); + + _presets = propertiesConfig.Presets; } /// @@ -213,6 +270,10 @@ private void UpdateFeedbacks() CurrentPresetIdFeedback.FireUpdate(); CurrentPresetNameFeedback.FireUpdate(); + BrightnessFeedback.FireUpdate(); + TestPatternIsOnFeedback.FireUpdate(); + IsOnlineFeedback.FireUpdate(); + ResponseCodeFeedback.FireUpdate(); ResponseContentFeedback.FireUpdate(); ResponseErrorFeedback.FireUpdate(); @@ -258,6 +319,15 @@ public override void LinkToApi(BasicTriList trilist, uint joinStart, string join trilist.SetSigTrueAction(joinMap.PowerOn.JoinNumber, PowerOn); trilist.SetSigTrueAction(joinMap.PowerOff.JoinNumber, PowerOff); + trilist.SetSigTrueAction(joinMap.TestPatternOn.JoinNumber, TestPatternOn); + trilist.SetSigTrueAction(joinMap.TestPatternOff.JoinNumber, TestPatternOff); + + trilist.SetSigTrueAction(joinMap.BrightnessHigh.JoinNumber, () => SetBrightness(BrightnessLevel.High)); + trilist.SetSigTrueAction(joinMap.BrightnessMedium.JoinNumber, () => SetBrightness(BrightnessLevel.Medium)); + trilist.SetSigTrueAction(joinMap.BrightnessLow.JoinNumber, () => SetBrightness(BrightnessLevel.Low)); + + trilist.SetUShortSigAction(joinMap.Brightness.JoinNumber, a => SetBrightness(a)); + trilist.SetSigTrueAction(joinMap.SetRedundancyToMain.JoinNumber, SetRedundancyToBackup); trilist.SetSigTrueAction(joinMap.SetRedundancyToBackup.JoinNumber, SetRedundancyToBackup); @@ -270,6 +340,14 @@ public override void LinkToApi(BasicTriList trilist, uint joinStart, string join PowerIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PowerOn.JoinNumber]); PowerIsOnFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PowerOff.JoinNumber]); + IsOnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]); + + TestPatternIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.TestPatternOn.JoinNumber]); + TestPatternIsOnFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.TestPatternOff.JoinNumber]); + + BrightnessFeedback.LinkInputSig(trilist.UShortInput[joinMap.Brightness.JoinNumber]); + + ResponseCodeFeedback.LinkInputSig(trilist.UShortInput[joinMap.ResponseCode.JoinNumber]); ResponseContentFeedback.LinkInputSig(trilist.StringInput[joinMap.ResponseContent.JoinNumber]); @@ -372,16 +450,36 @@ private void OnResponseReceived(object sender, GenericClientResponseEventArgs ar var feedback = JsonConvert.DeserializeObject(ResponseContent); - if (feedback.Dev.Display.Blackout != null) + if (feedback.Dev.Display != null) { - PowerIsOn = (bool)feedback.Dev.Display.Blackout; + + if (feedback.Dev.Display.Blackout != null) + { + PowerIsOn = (bool)feedback.Dev.Display.Blackout; + } + + if (feedback.Dev.Display.Brightness != null) + { + Brightness = (int)feedback.Dev.Display.Brightness; + } + + if (feedback.Dev.Display.Redundancy != null) + { + RedundancyOnMain = feedback.Dev.Display.Redundancy.State == eRedundancyState.main; + } + } - if (feedback.Dev.Display.Redundancy != null) + if (feedback.Dev.Ingest != null) { - RedundancyOnMain = feedback.Dev.Display.Redundancy.State == eRedundancyState.main; + if (feedback.Dev.Ingest.TestPattern != null) + { + TestPatternIsOn = feedback.Dev.Ingest.TestPattern.Enabled; + } } + + //ProcessJToken(jToken, "dev.display.blackout"); //ProcessJToken(jToken, "presetName"); } @@ -461,9 +559,7 @@ public void Poll() { // TODO [ ] Update Poll method as needed for the plugin being developed // Example: _client.SendRequest(REQUEST_TYPE, REQUEST_PATH, REQUEST_CONTENT); - GetRedunancyState(); - - + GetRedunancyState(); } @@ -474,7 +570,7 @@ public void GetRedunancyState() public void SetRedundancyToMain() { - var content = new RootDevObject() + var content = new RootDevObject { Dev = { @@ -493,7 +589,7 @@ public void SetRedundancyToMain() public void SetRedundancyToBackup() { - var content = new RootDevObject() + var content = new RootDevObject { Dev = { @@ -574,6 +670,115 @@ public void PowerOff() _client.SendRequest("PATCH", "/api/v1/public", content); } + /// + /// Brightiness (Brightness: 50) + /// + /// + /// requestType: PATCH + /// path: "/api/v1/public" + /// content: { "dev": { "display": { "brightness": 50 } } } + /// + public void SetBrightness(ushort brightness) + { + if (brightness <= 0 || brightness >= 100) + { + Debug.Console(MegapixelHeliosDebug.Notice, "SetBrightness: Value sent {0} out of range", brightness); + return; + } + + var jsonObject = new RootDevObject + { + Dev = new DevObject + { + Display = new DisplayObject + { + Brightness = (int)brightness + } + } + }; + + var content = JsonConvert.SerializeObject(jsonObject); + if (string.IsNullOrEmpty(content)) + { + Debug.Console(MegapixelHeliosDebug.Notice, "SetBrightness: failed to serialzie request content"); + return; + } + + Debug.Console(MegapixelHeliosDebug.Trace, this, "SetBrightness: content-'{0}'", content); + _client.SendRequest("PATCH", "/api/v1/public", content); + } + + /// + /// Test Pattern On (enable: true) - do not invoke pattern type + /// + /// + /// requestType: PATCH + /// path: "/api/v1/public" + /// content: { "dev": { "ingest": { "testPattern": { "enabled": true } } } } + /// + public void TestPatternOn() + { + var jsonObject = new RootDevObject + { + Dev = new DevObject + { + Ingest = new IngestObject + { + TestPattern = new TestPatternObject + { + Enabled = true + } + } + } + }; + + var content = JsonConvert.SerializeObject(jsonObject); + if (string.IsNullOrEmpty(content)) + { + Debug.Console(MegapixelHeliosDebug.Notice, "TestPatternEnable: failed to serialzie request content"); + return; + } + + Debug.Console(MegapixelHeliosDebug.Trace, this, "TestPatternEnable: content-'{0}'", content); + _client.SendRequest("PATCH", "/api/v1/public", content); + } + + + /// + /// Test Pattern Off (enable: false) + /// + /// + /// requestType: PATCH + /// path: "/api/v1/public" + /// content: { "dev": { "ingest": { "testPattern": { "enabled": false } } } } + /// + public void TestPatternOff() + { + var jsonObject = new RootDevObject + { + Dev = new DevObject + { + Ingest = new IngestObject + { + TestPattern = new TestPatternObject + { + Enabled = false + } + } + } + }; + + var content = JsonConvert.SerializeObject(jsonObject); + if (string.IsNullOrEmpty(content)) + { + Debug.Console(MegapixelHeliosDebug.Notice, "TestPatternEnable: failed to serialzie request content"); + return; + } + + Debug.Console(MegapixelHeliosDebug.Trace, this, "TestPatternEnable: content-'{0}'", content); + _client.SendRequest("PATCH", "/api/v1/public", content); + } + /// /// Queries device for preset list /// diff --git a/src/MegapixelHeliosPropertiesConfig.cs b/src/MegapixelHeliosPropertiesConfig.cs index eb50d78..6cc41a3 100644 --- a/src/MegapixelHeliosPropertiesConfig.cs +++ b/src/MegapixelHeliosPropertiesConfig.cs @@ -1,45 +1,64 @@ using Newtonsoft.Json; using PepperDash.Essentials.Core; +using System.Collections.Generic; namespace MegapixelHelios { - /// - /// Plugin device configuration object - /// - [ConfigSnippet("\"properties\":{}")] - public class MegapixelHeliosPropertiesConfig - { - /// - /// JSON control object - /// - [JsonProperty("control")] - public EssentialsControlPropertiesConfig Control { get; set; } - - /// - /// Constuctor - /// - public MegapixelHeliosPropertiesConfig() - { - } - } - - /// - /// Preset configuration object - /// - public class MegaPixelHeliosPresetConfig - { - [JsonProperty("label")] - public string Label { get; set; } - - [JsonProperty("presetName", NullValueHandling = NullValueHandling.Ignore)] - public string PresetName { get; set; } - - [JsonProperty("presetId", NullValueHandling = NullValueHandling.Ignore)] - public uint PreseId { get; set; } - - public override string ToString() - { - return JsonConvert.SerializeObject(this); - } - } + /// + /// Plugin device configuration object + /// + [ConfigSnippet("\"properties\":{}")] + public class MegapixelHeliosPropertiesConfig + { + /// + /// JSON control object + /// + [JsonProperty("control")] + public EssentialsControlPropertiesConfig Control { get; set; } + + /// + /// Constuctor + /// + public MegapixelHeliosPropertiesConfig() + { + Presets = new List(); + } + + [JsonProperty("brightness")] + public BrightnessConfigObject Brightness { get; set; } + + [JsonProperty("presets")] + public List Presets { get; set; } + } + + /// + /// Preset configuration object + /// + public class MegaPixelHeliosPresetConfig + { + [JsonProperty("label")] + public string Label { get; set; } + + [JsonProperty("presetName", NullValueHandling = NullValueHandling.Ignore)] + public string PresetName { get; set; } + + [JsonProperty("presetId", NullValueHandling = NullValueHandling.Ignore)] + public uint PreseId { get; set; } + + public override string ToString() + { + return JsonConvert.SerializeObject(this); + } + } + + public class BrightnessConfigObject + { + [JsonProperty("high")] + public ushort High { get; set; } + [JsonProperty("medium")] + public ushort Medium { get; set; } + [JsonProperty("low")] + public ushort Low { get; set; } + + } } \ No newline at end of file diff --git a/src/Parameters/Parameters.cs b/src/Parameters/Parameters.cs new file mode 100644 index 0000000..9de76c5 --- /dev/null +++ b/src/Parameters/Parameters.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +namespace MegapixelHelios.Parameters +{ + public class TestPatterns + { + Dictionary Parameters = new Dictionary(){ + { "colorbars", "colorBars" } + }; + } + + public static class BrightnessLevel + { + public static ushort High { get; set; } + public static ushort Medium { get; set; } + public static ushort Low { get; set; } + + static BrightnessLevel() + { + High = 75; + Medium = 50; + Low = 20; + } + } +} \ No newline at end of file diff --git a/src/epi-megapixel-helios.csproj b/src/epi-megapixel-helios.csproj index 42268e8..47f3732 100644 --- a/src/epi-megapixel-helios.csproj +++ b/src/epi-megapixel-helios.csproj @@ -108,6 +108,7 @@ +