diff --git a/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.projectinfo b/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.projectinfo index 9fdf18f4..66eccd5f 100644 Binary files a/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.projectinfo and b/Essentials Core/PepperDashEssentialsBase/PepperDash_Essentials_Core.projectinfo differ diff --git a/Essentials DM/Essentials_DM/Essentials_DM.projectinfo b/Essentials DM/Essentials_DM/Essentials_DM.projectinfo index 3811ad6a..a1d68468 100644 Binary files a/Essentials DM/Essentials_DM/Essentials_DM.projectinfo and b/Essentials DM/Essentials_DM/Essentials_DM.projectinfo differ diff --git a/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.projectinfo b/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.projectinfo index f4662abf..08ced498 100644 Binary files a/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.projectinfo and b/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.projectinfo differ diff --git a/Essentials/PepperDashEssentials/PepperDashEssentials.projectinfo b/Essentials/PepperDashEssentials/PepperDashEssentials.projectinfo index a3945a8e..e67ef746 100644 Binary files a/Essentials/PepperDashEssentials/PepperDashEssentials.projectinfo and b/Essentials/PepperDashEssentials/PepperDashEssentials.projectinfo differ diff --git a/Essentials/PepperDashEssentials/Room/Cotija/CotijaRoomBridge.cs b/Essentials/PepperDashEssentials/Room/Cotija/CotijaRoomBridge.cs index 570216f4..e8e468fa 100644 --- a/Essentials/PepperDashEssentials/Room/Cotija/CotijaRoomBridge.cs +++ b/Essentials/PepperDashEssentials/Room/Cotija/CotijaRoomBridge.cs @@ -23,8 +23,8 @@ namespace PepperDash.Essentials // 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.SourceSelect))); - Parent.AddAction(string.Format(@"/room/{0}/event/masterVolumeUpBtn", Room.Key), new Action(b => room.CurrentVolumeControls.VolumeUp(b))); - Parent.AddAction(string.Format(@"/room/{0}/event/masterVolumeDownBtn", Room.Key), new Action(b => room.CurrentVolumeControls.VolumeDown(b))); + Parent.AddAction(string.Format(@"/room/{0}/event/masterVolumeUpBtn", Room.Key), new PressAndHoldAction(b => room.CurrentVolumeControls.VolumeUp(b))); + Parent.AddAction(string.Format(@"/room/{0}/event/masterVolumeDownBtn", Room.Key), new PressAndHoldAction(b => room.CurrentVolumeControls.VolumeDown(b))); Parent.AddAction(string.Format(@"/room/{0}/event/muteToggle", Room.Key), new Action(() => room.CurrentVolumeControls.MuteToggle())); Room.CurrentSingleSourceChange += new SourceInfoChangeHandler(Room_CurrentSingleSourceChange); @@ -202,25 +202,6 @@ namespace PepperDash.Essentials public string SourceSelect { get; set; } } - //public class PostMessage - //{ - // [JsonProperty("type")] - // public string Type { get; set; } - - // [JsonProperty("content")] - // public JToken Content { get; set; } - //} - - //public class RoomStatusMessageContent - //{ - // [JsonProperty("selectedSourceKey")] - // public string SelectedSourceKey { get; set; } - // [JsonProperty("isOn")] - // public bool? IsOn { get; set; } - // [JsonProperty("masterVolumeLevel")] - // public int? MasterVolumeLevel { get; set; } - // [JsonProperty("masterVolumeMuteState")] - // public bool? MasterVolumeMuteState { get; set; } - //} + public delegate void PressAndHoldAction(bool b); } \ No newline at end of file diff --git a/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs b/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs index 7ddffbd6..3f038bac 100644 --- a/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs +++ b/Essentials/PepperDashEssentials/Room/Cotija/CotijaSystemController.cs @@ -24,22 +24,28 @@ namespace PepperDash.Essentials HttpClient Client; - Dictionary ActionDictionary; + Dictionary ActionDictionary = new Dictionary(); - CTimer Heartbeat; + Dictionary PushedActions = new Dictionary(); - CTimer Reconnect; + CTimer ServerHeartbeat; + + long ServerHeartbeatInterval = 20000; + + CTimer ServerReconnect; + + long ServerReconnectInterval = 5000; string SystemUuid; public List CotijaRooms { get; private set; } + long ButtonHeartbeatInterval = 1000; + public CotijaSystemController(string key, string name, CotijaConfig config) : base(key, name) { Config = config; - ActionDictionary = new Dictionary(); - CotijaRooms = new List(); CrestronConsole.AddNewConsoleCommand(RegisterSystemToServer, "InitializeHttpClient", "Initializes a new HTTP client connection to a specified URL", ConsoleAccessLevelEnum.AccessOperator); @@ -177,7 +183,7 @@ namespace PepperDash.Essentials Client.DispatchAsync(request, (r, err) => { if (r != null) { Debug.Console(1, this, "Status Response Code: {0}", r.Code); } }); - StartReconnectTimer(5000, 5000); + StartReconnectTimer(ServerReconnectInterval, ServerReconnectInterval); } catch(Exception e) { @@ -194,11 +200,11 @@ namespace PepperDash.Essentials if(SseClient != null) SseClient.Disconnect(); - if (Heartbeat != null) + if (ServerHeartbeat != null) { - Heartbeat.Stop(); + ServerHeartbeat.Stop(); - Heartbeat = null; + ServerHeartbeat = null; } } @@ -213,11 +219,11 @@ namespace PepperDash.Essentials { if (resp != null && resp.Code == 200) { - if(Reconnect != null) + if(ServerReconnect != null) { - Reconnect.Stop(); + ServerReconnect.Stop(); - Reconnect = null; + ServerReconnect = null; } if (SseClient == null) @@ -242,24 +248,24 @@ namespace PepperDash.Essentials /// void HeartbeatExpired(object o) { - if (Heartbeat != null) + if (ServerHeartbeat != null) { Debug.Console(1, this, "Heartbeat Timer Expired."); - Heartbeat.Stop(); + ServerHeartbeat.Stop(); - Heartbeat = null; + ServerHeartbeat = null; } - StartReconnectTimer(5000, 5000); + StartReconnectTimer(ServerReconnectInterval, ServerReconnectInterval); } void StartReconnectTimer(long dueTime, long repeatTime) { // Start the reconnect timer - Reconnect = new CTimer(ReconnectToServer, null, dueTime, repeatTime); + ServerReconnect = new CTimer(ReconnectToServer, null, dueTime, repeatTime); - Reconnect.Reset(dueTime, repeatTime); + ServerReconnect.Reset(dueTime, repeatTime); } @@ -313,15 +319,15 @@ namespace PepperDash.Essentials if (type == "hello") { - Heartbeat = new CTimer(HeartbeatExpired, null, 20000, 20000); + ServerHeartbeat = new CTimer(HeartbeatExpired, null, ServerHeartbeatInterval, ServerHeartbeatInterval); Debug.Console(2, this, "Heartbeat Timer Started."); - Heartbeat.Reset(20000, 20000); + ServerHeartbeat.Reset(ServerHeartbeatInterval, ServerHeartbeatInterval); } else if (type == "/system/heartbeat") { - Heartbeat.Reset(20000, 20000); + ServerHeartbeat.Reset(ServerHeartbeatInterval, ServerHeartbeatInterval); Debug.Console(2, this, "Heartbeat Timer Reset."); } @@ -330,9 +336,9 @@ namespace PepperDash.Essentials SseClient.Disconnect(); // Start the reconnect timer - Reconnect = new CTimer(ConnectSseClient, null, 5000, 5000); + ServerReconnect = new CTimer(ConnectSseClient, null, ServerReconnectInterval, ServerReconnectInterval); - Reconnect.Reset(5000, 5000); + ServerReconnect.Reset(ServerReconnectInterval, ServerReconnectInterval); } else { @@ -345,20 +351,59 @@ namespace PepperDash.Essentials { (action as Action)(); } - else if (action is Action) + else if (action is PressAndHoldAction) { var stateString = messageObj["content"]["state"].Value(); // Look for a button press event if (!string.IsNullOrEmpty(stateString)) { -#warning deal with held state later - if (stateString == "held") - return; + switch (stateString) + { + case "true": + { + if (!PushedActions.ContainsKey(type)) + { + PushedActions.Add(type, new CTimer(o => + { + (action as Action)(false); + PushedActions.Remove(type); + }, null, ButtonHeartbeatInterval, ButtonHeartbeatInterval)); + } + // Maybe add an else to reset the timer + break; + } + case "held": + { + if (!PushedActions.ContainsKey(type)) + { + PushedActions[type].Reset(ButtonHeartbeatInterval, ButtonHeartbeatInterval); + } + return; + } + case "false": + { + if (!PushedActions.ContainsKey(type)) + { + PushedActions[type].Stop(); + PushedActions.Remove(type); + } + break; + } + } (action as Action)(stateString == "true"); } } + else if (action is Action) + { + var stateString = messageObj["content"]["state"].Value(); + + if (!string.IsNullOrEmpty(stateString)) + { + (action as Action)(stateString == "true"); + } + } else if (action is Action) { (action as Action)(messageObj["content"]["value"].Value());