diff --git a/Essentials Core/PepperDashEssentialsBase/Touchpanels/TriListExtensions.cs b/Essentials Core/PepperDashEssentialsBase/Touchpanels/TriListExtensions.cs index d183abc4..cb6399cb 100644 --- a/Essentials Core/PepperDashEssentialsBase/Touchpanels/TriListExtensions.cs +++ b/Essentials Core/PepperDashEssentialsBase/Touchpanels/TriListExtensions.cs @@ -144,23 +144,47 @@ namespace PepperDash.Essentials.Core sig.UserObject = a; return sig; } - + /// + /// + /// + /// + /// + /// + /// public static UShortOutputSig SetUShortSigAction(this BasicTriList tl, uint sigNum, Action a) { return tl.UShortOutput[sigNum].SetUShortSigAction(a); } + /// + /// + /// + /// + /// + /// public static StringOutputSig SetStringSigAction(this StringOutputSig sig, Action a) { sig.UserObject = a; return sig; } + /// + /// + /// + /// + /// + /// + /// public static StringOutputSig SetStringSigAction(this BasicTriList tl, uint sigNum, Action a) { - return tl.SetStringSigAction(sigNum, a); + return tl.StringOutput[sigNum].SetStringSigAction(a); } + /// + /// + /// + /// + /// public static Sig ClearSigAction(this Sig sig) { sig.UserObject = null; @@ -190,6 +214,27 @@ namespace PepperDash.Essentials.Core tl.BooleanInput[sigNum].BoolValue = value; } + /// + /// Sends an true-false pulse to the sig + /// + /// + /// + public static void PulseBool(this BasicTriList tl, uint sigNum) + { + tl.BooleanInput[sigNum].Pulse(); + } + + /// + /// Sends a timed pulse to the sig + /// + /// + /// + /// + public static void PulseBool(this BasicTriList tl, uint sigNum, int ms) + { + tl.BooleanInput[sigNum].Pulse(ms); + } + /// /// Helper method to set the value of a ushort Sig on TriList /// diff --git a/Essentials/PepperDashEssentials/Config/DeviceFactory.cs b/Essentials/PepperDashEssentials/Config/DeviceFactory.cs index 7a8dfdb9..19fbf925 100644 --- a/Essentials/PepperDashEssentials/Config/DeviceFactory.cs +++ b/Essentials/PepperDashEssentials/Config/DeviceFactory.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Crestron.SimplSharp; using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharpPro; @@ -68,6 +69,12 @@ namespace PepperDash.Essentials return new CotijaSystemController(key, name, props); } + else if (typeName == "cotijaddvc01room") + { + var comm = CommFactory.GetControlPropertiesConfig(dc); + return new PepperDash.Essentials.Room.Cotija.CotijaDdvc01RoomBridge(key, name, comm.IpIdInt); + } + return null; } } diff --git a/Essentials/PepperDashEssentials/ControlSystem.cs b/Essentials/PepperDashEssentials/ControlSystem.cs index 640f1bec..e4b69331 100644 --- a/Essentials/PepperDashEssentials/ControlSystem.cs +++ b/Essentials/PepperDashEssentials/ControlSystem.cs @@ -66,19 +66,7 @@ namespace PepperDash.Essentials if (!ConfigReader.LoadConfig2()) return; - LoadDevices(); - LoadTieLines(); - LoadRooms(); - - try - { - LogoServer = new HttpLogoServer(8080, @"\html\logo"); - } - catch (Exception e) - { - - Debug.Console(0, "WARNING: Logo server cannot be started on port 8080:\n{0}", e); - } + Load(); DeviceManager.ActivateAll(); Debug.Console(0, "Essentials load complete\r" + @@ -87,14 +75,14 @@ namespace PepperDash.Essentials else { Debug.Console(0, - "------------------------------------------------\n" + - "------------------------------------------------\n" + - "------------------------------------------------\n" + - "Essentials file structure setup completed.\n" + - "Please load config, sgd and ir files and\n" + - "restart program.\n" + - "------------------------------------------------\n" + - "------------------------------------------------\n" + + "------------------------------------------------\r" + + "------------------------------------------------\r" + + "------------------------------------------------\r" + + "Essentials file structure setup completed.\r" + + "Please load config, sgd and ir files and\r" + + "restart program.\r" + + "------------------------------------------------\r" + + "------------------------------------------------\r" + "------------------------------------------------"); } } @@ -150,6 +138,17 @@ namespace PepperDash.Essentials Debug.Console(0, "Tear down COMPLETE"); } + /// + /// + /// + void Load() + { + LoadDevices(); + LoadTieLines(); + LoadRooms(); + LoadLogoServer(); + } + /// /// Reads all devices from config and adds them to DeviceManager @@ -242,5 +241,21 @@ namespace PepperDash.Essentials Debug.Console(0, "WARNING: Cannot create room from config, key '{0}'", roomConfig.Key); } } + + /// + /// Fires up a logo server if not already running + /// + void LoadLogoServer() + { + + try + { + LogoServer = new HttpLogoServer(8080, @"\html\logo"); + } + catch (Exception) + { + Debug.Console(0, "NOTICE: Logo server cannot be started. Likely already running in another program"); + } + } } } diff --git a/Essentials/PepperDashEssentials/PepperDashEssentials.csproj b/Essentials/PepperDashEssentials/PepperDashEssentials.csproj index a0736c23..397eb1b2 100644 --- a/Essentials/PepperDashEssentials/PepperDashEssentials.csproj +++ b/Essentials/PepperDashEssentials/PepperDashEssentials.csproj @@ -139,6 +139,7 @@ + diff --git a/Essentials/PepperDashEssentials/Room/Cotija/CotijaConfig.cs b/Essentials/PepperDashEssentials/Room/Cotija/CotijaConfig.cs index 4bbe068e..1d4e9718 100644 --- a/Essentials/PepperDashEssentials/Room/Cotija/CotijaConfig.cs +++ b/Essentials/PepperDashEssentials/Room/Cotija/CotijaConfig.cs @@ -9,9 +9,22 @@ using Newtonsoft.Json; namespace PepperDash.Essentials { - public class CotijaConfig : DeviceConfig + + /// + /// + /// + public class CotijaConfig { [JsonProperty("serverUrl")] public string ServerUrl { get; set; } } + + /// + /// + /// + public class CotijaDdvc01RoomBridgePropertiesConfig + { + [JsonProperty("eiscId")] + public string EiscId { get; set; } + } } \ No newline at end of file diff --git a/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs b/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs index a335bd20..c0566b52 100644 --- a/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs +++ b/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs @@ -211,7 +211,7 @@ namespace PepperDash.Essentials /// /// room from which the message originates /// object to be serialized and sent in post body - public void PostToServer(EssentialsRoomBase room, JObject o) + public void PostToServer(JObject o) { CrestronInvoke.BeginInvoke(oo => { @@ -258,7 +258,7 @@ namespace PepperDash.Essentials // Try again. This client is hosed. NeedNewClient = true; PostLockEvent.Set(); - PostToServer(room, o); + PostToServer(o); } }); } diff --git a/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaDdvc01RoomBridge.cs b/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaDdvc01RoomBridge.cs new file mode 100644 index 00000000..9afcb306 --- /dev/null +++ b/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaDdvc01RoomBridge.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharpPro.EthernetCommunication; + +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +using PepperDash.Core; +using PepperDash.Essentials.Core; + +namespace PepperDash.Essentials.Room.Cotija +{ + public class CotijaDdvc01RoomBridge : Device + { + public class BoolJoin + { + /// + /// 1 + /// + public const uint GetStatus = 1; + /// + /// 2 + /// + public const uint RoomIsOn = 2; + /// + /// 3 + /// + public const uint DefaultSourcePress = 3; + /// + /// 4 + /// + public const uint MasterVolumeIsMuted = 4; + /// + /// 4 + /// + public const uint MasterVolumeMuteToggle = 4; + /// + /// 21 + /// + public const uint ShutdownStart = 21; + /// + /// 22 + /// + public const uint ShutdownEnd = 22; + /// + /// 23 + /// + public const uint ShutdownCancel = 23; + } + + public class UshortJoin + { + /// + /// + /// + public const uint MasterVolumeLevel = 4; + } + + public class StringJoin + { + /// + /// + /// + public const uint SetSource = 3; + } + + + public ThreeSeriesTcpIpEthernetIntersystemCommunications EISC { get; private set; } + + CotijaSystemController Parent; + + public CotijaDdvc01RoomBridge(string key, string name, uint ipId) + : base(key, name) + { + Key = key; + try + { + EISC = new ThreeSeriesTcpIpEthernetIntersystemCommunications(ipId, "127.0.0.2", Global.ControlSystem); + var reg = EISC.Register(); + if (reg != Crestron.SimplSharpPro.eDeviceRegistrationUnRegistrationResponse.Success) + Debug.Console(0, this, "Cannot connect EISC at IPID {0}: \r{1}", ipId, reg); + } + catch (Exception) + { + throw; + } + } + + /// + /// Finish wiring up everything after all devices are created + /// + /// + public override bool CustomActivate() + { + + Parent = DeviceManager.AllDevices.FirstOrDefault(d => d is CotijaSystemController) as CotijaSystemController; + if (Parent == null) + { + Debug.Console(0, this, "ERROR: Cannot build CotijaDdvc01RoomBridge. System controller not present"); + return false; + } + + SetupFunctions(); + SetupFeedbacks(); + return base.CustomActivate(); + } + + + /// + /// Setup the actions to take place on various incoming API calls + /// + void SetupFunctions() + { + Parent.AddAction(@"/room/room1/status", new Action(() => + EISC.PulseBool(BoolJoin.GetStatus))); + Parent.AddAction(@"/room/room1/source", new Action(c => + EISC.SetString(StringJoin.SetSource, c.SourceListItem))); + Parent.AddAction(@"/room/room1/defaultsource", new Action(() => + EISC.PulseBool(BoolJoin.DefaultSourcePress))); + + Parent.AddAction(@"/room/room1/masterVolumeLevel", new Action(u => + EISC.SetUshort(UshortJoin.MasterVolumeLevel, u))); + Parent.AddAction(@"/room/room1/masterVolumeMuteToggle", new Action(() => + EISC.PulseBool(BoolJoin.MasterVolumeIsMuted))); + + Parent.AddAction(@"/room/room1/shutdownStart", new Action(() => + EISC.PulseBool(BoolJoin.ShutdownStart))); + Parent.AddAction(@"/room/room1/shutdownEnd", new Action(() => + EISC.PulseBool(BoolJoin.ShutdownEnd))); + Parent.AddAction(@"/room/room1/shutdownCancel", new Action(() => + EISC.PulseBool(BoolJoin.ShutdownCancel))); + } + + /// + /// Links feedbacks to whatever is gonna happen! + /// + void SetupFeedbacks() + { + EISC.SetStringSigAction(StringJoin.SetSource, s => + PostStatusMessage(new + { + selectedSourceKey = s + })); + + EISC.SetUShortSigAction(UshortJoin.MasterVolumeLevel, u => + PostStatusMessage(new + { + masterVolumeLevel = u + })); + + EISC.SetBoolSigAction(BoolJoin.MasterVolumeIsMuted, b => + PostStatusMessage(new + { + masterVolumeMuteState = b + })); + + EISC.SetSigTrueAction(BoolJoin.GetStatus, () => + PostStatusMessage(new + { + isOn = EISC.BooleanOutput[BoolJoin.RoomIsOn].BoolValue, + selectedSourceKey = EISC.StringOutput[StringJoin.SetSource].StringValue, + masterVolumeLevel = EISC.UShortOutput[UshortJoin.MasterVolumeLevel].UShortValue, + masterVolumeMuteState = EISC.BooleanOutput[BoolJoin.MasterVolumeIsMuted].BoolValue + })); + } + + /// + /// Helper for posting status message + /// + /// The contents of the content object + void PostStatusMessage(object contentObject) + { + Parent.PostToServer(JObject.FromObject(new + { + type = "/room/status/", + content = contentObject + })); + } + } +} \ No newline at end of file diff --git a/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs b/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs index 6bb53bda..ea9bc6ed 100644 --- a/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs +++ b/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs @@ -79,7 +79,7 @@ namespace PepperDash.Essentials JObject message = new JObject(); message.Add("type", "/room/shutdown/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); } /// @@ -94,7 +94,7 @@ namespace PepperDash.Essentials JObject message = new JObject(); message.Add("type", "/room/shutdown/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); } /// @@ -110,7 +110,7 @@ namespace PepperDash.Essentials JObject message = new JObject(); message.Add("type", "/room/shutdown/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); // equivalent JS message: // Post( { type: '/room/status/', content: { shutdown: 'hasStarted', duration: Room.ShutdownPromptTimer.SecondsToCount }) } @@ -127,7 +127,7 @@ namespace PepperDash.Essentials JObject message = new JObject(); message.Add("type", "/room/status/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); } /// @@ -142,7 +142,7 @@ namespace PepperDash.Essentials JObject message = new JObject(); message.Add("type", "/room/status/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); } /// @@ -170,7 +170,7 @@ namespace PepperDash.Essentials message.Add("type", "/room/status/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); } void Room_CurrentVolumeDeviceChange(object sender, VolumeDeviceChangeEventArgs e) @@ -222,7 +222,7 @@ namespace PepperDash.Essentials message.Add("type", "/room/status/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); } } @@ -264,9 +264,9 @@ namespace PepperDash.Essentials (previousDev as ITransport).UnlinkActions(Parent); } - JObject roomStatus = new JObject(); var huddleRoom = room as EssentialsHuddleSpaceRoom; + JObject roomStatus = new JObject(); roomStatus.Add("selectedSourceKey", huddleRoom.CurrentSourceInfoKey); JObject message = new JObject(); @@ -274,7 +274,7 @@ namespace PepperDash.Essentials message.Add("type", "/room/status/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); } else { @@ -339,7 +339,7 @@ namespace PepperDash.Essentials message.Add("type", "/room/status/"); message.Add("content", roomStatus); - Parent.PostToServer(Room, message); + Parent.PostToServer(message); } diff --git a/Release Package/PepperDashEssentials.cpz b/Release Package/PepperDashEssentials.cpz index d41a052d..2bbf6c3c 100644 Binary files a/Release Package/PepperDashEssentials.cpz and b/Release Package/PepperDashEssentials.cpz differ diff --git a/Release Package/PepperDashEssentials.dll b/Release Package/PepperDashEssentials.dll index 74bda012..77c85639 100644 Binary files a/Release Package/PepperDashEssentials.dll and b/Release Package/PepperDashEssentials.dll differ