diff --git a/Essentials/PepperDashEssentials/Config/ConfigReader.cs b/Essentials/PepperDashEssentials/Config/ConfigReader.cs index 812d288b..6ec74019 100644 --- a/Essentials/PepperDashEssentials/Config/ConfigReader.cs +++ b/Essentials/PepperDashEssentials/Config/ConfigReader.cs @@ -16,13 +16,21 @@ namespace PepperDash.Essentials { public static EssentialsConfig ConfigObject { get; private set; } - public static void LoadConfig2() + public static bool LoadConfig2() { Debug.Console(0, "Using unmerged system/template configs."); try { - using (StreamReader fs = new StreamReader(string.Format(@"\NVRAM\program{0}\ConfigurationFile.json", - InitialParametersClass.ApplicationNumber))) + var filePath = string.Format(@"\NVRAM\program{0}\ConfigurationFile.json", + InitialParametersClass.ApplicationNumber); + if (!File.Exists(filePath)) + { + Debug.Console(0, + "ERROR: Configuration file not present. Please load file to {0} and reset program", filePath); + return false; + } + + using (StreamReader fs = new StreamReader(filePath)) { var doubleObj = JObject.Parse(fs.ReadToEnd()); ConfigObject = MergeConfigs(doubleObj).ToObject(); @@ -38,13 +46,13 @@ namespace PepperDash.Essentials { ConfigObject.TemplateUrl= doubleObj["template_url"].Value(); } - - } + return true; } catch (Exception e) { - Debug.Console(0, "Config failed: \r{0}", e); + Debug.Console(0, "ERROR: Config load failed: \r{0}", e); + return false; } } diff --git a/Essentials/PepperDashEssentials/ControlSystem.cs b/Essentials/PepperDashEssentials/ControlSystem.cs index 5271248f..640f1bec 100644 --- a/Essentials/PepperDashEssentials/ControlSystem.cs +++ b/Essentials/PepperDashEssentials/ControlSystem.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Crestron.SimplSharp; +using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharpPro; using Crestron.SimplSharpPro.CrestronThread; using PepperDash.Core; @@ -49,33 +50,82 @@ namespace PepperDash.Essentials /// public void GoWithLoad() { -// var thread = new Thread(o => -// { - try + try + { + CrestronConsole.AddNewConsoleCommand(EnablePortalSync, "portalsync", "Loads Portal Sync", + ConsoleAccessLevelEnum.AccessOperator); + + //PortalSync = new PepperDashPortalSyncClient(); + + Debug.Console(0, "Starting Essentials load from configuration"); + + var filesReady = SetupFilesystem(); + if (filesReady) { - CrestronConsole.AddNewConsoleCommand(EnablePortalSync, "portalsync", "Loads Portal Sync", - ConsoleAccessLevelEnum.AccessOperator); + Debug.Console(0, "Folder structure verified. Loading config..."); + if (!ConfigReader.LoadConfig2()) + return; - //PortalSync = new PepperDashPortalSyncClient(); - - Debug.Console(0, "Starting Essentials load from configuration"); - ConfigReader.LoadConfig2(); LoadDevices(); LoadTieLines(); LoadRooms(); - LogoServer = new HttpLogoServer(8080, @"\html\logo"); + 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); + } DeviceManager.ActivateAll(); Debug.Console(0, "Essentials load complete\r" + - "-------------------------------------------------------------"); - } - catch (Exception e) - { - Debug.Console(0, "FATAL INITIALIZE ERROR. System is in an inconsistent state:\r{0}", e); + "-------------------------------------------------------------"); } -// return null; -// }, null); + 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" + + "------------------------------------------------"); + } + } + catch (Exception e) + { + Debug.Console(0, "FATAL INITIALIZE ERROR. System is in an inconsistent state:\r{0}", e); + } + + } + + /// + /// Verifies filesystem is set up. IR, SGD, and program1 folders + /// + bool SetupFilesystem() + { + Debug.Console(0, "Verifying and/or creating folder structure"); + var appNum = InitialParametersClass.ApplicationNumber; + var configDir = @"\NVRAM\Program" + appNum; + var configExists = Directory.Exists(configDir); + if (!configExists) + Directory.Create(configDir); + + var irDir = string.Format(@"\NVRAM\Program{0}\ir", appNum); + if (!Directory.Exists(irDir)) + Directory.Create(irDir); + + var sgdDir = string.Format(@"\NVRAM\Program{0}\sgd", appNum); + if (!Directory.Exists(sgdDir)) + Directory.Create(sgdDir); + + return configExists; } public void EnablePortalSync(string s) diff --git a/Essentials/PepperDashEssentials/PepperDashEssentials.csproj b/Essentials/PepperDashEssentials/PepperDashEssentials.csproj index 3476d143..a0736c23 100644 --- a/Essentials/PepperDashEssentials/PepperDashEssentials.csproj +++ b/Essentials/PepperDashEssentials/PepperDashEssentials.csproj @@ -139,7 +139,7 @@ - + diff --git a/Essentials/PepperDashEssentials/Properties/AssemblyInfo.cs b/Essentials/PepperDashEssentials/Properties/AssemblyInfo.cs index 06ce5109..e9174846 100644 --- a/Essentials/PepperDashEssentials/Properties/AssemblyInfo.cs +++ b/Essentials/PepperDashEssentials/Properties/AssemblyInfo.cs @@ -4,5 +4,5 @@ [assembly: AssemblyCompany("PepperDash Technology Corp")] [assembly: AssemblyProduct("PepperDashEssentials")] [assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")] -[assembly: AssemblyVersion("1.0.15.*")] +[assembly: AssemblyVersion("1.0.17.*")] diff --git a/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs b/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs index 25a7ecd7..a335bd20 100644 --- a/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs +++ b/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs @@ -53,6 +53,7 @@ namespace PepperDash.Essentials public CotijaSystemController(string key, string name, CotijaConfig config) : base(key, name) { Config = config; + Debug.Console(0, this, "Mobile UI controller initializing for server:{0}", config.ServerUrl); CotijaRooms = new List(); diff --git a/Essentials/PepperDashEssentials/Room/Cotija/CotijaRoomBridge.cs b/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs similarity index 97% rename from Essentials/PepperDashEssentials/Room/Cotija/CotijaRoomBridge.cs rename to Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs index b725c2d5..6bb53bda 100644 --- a/Essentials/PepperDashEssentials/Room/Cotija/CotijaRoomBridge.cs +++ b/Essentials/PepperDashEssentials/Room/Cotija/RoomBridges/CotijaEssentialsHuddleSpaceRoomBridge.cs @@ -1,357 +1,357 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Crestron.SimplSharp; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using PepperDash.Essentials.Core; -using PepperDash.Essentials.Room.Cotija; - -namespace PepperDash.Essentials -{ - public class CotijaEssentialsHuddleSpaceRoomBridge - { - CotijaSystemController Parent; - - public EssentialsHuddleSpaceRoom Room { get; private set; } - - public CotijaEssentialsHuddleSpaceRoomBridge(CotijaSystemController parent, EssentialsHuddleSpaceRoom room) - { - Parent = parent; - Room = room; - - // we add actions to the messaging system with a path, and a related action. Custom action - // content objects can be handled in the controller's LineReceived method - and perhaps other - // sub-controller parsing could be attached to these classes, so that the systemController - // doesn't need to know about everything. - - // Source Changes and room off - Parent.AddAction(string.Format(@"/room/{0}/status",Room.Key), new Action(() => Room_RoomFullStatus(Room))); - Parent.AddAction(string.Format(@"/room/{0}/source", Room.Key), new Action(c => room.RunRouteAction(c.SourceListItem))); - Parent.AddAction(string.Format(@"/room/{0}/defaultsource", Room.Key), new Action(Room.RunDefaultRoute)); - - Parent.AddAction(string.Format(@"/room/{0}/masterVolumeLevel", Room.Key), new Action(u => - (room.CurrentVolumeControls as IBasicVolumeWithFeedback).SetVolume(u))); - Parent.AddAction(string.Format(@"/room/{0}/masterVolumeMuteToggle", Room.Key), new Action(() => room.CurrentVolumeControls.MuteToggle())); - - Parent.AddAction(string.Format(@"/room/{0}/shutdownStart", Room.Key), new Action(() => room.StartShutdown(eShutdownType.Manual))); - Parent.AddAction(string.Format(@"/room/{0}/shutdownEnd", Room.Key), new Action(() => room.ShutdownPromptTimer.Finish())); - Parent.AddAction(string.Format(@"/room/{0}/shutdownCancel", Room.Key), new Action(() => room.ShutdownPromptTimer.Cancel())); - - Room.CurrentSingleSourceChange += new SourceInfoChangeHandler(Room_CurrentSingleSourceChange); - - Room.CurrentVolumeDeviceChange += new EventHandler(Room_CurrentVolumeDeviceChange); - - Room.OnFeedback.OutputChange += new EventHandler(OnFeedback_OutputChange); - Room.IsCoolingDownFeedback.OutputChange += new EventHandler(IsCoolingDownFeedback_OutputChange); - Room.IsWarmingUpFeedback.OutputChange += new EventHandler(IsWarmingUpFeedback_OutputChange); - - Room.ShutdownPromptTimer.HasStarted += new EventHandler(ShutdownPromptTimer_HasStarted); - Room.ShutdownPromptTimer.HasFinished += new EventHandler(ShutdownPromptTimer_HasFinished); - Room.ShutdownPromptTimer.WasCancelled += new EventHandler(ShutdownPromptTimer_WasCancelled); - - // Registers for initial volume events, if possible - var currentVolumeDevice = Room.CurrentVolumeControls; - - if (currentVolumeDevice != null) - { - if (currentVolumeDevice is IBasicVolumeWithFeedback) - { - var newDev = currentVolumeDevice as IBasicVolumeWithFeedback; - - newDev.MuteFeedback.OutputChange += new EventHandler(VolumeLevelFeedback_OutputChange); - newDev.VolumeLevelFeedback.OutputChange += new EventHandler(VolumeLevelFeedback_OutputChange); - } - } - - } - - /// - /// Handler for cancelled shutdown - /// - /// - /// - void ShutdownPromptTimer_WasCancelled(object sender, EventArgs e) - { - JObject roomStatus = new JObject(); - roomStatus.Add("state", "wasCancelled"); - JObject message = new JObject(); - message.Add("type", "/room/shutdown/"); - message.Add("content", roomStatus); - Parent.PostToServer(Room, message); - } - - /// - /// Handler for when shutdown finishes - /// - /// - /// - void ShutdownPromptTimer_HasFinished(object sender, EventArgs e) - { - JObject roomStatus = new JObject(); - roomStatus.Add("state", "hasFinished"); - JObject message = new JObject(); - message.Add("type", "/room/shutdown/"); - message.Add("content", roomStatus); - Parent.PostToServer(Room, message); - } - - /// - /// Handler for when shutdown starts - /// - /// - /// - void ShutdownPromptTimer_HasStarted(object sender, EventArgs e) - { - JObject roomStatus = new JObject(); - roomStatus.Add("state", "hasStarted"); - roomStatus.Add("duration", Room.ShutdownPromptTimer.SecondsToCount); - JObject message = new JObject(); - message.Add("type", "/room/shutdown/"); - message.Add("content", roomStatus); - Parent.PostToServer(Room, message); - // equivalent JS message: - // Post( { type: '/room/status/', content: { shutdown: 'hasStarted', duration: Room.ShutdownPromptTimer.SecondsToCount }) - } - - /// - /// - /// - /// - /// - void IsWarmingUpFeedback_OutputChange(object sender, EventArgs e) - { - JObject roomStatus = new JObject(); - roomStatus.Add("isWarmingUp", (sender as BoolFeedback).BoolValue); - JObject message = new JObject(); - message.Add("type", "/room/status/"); - message.Add("content", roomStatus); - Parent.PostToServer(Room, message); - } - - /// - /// - /// - /// - /// - void IsCoolingDownFeedback_OutputChange(object sender, EventArgs e) - { - JObject roomStatus = new JObject(); - roomStatus.Add("isCoolingDown", (sender as BoolFeedback).BoolValue); - JObject message = new JObject(); - message.Add("type", "/room/status/"); - message.Add("content", roomStatus); - Parent.PostToServer(Room, message); - } - - /// - /// - /// - /// - /// - void OnFeedback_OutputChange(object sender, EventArgs e) - { - /* Example message - * { - "type":"/room/status", - "content": { - "isOn": false - } - } - */ - - JObject roomStatus = new JObject(); - - roomStatus.Add("isOn", (sender as BoolFeedback).BoolValue); - - JObject message = new JObject(); - - message.Add("type", "/room/status/"); - message.Add("content", roomStatus); - - Parent.PostToServer(Room, message); - } - - void Room_CurrentVolumeDeviceChange(object sender, VolumeDeviceChangeEventArgs e) - { - if (e.OldDev is IBasicVolumeWithFeedback) - { - var oldDev = e.OldDev as IBasicVolumeWithFeedback; - - oldDev.MuteFeedback.OutputChange -= VolumeLevelFeedback_OutputChange; - oldDev.VolumeLevelFeedback.OutputChange -= VolumeLevelFeedback_OutputChange; - } - - if (e.NewDev is IBasicVolumeWithFeedback) - { - var newDev = e.NewDev as IBasicVolumeWithFeedback; - - newDev.MuteFeedback.OutputChange += new EventHandler(VolumeLevelFeedback_OutputChange); - newDev.VolumeLevelFeedback.OutputChange += new EventHandler(VolumeLevelFeedback_OutputChange); - } - } - - void VolumeLevelFeedback_OutputChange(object sender, EventArgs e) - { - /* Example message - * { -   "type":"/room/status", -   "content": { -     "masterVolumeLevel": 12345, -     "masterVolumeMuteState": false -   } - } - */ - - var huddleRoom = Room as EssentialsHuddleSpaceRoom; - - if(huddleRoom.CurrentVolumeControls is IBasicVolumeWithFeedback) - { - JObject roomStatus = new JObject(); - - if (huddleRoom.CurrentVolumeControls is IBasicVolumeWithFeedback) - { - var currentVolumeConstrols = huddleRoom.CurrentVolumeControls as IBasicVolumeWithFeedback; - roomStatus.Add("masterVolumeLevel", currentVolumeConstrols.VolumeLevelFeedback.IntValue); - roomStatus.Add("masterVolumeMuteState", currentVolumeConstrols.MuteFeedback.BoolValue); - } - - JObject message = new JObject(); - - message.Add("type", "/room/status/"); - message.Add("content", roomStatus); - - Parent.PostToServer(Room, message); - } - } - - void Room_CurrentSingleSourceChange(EssentialsRoomBase room, PepperDash.Essentials.Core.SourceListItem info, ChangeType type) - { - /* Example message - * { -   "type":"/room/status", -   "content": { -     "selectedSourceKey": "off", -   } - } - */ - if (type == ChangeType.WillChange) - { - // Disconnect from previous source - - if (info != null) - { - var previousDev = info.SourceDevice; - - // device type interfaces - if (previousDev is ISetTopBoxControls) - (previousDev as ISetTopBoxControls).UnlinkActions(Parent); - // common interfaces - if (previousDev is IChannel) - (previousDev as IChannel).UnlinkActions(Parent); - if (previousDev is IColor) - (previousDev as IColor).UnlinkActions(Parent); - if (previousDev is IDPad) - (previousDev as IDPad).UnlinkActions(Parent); - if (previousDev is IDvr) - (previousDev as IDvr).UnlinkActions(Parent); - if (previousDev is INumericKeypad) - (previousDev as INumericKeypad).UnlinkActions(Parent); - if (previousDev is IPower) - (previousDev as IPower).UnlinkActions(Parent); - if (previousDev is ITransport) - (previousDev as ITransport).UnlinkActions(Parent); - } - - JObject roomStatus = new JObject(); - - var huddleRoom = room as EssentialsHuddleSpaceRoom; - roomStatus.Add("selectedSourceKey", huddleRoom.CurrentSourceInfoKey); - - JObject message = new JObject(); - - message.Add("type", "/room/status/"); - message.Add("content", roomStatus); - - Parent.PostToServer(Room, message); - } - else - { - if (info != null) - { - var dev = info.SourceDevice; - - if (dev is ISetTopBoxControls) - (dev as ISetTopBoxControls).LinkActions(Parent); - if (dev is IChannel) - (dev as IChannel).LinkActions(Parent); - if (dev is IColor) - (dev as IColor).LinkActions(Parent); - if (dev is IDPad) - (dev as IDPad).LinkActions(Parent); - if (dev is IDvr) - (dev as IDvr).LinkActions(Parent); - if (dev is INumericKeypad) - (dev as INumericKeypad).LinkActions(Parent); - if (dev is IPower) - (dev as IPower).LinkActions(Parent); - if (dev is ITransport) - (dev as ITransport).LinkActions(Parent); - } - } - } - - /// - /// Posts the full status of the room to the server - /// - /// - void Room_RoomFullStatus(EssentialsRoomBase room) - { - /* Example message - * { - "type":"/room/status", - "content": { - "selectedSourceKey": "off", - "isOn": false, - "masterVolumeLevel": 50, - "masterVolumeMuteState": false - } - } - */ - - JObject roomStatus = new JObject(); - - var huddleRoom = room as EssentialsHuddleSpaceRoom; - roomStatus.Add("isOn", huddleRoom.OnFeedback.BoolValue); - roomStatus.Add("selectedSourceKey", huddleRoom.CurrentSourceInfoKey); - - - if(huddleRoom.CurrentVolumeControls is IBasicVolumeWithFeedback) - { - var currentVolumeConstrols = huddleRoom.CurrentVolumeControls as IBasicVolumeWithFeedback; - roomStatus.Add("masterVolumeLevel", currentVolumeConstrols.VolumeLevelFeedback.IntValue); - roomStatus.Add("masterVolumeMuteState", currentVolumeConstrols.MuteFeedback.BoolValue); - } - - JObject message = new JObject(); - - message.Add("type", "/room/status/"); - message.Add("content", roomStatus); - - Parent.PostToServer(Room, message); - - } - - } - - public class SourceSelectMessageContent - { - public string SourceListItem { get; set; } - //public string Destination { get; set; } - //public string SourceSelect { get; set; } - } - - public delegate void PressAndHoldAction(bool b); - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Room.Cotija; + +namespace PepperDash.Essentials +{ + public class CotijaEssentialsHuddleSpaceRoomBridge + { + CotijaSystemController Parent; + + public EssentialsHuddleSpaceRoom Room { get; private set; } + + public CotijaEssentialsHuddleSpaceRoomBridge(CotijaSystemController parent, EssentialsHuddleSpaceRoom room) + { + Parent = parent; + Room = room; + + // we add actions to the messaging system with a path, and a related action. Custom action + // content objects can be handled in the controller's LineReceived method - and perhaps other + // sub-controller parsing could be attached to these classes, so that the systemController + // doesn't need to know about everything. + + // Source Changes and room off + Parent.AddAction(string.Format(@"/room/{0}/status",Room.Key), new Action(() => Room_RoomFullStatus(Room))); + Parent.AddAction(string.Format(@"/room/{0}/source", Room.Key), new Action(c => room.RunRouteAction(c.SourceListItem))); + Parent.AddAction(string.Format(@"/room/{0}/defaultsource", Room.Key), new Action(Room.RunDefaultRoute)); + + Parent.AddAction(string.Format(@"/room/{0}/masterVolumeLevel", Room.Key), new Action(u => + (room.CurrentVolumeControls as IBasicVolumeWithFeedback).SetVolume(u))); + Parent.AddAction(string.Format(@"/room/{0}/masterVolumeMuteToggle", Room.Key), new Action(() => room.CurrentVolumeControls.MuteToggle())); + + Parent.AddAction(string.Format(@"/room/{0}/shutdownStart", Room.Key), new Action(() => room.StartShutdown(eShutdownType.Manual))); + Parent.AddAction(string.Format(@"/room/{0}/shutdownEnd", Room.Key), new Action(() => room.ShutdownPromptTimer.Finish())); + Parent.AddAction(string.Format(@"/room/{0}/shutdownCancel", Room.Key), new Action(() => room.ShutdownPromptTimer.Cancel())); + + Room.CurrentSingleSourceChange += new SourceInfoChangeHandler(Room_CurrentSingleSourceChange); + + Room.CurrentVolumeDeviceChange += new EventHandler(Room_CurrentVolumeDeviceChange); + + Room.OnFeedback.OutputChange += new EventHandler(OnFeedback_OutputChange); + Room.IsCoolingDownFeedback.OutputChange += new EventHandler(IsCoolingDownFeedback_OutputChange); + Room.IsWarmingUpFeedback.OutputChange += new EventHandler(IsWarmingUpFeedback_OutputChange); + + Room.ShutdownPromptTimer.HasStarted += new EventHandler(ShutdownPromptTimer_HasStarted); + Room.ShutdownPromptTimer.HasFinished += new EventHandler(ShutdownPromptTimer_HasFinished); + Room.ShutdownPromptTimer.WasCancelled += new EventHandler(ShutdownPromptTimer_WasCancelled); + + // Registers for initial volume events, if possible + var currentVolumeDevice = Room.CurrentVolumeControls; + + if (currentVolumeDevice != null) + { + if (currentVolumeDevice is IBasicVolumeWithFeedback) + { + var newDev = currentVolumeDevice as IBasicVolumeWithFeedback; + + newDev.MuteFeedback.OutputChange += new EventHandler(VolumeLevelFeedback_OutputChange); + newDev.VolumeLevelFeedback.OutputChange += new EventHandler(VolumeLevelFeedback_OutputChange); + } + } + + } + + /// + /// Handler for cancelled shutdown + /// + /// + /// + void ShutdownPromptTimer_WasCancelled(object sender, EventArgs e) + { + JObject roomStatus = new JObject(); + roomStatus.Add("state", "wasCancelled"); + JObject message = new JObject(); + message.Add("type", "/room/shutdown/"); + message.Add("content", roomStatus); + Parent.PostToServer(Room, message); + } + + /// + /// Handler for when shutdown finishes + /// + /// + /// + void ShutdownPromptTimer_HasFinished(object sender, EventArgs e) + { + JObject roomStatus = new JObject(); + roomStatus.Add("state", "hasFinished"); + JObject message = new JObject(); + message.Add("type", "/room/shutdown/"); + message.Add("content", roomStatus); + Parent.PostToServer(Room, message); + } + + /// + /// Handler for when shutdown starts + /// + /// + /// + void ShutdownPromptTimer_HasStarted(object sender, EventArgs e) + { + JObject roomStatus = new JObject(); + roomStatus.Add("state", "hasStarted"); + roomStatus.Add("duration", Room.ShutdownPromptTimer.SecondsToCount); + JObject message = new JObject(); + message.Add("type", "/room/shutdown/"); + message.Add("content", roomStatus); + Parent.PostToServer(Room, message); + // equivalent JS message: + // Post( { type: '/room/status/', content: { shutdown: 'hasStarted', duration: Room.ShutdownPromptTimer.SecondsToCount }) + } + + /// + /// + /// + /// + /// + void IsWarmingUpFeedback_OutputChange(object sender, EventArgs e) + { + JObject roomStatus = new JObject(); + roomStatus.Add("isWarmingUp", (sender as BoolFeedback).BoolValue); + JObject message = new JObject(); + message.Add("type", "/room/status/"); + message.Add("content", roomStatus); + Parent.PostToServer(Room, message); + } + + /// + /// + /// + /// + /// + void IsCoolingDownFeedback_OutputChange(object sender, EventArgs e) + { + JObject roomStatus = new JObject(); + roomStatus.Add("isCoolingDown", (sender as BoolFeedback).BoolValue); + JObject message = new JObject(); + message.Add("type", "/room/status/"); + message.Add("content", roomStatus); + Parent.PostToServer(Room, message); + } + + /// + /// + /// + /// + /// + void OnFeedback_OutputChange(object sender, EventArgs e) + { + /* Example message + * { + "type":"/room/status", + "content": { + "isOn": false + } + } + */ + + JObject roomStatus = new JObject(); + + roomStatus.Add("isOn", (sender as BoolFeedback).BoolValue); + + JObject message = new JObject(); + + message.Add("type", "/room/status/"); + message.Add("content", roomStatus); + + Parent.PostToServer(Room, message); + } + + void Room_CurrentVolumeDeviceChange(object sender, VolumeDeviceChangeEventArgs e) + { + if (e.OldDev is IBasicVolumeWithFeedback) + { + var oldDev = e.OldDev as IBasicVolumeWithFeedback; + + oldDev.MuteFeedback.OutputChange -= VolumeLevelFeedback_OutputChange; + oldDev.VolumeLevelFeedback.OutputChange -= VolumeLevelFeedback_OutputChange; + } + + if (e.NewDev is IBasicVolumeWithFeedback) + { + var newDev = e.NewDev as IBasicVolumeWithFeedback; + + newDev.MuteFeedback.OutputChange += new EventHandler(VolumeLevelFeedback_OutputChange); + newDev.VolumeLevelFeedback.OutputChange += new EventHandler(VolumeLevelFeedback_OutputChange); + } + } + + void VolumeLevelFeedback_OutputChange(object sender, EventArgs e) + { + /* Example message + * { +   "type":"/room/status", +   "content": { +     "masterVolumeLevel": 12345, +     "masterVolumeMuteState": false +   } + } + */ + + var huddleRoom = Room as EssentialsHuddleSpaceRoom; + + if(huddleRoom.CurrentVolumeControls is IBasicVolumeWithFeedback) + { + JObject roomStatus = new JObject(); + + if (huddleRoom.CurrentVolumeControls is IBasicVolumeWithFeedback) + { + var currentVolumeConstrols = huddleRoom.CurrentVolumeControls as IBasicVolumeWithFeedback; + roomStatus.Add("masterVolumeLevel", currentVolumeConstrols.VolumeLevelFeedback.IntValue); + roomStatus.Add("masterVolumeMuteState", currentVolumeConstrols.MuteFeedback.BoolValue); + } + + JObject message = new JObject(); + + message.Add("type", "/room/status/"); + message.Add("content", roomStatus); + + Parent.PostToServer(Room, message); + } + } + + void Room_CurrentSingleSourceChange(EssentialsRoomBase room, PepperDash.Essentials.Core.SourceListItem info, ChangeType type) + { + /* Example message + * { +   "type":"/room/status", +   "content": { +     "selectedSourceKey": "off", +   } + } + */ + if (type == ChangeType.WillChange) + { + // Disconnect from previous source + + if (info != null) + { + var previousDev = info.SourceDevice; + + // device type interfaces + if (previousDev is ISetTopBoxControls) + (previousDev as ISetTopBoxControls).UnlinkActions(Parent); + // common interfaces + if (previousDev is IChannel) + (previousDev as IChannel).UnlinkActions(Parent); + if (previousDev is IColor) + (previousDev as IColor).UnlinkActions(Parent); + if (previousDev is IDPad) + (previousDev as IDPad).UnlinkActions(Parent); + if (previousDev is IDvr) + (previousDev as IDvr).UnlinkActions(Parent); + if (previousDev is INumericKeypad) + (previousDev as INumericKeypad).UnlinkActions(Parent); + if (previousDev is IPower) + (previousDev as IPower).UnlinkActions(Parent); + if (previousDev is ITransport) + (previousDev as ITransport).UnlinkActions(Parent); + } + + JObject roomStatus = new JObject(); + + var huddleRoom = room as EssentialsHuddleSpaceRoom; + roomStatus.Add("selectedSourceKey", huddleRoom.CurrentSourceInfoKey); + + JObject message = new JObject(); + + message.Add("type", "/room/status/"); + message.Add("content", roomStatus); + + Parent.PostToServer(Room, message); + } + else + { + if (info != null) + { + var dev = info.SourceDevice; + + if (dev is ISetTopBoxControls) + (dev as ISetTopBoxControls).LinkActions(Parent); + if (dev is IChannel) + (dev as IChannel).LinkActions(Parent); + if (dev is IColor) + (dev as IColor).LinkActions(Parent); + if (dev is IDPad) + (dev as IDPad).LinkActions(Parent); + if (dev is IDvr) + (dev as IDvr).LinkActions(Parent); + if (dev is INumericKeypad) + (dev as INumericKeypad).LinkActions(Parent); + if (dev is IPower) + (dev as IPower).LinkActions(Parent); + if (dev is ITransport) + (dev as ITransport).LinkActions(Parent); + } + } + } + + /// + /// Posts the full status of the room to the server + /// + /// + void Room_RoomFullStatus(EssentialsRoomBase room) + { + /* Example message + * { + "type":"/room/status", + "content": { + "selectedSourceKey": "off", + "isOn": false, + "masterVolumeLevel": 50, + "masterVolumeMuteState": false + } + } + */ + + JObject roomStatus = new JObject(); + + var huddleRoom = room as EssentialsHuddleSpaceRoom; + roomStatus.Add("isOn", huddleRoom.OnFeedback.BoolValue); + roomStatus.Add("selectedSourceKey", huddleRoom.CurrentSourceInfoKey); + + + if(huddleRoom.CurrentVolumeControls is IBasicVolumeWithFeedback) + { + var currentVolumeConstrols = huddleRoom.CurrentVolumeControls as IBasicVolumeWithFeedback; + roomStatus.Add("masterVolumeLevel", currentVolumeConstrols.VolumeLevelFeedback.IntValue); + roomStatus.Add("masterVolumeMuteState", currentVolumeConstrols.MuteFeedback.BoolValue); + } + + JObject message = new JObject(); + + message.Add("type", "/room/status/"); + message.Add("content", roomStatus); + + Parent.PostToServer(Room, message); + + } + + } + + public class SourceSelectMessageContent + { + public string SourceListItem { get; set; } + //public string Destination { get; set; } + //public string SourceSelect { get; set; } + } + + public delegate void PressAndHoldAction(bool b); + } \ No newline at end of file diff --git a/Essentials/PepperDashEssentials/UI/EssentialsTouchpanelController.cs b/Essentials/PepperDashEssentials/UI/EssentialsTouchpanelController.cs index 7c1bd959..5aeb2837 100644 --- a/Essentials/PepperDashEssentials/UI/EssentialsTouchpanelController.cs +++ b/Essentials/PepperDashEssentials/UI/EssentialsTouchpanelController.cs @@ -98,7 +98,7 @@ namespace PepperDash.Essentials + @"\sgd\" + props.SgdFile; if (!File.Exists(sgdName)) { - Debug.Console(0, this, "WARNING: Smart object file '{0}' not present. Exiting TSW load", sgdName); + Debug.Console(0, this, "ERROR: Smart object file '{0}' not present. Exiting TSW load", sgdName); return; } diff --git a/Release Package/PepperDashEssentials.cpz b/Release Package/PepperDashEssentials.cpz index d590b67c..6361dec8 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 df93e061..974d1078 100644 Binary files a/Release Package/PepperDashEssentials.dll and b/Release Package/PepperDashEssentials.dll differ