mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-06 08:16:11 +00:00
Fixed SetStringSigAction stack overflow ;-); Added DDVC room bridge class with basic actions attached and messages prepared
This commit is contained in:
@@ -144,23 +144,47 @@ namespace PepperDash.Essentials.Core
|
||||
sig.UserObject = a;
|
||||
return sig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tl"></param>
|
||||
/// <param name="sigNum"></param>
|
||||
/// <param name="a"></param>
|
||||
/// <returns></returns>
|
||||
public static UShortOutputSig SetUShortSigAction(this BasicTriList tl, uint sigNum, Action<ushort> a)
|
||||
{
|
||||
return tl.UShortOutput[sigNum].SetUShortSigAction(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sig"></param>
|
||||
/// <param name="a"></param>
|
||||
/// <returns></returns>
|
||||
public static StringOutputSig SetStringSigAction(this StringOutputSig sig, Action<string> a)
|
||||
{
|
||||
sig.UserObject = a;
|
||||
return sig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="tl"></param>
|
||||
/// <param name="sigNum"></param>
|
||||
/// <param name="a"></param>
|
||||
/// <returns></returns>
|
||||
public static StringOutputSig SetStringSigAction(this BasicTriList tl, uint sigNum, Action<string> a)
|
||||
{
|
||||
return tl.SetStringSigAction(sigNum, a);
|
||||
return tl.StringOutput[sigNum].SetStringSigAction(a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sig"></param>
|
||||
/// <returns></returns>
|
||||
public static Sig ClearSigAction(this Sig sig)
|
||||
{
|
||||
sig.UserObject = null;
|
||||
@@ -190,6 +214,27 @@ namespace PepperDash.Essentials.Core
|
||||
tl.BooleanInput[sigNum].BoolValue = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an true-false pulse to the sig
|
||||
/// </summary>
|
||||
/// <param name="tl"></param>
|
||||
/// <param name="sigNum"></param>
|
||||
public static void PulseBool(this BasicTriList tl, uint sigNum)
|
||||
{
|
||||
tl.BooleanInput[sigNum].Pulse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a timed pulse to the sig
|
||||
/// </summary>
|
||||
/// <param name="tl"></param>
|
||||
/// <param name="sigNum"></param>
|
||||
/// <param name="ms"></param>
|
||||
public static void PulseBool(this BasicTriList tl, uint sigNum, int ms)
|
||||
{
|
||||
tl.BooleanInput[sigNum].Pulse(ms);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to set the value of a ushort Sig on TriList
|
||||
/// </summary>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
void Load()
|
||||
{
|
||||
LoadDevices();
|
||||
LoadTieLines();
|
||||
LoadRooms();
|
||||
LoadLogoServer();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires up a logo server if not already running
|
||||
/// </summary>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@
|
||||
<Compile Include="Room\Config\EssentialsHuddleVtc1PropertiesConfig.cs" />
|
||||
<Compile Include="Room\Config\EssentialsRoomEmergencyConfig.cs" />
|
||||
<Compile Include="Room\Cotija\CotijaConfig.cs" />
|
||||
<Compile Include="Room\Cotija\RoomBridges\CotijaDdvc01RoomBridge.cs" />
|
||||
<Compile Include="Room\Cotija\RoomBridges\CotijaEssentialsHuddleSpaceRoomBridge.cs" />
|
||||
<Compile Include="Room\Cotija\DeviceTypeInterfaces\IChannelExtensions.cs" />
|
||||
<Compile Include="Room\Cotija\DeviceTypeInterfaces\IColorExtensions.cs" />
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user