Added IPad Extension methods to link actions between Cotija server and devices for proof of concept

This commit is contained in:
Neil Dorin
2017-06-28 16:29:17 -06:00
parent 95dcc48628
commit 3f6b3ffba0
13 changed files with 969 additions and 860 deletions

View File

@@ -135,22 +135,73 @@ namespace PepperDash.Essentials
}
}
*/
if (type == ChangeType.WillChange)
{
// Disconnect from previous source
if (type != ChangeType.DidChange)
return;
if (info != null)
{
var previousDev = info.SourceDevice;
JObject roomStatus = new JObject();
// device type interfaces
//if (previousDev is ISetTopBoxControls)
// (previousDev as ISetTopBoxControls).UnlinkButtons(TriList);
//// common interfaces
//if (previousDev is IChannel)
// (previousDev as IChannel).UnlinkButtons(TriList);
//if (previousDev is IColor)
// (previousDev as IColor).UnlinkButtons(TriList);
if (previousDev is IDPad)
(previousDev as IDPad).UnlinkActions(Parent);
//if (previousDev is IDvr)
// (previousDev as IDvr).UnlinkButtons(TriList);
//if (previousDev is INumericKeypad)
// (previousDev as INumericKeypad).UnlinkButtons(TriList);
//if (previousDev is IPower)
// (previousDev as IPower).UnlinkButtons(TriList);
//if (previousDev is ITransport)
// (previousDev as ITransport).UnlinkButtons(TriList);
}
var huddleRoom = room as EssentialsHuddleSpaceRoom;
//roomStatus.Add("isOn", huddleRoom.OnFeedback.BoolValue);
roomStatus.Add("selectedSourceKey", huddleRoom.CurrentSourceInfoKey);
JObject roomStatus = new JObject();
JObject message = new JObject();
var huddleRoom = room as EssentialsHuddleSpaceRoom;
//roomStatus.Add("isOn", huddleRoom.OnFeedback.BoolValue);
roomStatus.Add("selectedSourceKey", huddleRoom.CurrentSourceInfoKey);
message.Add("type", "/room/status/");
message.Add("content", roomStatus);
JObject message = new JObject();
Parent.PostToServer(Room, message);
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).LinkButtons(TriList);
//if (dev is IChannel)
// (dev as IChannel).LinkButtons(TriList);
//if (dev is IColor)
// (dev as IColor).LinkButtons(TriList);
if (dev is IDPad)
(dev as IDPad).LinkActions(Parent);
//if (dev is IDvr)
// (dev as IDvr).LinkButtons(TriList);
//if (dev is INumericKeypad)
// (dev as INumericKeypad).LinkButtons(TriList);
//if (dev is IPower)
// (dev as IPower).LinkButtons(TriList);
//if (dev is ITransport)
// (dev as ITransport).LinkButtons(TriList);
}
}
}
/// <summary>

View File

@@ -107,7 +107,7 @@ namespace PepperDash.Essentials
if (FileLock.TryEnter())
{
Debug.Console(1, this, "Reading Configuration File");
Debug.Console(1, this, "Reading configuration file to extract system UUID...");
postBody = File.ReadToEnd(filePath, Encoding.ASCII);
@@ -268,6 +268,20 @@ namespace PepperDash.Essentials
ServerReconnect.Reset(dueTime, repeatTime);
}
void StartHearbeatTimer(long dueTime, long repeatTime)
{
if (ServerHeartbeat == null)
{
ServerHeartbeat = new CTimer(HeartbeatExpired, null, dueTime, repeatTime);
Debug.Console(2, this, "Heartbeat Timer Started.");
}
ServerHeartbeat.Reset(dueTime, repeatTime);
Debug.Console(2, this, "Heartbeat Timer Reset.");
}
/// <summary>
/// Connects the SSE Client
@@ -319,17 +333,11 @@ namespace PepperDash.Essentials
if (type == "hello")
{
ServerHeartbeat = new CTimer(HeartbeatExpired, null, ServerHeartbeatInterval, ServerHeartbeatInterval);
Debug.Console(2, this, "Heartbeat Timer Started.");
ServerHeartbeat.Reset(ServerHeartbeatInterval, ServerHeartbeatInterval);
StartHearbeatTimer(ServerHeartbeatInterval, ServerHeartbeatInterval);
}
else if (type == "/system/heartbeat")
{
ServerHeartbeat.Reset(ServerHeartbeatInterval, ServerHeartbeatInterval);
Debug.Console(2, this, "Heartbeat Timer Reset.");
StartHearbeatTimer(ServerHeartbeatInterval, ServerHeartbeatInterval);
}
else if (type == "close")
{
@@ -366,7 +374,7 @@ namespace PepperDash.Essentials
{
PushedActions.Add(type, new CTimer(o =>
{
(action as Action<bool>)(false);
(action as PressAndHoldAction)(false);
PushedActions.Remove(type);
}, null, ButtonHeartbeatInterval, ButtonHeartbeatInterval));
}
@@ -383,7 +391,7 @@ namespace PepperDash.Essentials
}
case "false":
{
if (!PushedActions.ContainsKey(type))
if (PushedActions.ContainsKey(type))
{
PushedActions[type].Stop();
PushedActions.Remove(type);
@@ -392,7 +400,7 @@ namespace PepperDash.Essentials
}
}
(action as Action<bool>)(stateString == "true");
(action as PressAndHoldAction)(stateString == "true");
}
}
else if (action is Action<bool>)

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Essentials.Core;
using PepperDash.Core;
namespace PepperDash.Essentials
{
public static class IDPadExtensions
{
public static void LinkActions(this IDPad dev, CotijaSystemController controller)
{
var prefix = string.Format(@"/device/{0}/", (dev as IKeyed).Key);
controller.AddAction(prefix + "up", new Action<bool>(dev.Up));
controller.AddAction(prefix + "down", new Action<bool>(dev.Down));
controller.AddAction(prefix + "left", new Action<bool>(dev.Left));
controller.AddAction(prefix + "right", new Action<bool>(dev.Right));
controller.AddAction(prefix + "select", new Action<bool>(dev.Select));
controller.AddAction(prefix + "menu", new Action<bool>(dev.Menu));
controller.AddAction(prefix + "exit", new Action<bool>(dev.Exit));
}
public static void UnlinkActions(this IDPad dev, CotijaSystemController controller)
{
var prefix = string.Format(@"/device/{0}/", (dev as IKeyed).Key);
controller.RemoveAction(prefix + "up");
controller.RemoveAction(prefix + "down");
controller.RemoveAction(prefix + "left");
controller.RemoveAction(prefix + "right");
controller.RemoveAction(prefix + "select");
controller.RemoveAction(prefix + "menu");
controller.RemoveAction(prefix + "exit");
}
}
}