mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 05:05:00 +00:00
Fixed SetStringSigAction stack overflow ;-); Added DDVC room bridge class with basic actions attached and messages prepared
This commit is contained in:
@@ -9,9 +9,22 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace PepperDash.Essentials
|
||||
{
|
||||
public class CotijaConfig : DeviceConfig
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CotijaConfig
|
||||
{
|
||||
[JsonProperty("serverUrl")]
|
||||
public string ServerUrl { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CotijaDdvc01RoomBridgePropertiesConfig
|
||||
{
|
||||
[JsonProperty("eiscId")]
|
||||
public string EiscId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ namespace PepperDash.Essentials
|
||||
/// </summary>
|
||||
/// <param name="room">room from which the message originates</param>
|
||||
/// <param name="o">object to be serialized and sent in post body</param>
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 1
|
||||
/// </summary>
|
||||
public const uint GetStatus = 1;
|
||||
/// <summary>
|
||||
/// 2
|
||||
/// </summary>
|
||||
public const uint RoomIsOn = 2;
|
||||
/// <summary>
|
||||
/// 3
|
||||
/// </summary>
|
||||
public const uint DefaultSourcePress = 3;
|
||||
/// <summary>
|
||||
/// 4
|
||||
/// </summary>
|
||||
public const uint MasterVolumeIsMuted = 4;
|
||||
/// <summary>
|
||||
/// 4
|
||||
/// </summary>
|
||||
public const uint MasterVolumeMuteToggle = 4;
|
||||
/// <summary>
|
||||
/// 21
|
||||
/// </summary>
|
||||
public const uint ShutdownStart = 21;
|
||||
/// <summary>
|
||||
/// 22
|
||||
/// </summary>
|
||||
public const uint ShutdownEnd = 22;
|
||||
/// <summary>
|
||||
/// 23
|
||||
/// </summary>
|
||||
public const uint ShutdownCancel = 23;
|
||||
}
|
||||
|
||||
public class UshortJoin
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public const uint MasterVolumeLevel = 4;
|
||||
}
|
||||
|
||||
public class StringJoin
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finish wiring up everything after all devices are created
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Setup the actions to take place on various incoming API calls
|
||||
/// </summary>
|
||||
void SetupFunctions()
|
||||
{
|
||||
Parent.AddAction(@"/room/room1/status", new Action(() =>
|
||||
EISC.PulseBool(BoolJoin.GetStatus)));
|
||||
Parent.AddAction(@"/room/room1/source", new Action<SourceSelectMessageContent>(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<ushort>(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)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Links feedbacks to whatever is gonna happen!
|
||||
/// </summary>
|
||||
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
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper for posting status message
|
||||
/// </summary>
|
||||
/// <param name="contentObject">The contents of the content object</param>
|
||||
void PostStatusMessage(object contentObject)
|
||||
{
|
||||
Parent.PostToServer(JObject.FromObject(new
|
||||
{
|
||||
type = "/room/status/",
|
||||
content = contentObject
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user