Merge from feature/fusion-nyc

This commit is contained in:
Heath Volmer
2017-08-28 15:02:11 -05:00
13 changed files with 2375 additions and 159 deletions

View File

@@ -16,6 +16,9 @@ namespace PepperDash.Essentials.Core.Config
[JsonProperty("key")]
public string Key { get; set; }
[JsonProperty("uid")]
public int Uid { get; set; }
[JsonProperty("name")]
public string Name { get; set; }

View File

@@ -30,8 +30,12 @@ namespace PepperDash.Essentials.Core
public DateTime UsageStartTime { get; protected set; }
public DateTime UsageEndTime { get; protected set; }
public UsageTracking()
public Device Parent { get; private set; }
public UsageTracking(Device parent)
{
Parent = parent;
InUseTracker = new InUseTracking();
InUseTracker.InUseFeedback.OutputChange +=new EventHandler<EventArgs>(InUseFeedback_OutputChange);
@@ -63,16 +67,26 @@ namespace PepperDash.Essentials.Core
/// </summary>
public void EndDeviceUsage()
{
UsageEndTime = DateTime.Now;
var timeUsed = UsageEndTime - UsageStartTime;
var handler = DeviceUsageEnded;
if (handler != null)
try
{
Debug.Console(1, "Device Usage Ended at {0}. In use for {1} minutes.", UsageEndTime, timeUsed.Minutes);
handler(this, new DeviceUsageEventArgs() { UsageEndTime = UsageEndTime, MinutesUsed = timeUsed.Minutes });
UsageEndTime = DateTime.Now;
if (UsageStartTime != null)
{
var timeUsed = UsageEndTime - UsageStartTime;
var handler = DeviceUsageEnded;
if (handler != null)
{
Debug.Console(1, "Device Usage Ended for: {0} at {1}. In use for {2} minutes.", Parent.Name, UsageEndTime, timeUsed.Minutes);
handler(this, new DeviceUsageEventArgs() { UsageEndTime = UsageEndTime, MinutesUsed = timeUsed.Minutes });
}
}
}
catch (Exception e)
{
Debug.Console(1, "Error ending device usage: {0}", e);
}
}
}

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
public interface IUsageTracking
{
UsageTracking UsageTracker { get; set; }
}
//public static class IUsageTrackingExtensions
//{
// public static void EnableUsageTracker(this IUsageTracking device)
// {
// device.UsageTracker = new UsageTracking();
// }
//}
public class UsageTracking
{
public event EventHandler<DeviceUsageEventArgs> DeviceUsageEnded;
public InUseTracking InUseTracker { get; protected set; }
public bool UsageIsTracked { get; set; }
public DateTime UsageStartTime { get; protected set; }
public DateTime UsageEndTime { get; protected set; }
public Device Parent { get; private set; }
public UsageTracking(Device parent)
{
Parent = parent;
InUseTracker = new InUseTracking();
InUseTracker.InUseFeedback.OutputChange +=new EventHandler<EventArgs>(InUseFeedback_OutputChange);
}
void InUseFeedback_OutputChange(object sender, EventArgs e)
{
if(InUseTracker.InUseFeedback.BoolValue)
{
StartDeviceUsage();
}
else
{
EndDeviceUsage();
}
}
/// <summary>
/// Stores the usage start time
/// </summary>
public void StartDeviceUsage()
{
UsageStartTime = DateTime.Now;
}
/// <summary>
/// Calculates the difference between the usage start and end times, gets the total minutes used and fires an event to pass that info to a consumer
/// </summary>
public void EndDeviceUsage()
{
try
{
UsageEndTime = DateTime.Now;
if (UsageStartTime != null)
{
var timeUsed = UsageEndTime - UsageStartTime;
var handler = DeviceUsageEnded;
if (handler != null)
{
Debug.Console(1, "Device Usage Ended for: {0} at {1}. In use for {2} minutes.", Parent.Name, UsageEndTime, timeUsed.Minutes);
handler(this, new DeviceUsageEventArgs() { UsageEndTime = UsageEndTime, MinutesUsed = timeUsed.Minutes });
}
}
}
catch (Exception e)
{
<<<<<<< HEAD
Debug.Console(1, "Device Usage Ended at {0}. In use for {1} minutes.", UsageEndTime, timeUsed.Minutes);
handler(this, new DeviceUsageEventArgs() { UsageEndTime = UsageEndTime, MinutesUsed = timeUsed.Minutes });
=======
Debug.Console(1, "Error ending device usage: {0}", e);
>>>>>>> origin/feature/fusion-nyu
}
}
}
public class DeviceUsageEventArgs : EventArgs
{
public DateTime UsageEndTime { get; set; }
public int MinutesUsed { get; set; }
}
}

View File

@@ -53,8 +53,21 @@ namespace PepperDash.Essentials.Core
IsWarmingUpFeedback = new BoolFeedback(CommonBoolCue.IsWarmingUp, IsWarmingUpFeedbackFunc);
InputPorts = new RoutingPortCollection<RoutingInputPort>();
PowerIsOnFeedback.OutputChange += new EventHandler<EventArgs>(PowerIsOnFeedback_OutputChange);
}
void PowerIsOnFeedback_OutputChange(object sender, EventArgs e)
{
if (UsageTracker != null)
{
if (PowerIsOnFeedback.BoolValue)
UsageTracker.StartDeviceUsage();
else
UsageTracker.EndDeviceUsage();
}
}
public abstract void PowerOn();
public abstract void PowerOff();
public abstract void PowerToggle();

View File

@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DM;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.DM
{
public class DmCardAudioOutputController : IBasicVolumeWithFeedback
{
public Audio.Output Output { get; private set; }
public IntFeedback VolumeLevelFeedback { get; private set; }
public BoolFeedback MuteFeedback { get; private set; }
ushort PreMuteVolumeLevel;
bool IsMuted;
public DmCardAudioOutputController(Audio.Output output)
{
Output = output;
VolumeLevelFeedback = new IntFeedback(() => Output.VolumeFeedback.UShortValue);
MuteFeedback = new BoolFeedback(() => IsMuted);
}
#region IBasicVolumeWithFeedback Members
/// <summary>
///
/// </summary>
public void MuteOff()
{
SetVolume(PreMuteVolumeLevel);
IsMuted = false;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void MuteOn()
{
PreMuteVolumeLevel = Output.VolumeFeedback.UShortValue;
SetVolume(0);
IsMuted = true;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void SetVolume(ushort level)
{
Debug.Console(2, "Set volume out {0}", level);
Output.Volume.UShortValue = level;
}
/// <summary>
///
/// </summary>
internal void VolumeEventFromChassis()
{
VolumeLevelFeedback.FireUpdate();
}
#endregion
#region IBasicVolumeControls Members
/// <summary>
///
/// </summary>
public void MuteToggle()
{
if (IsMuted)
MuteOff();
else
MuteOn();
}
/// <summary>
///
/// </summary>
public void VolumeDown(bool pressRelease)
{
if (pressRelease)
<<<<<<< HEAD
{
var remainingRatio = Output.Volume.UShortValue / 65535;
Output.Volume.CreateRamp(0, (uint)(400 * remainingRatio));
}
=======
Output.Volume.CreateRamp(0, 400);
>>>>>>> origin/feature/fusion-nyu
else
Output.Volume.StopRamp();
}
/// <summary>
///
/// </summary>
public void VolumeUp(bool pressRelease)
{
if (pressRelease)
{
var remainingRatio = (65535 - Output.Volume.UShortValue) / 65535;
Output.Volume.CreateRamp(65535, 400);
}
else
Output.Volume.StopRamp();
}
#endregion
}
}

View File

@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DM;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.DM
{
public class DmCardAudioOutputController : IBasicVolumeWithFeedback
{
public Audio.Output Output { get; private set; }
public IntFeedback VolumeLevelFeedback { get; private set; }
public BoolFeedback MuteFeedback { get; private set; }
ushort PreMuteVolumeLevel;
bool IsMuted;
public DmCardAudioOutputController(Audio.Output output)
{
Output = output;
VolumeLevelFeedback = new IntFeedback(() => Output.VolumeFeedback.UShortValue);
MuteFeedback = new BoolFeedback(() => IsMuted);
}
#region IBasicVolumeWithFeedback Members
/// <summary>
///
/// </summary>
public void MuteOff()
{
SetVolume(PreMuteVolumeLevel);
IsMuted = false;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void MuteOn()
{
PreMuteVolumeLevel = Output.VolumeFeedback.UShortValue;
SetVolume(0);
IsMuted = true;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void SetVolume(ushort level)
{
Debug.Console(2, "Set volume out {0}", level);
Output.Volume.UShortValue = level;
}
/// <summary>
///
/// </summary>
internal void VolumeEventFromChassis()
{
VolumeLevelFeedback.FireUpdate();
}
#endregion
#region IBasicVolumeControls Members
/// <summary>
///
/// </summary>
public void MuteToggle()
{
if (IsMuted)
MuteOff();
else
MuteOn();
}
/// <summary>
///
/// </summary>
public void VolumeDown(bool pressRelease)
{
if (pressRelease)
<<<<<<< HEAD
{
var remainingRatio = Output.Volume.UShortValue / 65535;
Output.Volume.CreateRamp(0, (uint)(400 * remainingRatio));
}
=======
Output.Volume.CreateRamp(0, 400);
>>>>>>> origin/feature/fusion-nyu
else
Output.Volume.StopRamp();
}
/// <summary>
///
/// </summary>
public void VolumeUp(bool pressRelease)
{
if (pressRelease)
{
var remainingRatio = (65535 - Output.Volume.UShortValue) / 65535;
Output.Volume.CreateRamp(65535, 400);
}
else
Output.Volume.StopRamp();
}
#endregion
}
}

View File

@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DM;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.DM
{
public class DmCardAudioOutputController : IBasicVolumeWithFeedback
{
public Audio.Output Output { get; private set; }
public IntFeedback VolumeLevelFeedback { get; private set; }
public BoolFeedback MuteFeedback { get; private set; }
ushort PreMuteVolumeLevel;
bool IsMuted;
public DmCardAudioOutputController(Audio.Output output)
{
Output = output;
VolumeLevelFeedback = new IntFeedback(() => Output.VolumeFeedback.UShortValue);
MuteFeedback = new BoolFeedback(() => IsMuted);
}
#region IBasicVolumeWithFeedback Members
/// <summary>
///
/// </summary>
public void MuteOff()
{
SetVolume(PreMuteVolumeLevel);
IsMuted = false;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void MuteOn()
{
PreMuteVolumeLevel = Output.VolumeFeedback.UShortValue;
SetVolume(0);
IsMuted = true;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void SetVolume(ushort level)
{
Debug.Console(2, "Set volume out {0}", level);
Output.Volume.UShortValue = level;
}
/// <summary>
///
/// </summary>
internal void VolumeEventFromChassis()
{
VolumeLevelFeedback.FireUpdate();
}
#endregion
#region IBasicVolumeControls Members
/// <summary>
///
/// </summary>
public void MuteToggle()
{
if (IsMuted)
MuteOff();
else
MuteOn();
}
/// <summary>
///
/// </summary>
public void VolumeDown(bool pressRelease)
{
if (pressRelease)
Output.Volume.CreateRamp(0, 400);
#warning SCALE THIS RAMP
else
Output.Volume.StopRamp();
}
/// <summary>
///
/// </summary>
public void VolumeUp(bool pressRelease)
{
if (pressRelease)
Output.Volume.CreateRamp(65535, 400);
else
Output.Volume.StopRamp();
}
#endregion
}
}

View File

@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DM;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.DM
{
public class DmCardAudioOutputController : IBasicVolumeWithFeedback
{
public Audio.Output Output { get; private set; }
public IntFeedback VolumeLevelFeedback { get; private set; }
public BoolFeedback MuteFeedback { get; private set; }
ushort PreMuteVolumeLevel;
bool IsMuted;
public DmCardAudioOutputController(Audio.Output output)
{
Output = output;
VolumeLevelFeedback = new IntFeedback(() => Output.VolumeFeedback.UShortValue);
MuteFeedback = new BoolFeedback(() => IsMuted);
}
#region IBasicVolumeWithFeedback Members
/// <summary>
///
/// </summary>
public void MuteOff()
{
SetVolume(PreMuteVolumeLevel);
IsMuted = false;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void MuteOn()
{
PreMuteVolumeLevel = Output.VolumeFeedback.UShortValue;
SetVolume(0);
IsMuted = true;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void SetVolume(ushort level)
{
Debug.Console(2, "Set volume out {0}", level);
Output.Volume.UShortValue = level;
}
/// <summary>
///
/// </summary>
internal void VolumeEventFromChassis()
{
VolumeLevelFeedback.FireUpdate();
}
#endregion
#region IBasicVolumeControls Members
/// <summary>
///
/// </summary>
public void MuteToggle()
{
if (IsMuted)
MuteOff();
else
MuteOn();
}
/// <summary>
///
/// </summary>
public void VolumeDown(bool pressRelease)
{
if (pressRelease)
{
var remainingRatio = Output.Volume.UShortValue / 65535;
Output.Volume.CreateRamp(0, (uint)(400 * remainingRatio));
}
else
Output.Volume.StopRamp();
}
/// <summary>
///
/// </summary>
public void VolumeUp(bool pressRelease)
{
if (pressRelease)
{
var remainingRatio = (65535 - Output.Volume.UShortValue) / 65535;
Output.Volume.CreateRamp(65535, 400);
}
else
Output.Volume.StopRamp();
}
#endregion
}
}

View File

@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DM;
using PepperDash.Core;
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.DM
{
public class DmCardAudioOutputController : IBasicVolumeWithFeedback
{
public Audio.Output Output { get; private set; }
public IntFeedback VolumeLevelFeedback { get; private set; }
public BoolFeedback MuteFeedback { get; private set; }
ushort PreMuteVolumeLevel;
bool IsMuted;
public DmCardAudioOutputController(Audio.Output output)
{
Output = output;
VolumeLevelFeedback = new IntFeedback(() => Output.VolumeFeedback.UShortValue);
MuteFeedback = new BoolFeedback(() => IsMuted);
}
#region IBasicVolumeWithFeedback Members
/// <summary>
///
/// </summary>
public void MuteOff()
{
SetVolume(PreMuteVolumeLevel);
IsMuted = false;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void MuteOn()
{
PreMuteVolumeLevel = Output.VolumeFeedback.UShortValue;
SetVolume(0);
IsMuted = true;
MuteFeedback.FireUpdate();
}
/// <summary>
///
/// </summary>
public void SetVolume(ushort level)
{
Debug.Console(2, "Set volume out {0}", level);
Output.Volume.UShortValue = level;
}
/// <summary>
///
/// </summary>
internal void VolumeEventFromChassis()
{
VolumeLevelFeedback.FireUpdate();
}
#endregion
#region IBasicVolumeControls Members
/// <summary>
///
/// </summary>
public void MuteToggle()
{
if (IsMuted)
MuteOff();
else
MuteOn();
}
/// <summary>
///
/// </summary>
public void VolumeDown(bool pressRelease)
{
if (pressRelease)
Output.Volume.CreateRamp(0, 400);
else
Output.Volume.StopRamp();
}
/// <summary>
///
/// </summary>
public void VolumeUp(bool pressRelease)
{
if (pressRelease)
Output.Volume.CreateRamp(65535, 400);
else
Output.Volume.StopRamp();
}
#endregion
}
}

View File

@@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.Fusion;
using PepperDash.Core;
namespace PepperDash.Essentials.Fusion
{
@@ -16,47 +19,144 @@ namespace PepperDash.Essentials.Fusion
public string RoomName { get; set; }
public uint IpId { get; set; }
public string RoomGuid { get; set; }
public List<FusionAsset> StaticAssets { get; set; }
public FusionOccupancySensorAsset OccupancyAsset { get; set; }
public Dictionary<int, FusionAsset> StaticAssets { get; set; }
public FusionRoomGuids()
{
StaticAssets = new List<FusionAsset>();
StaticAssets = new Dictionary<int, FusionAsset>();
OccupancyAsset = new FusionOccupancySensorAsset();
}
public FusionRoomGuids(string roomName, uint ipId, string roomGuid, List<FusionAsset> staticAssets)
public FusionRoomGuids(string roomName, uint ipId, string roomGuid, Dictionary<int, FusionAsset> staticAssets)
{
RoomName = roomName;
IpId = ipId;
RoomGuid = roomGuid;
StaticAssets = new List<FusionAsset>(staticAssets);
StaticAssets = staticAssets;
OccupancyAsset = new FusionOccupancySensorAsset();
}
public FusionRoomGuids(string roomName, uint ipId, string roomGuid, Dictionary<int, FusionAsset> staticAssets, FusionOccupancySensorAsset occAsset)
{
RoomName = roomName;
IpId = ipId;
RoomGuid = roomGuid;
StaticAssets = staticAssets;
OccupancyAsset = occAsset;
}
/// <summary>
/// Generates a new room GUID prefixed by the program slot number and NIC MAC address
/// </summary>
/// <param name="progSlot"></param>
/// <param name="mac"></param>
public string GenerateNewRoomGuid(uint progSlot, string mac)
{
Guid roomGuid = Guid.NewGuid();
return string.Format("{0}-{1}-{2}", progSlot, mac, roomGuid.ToString());
}
/// <summary>
/// Adds an asset to the StaticAssets collection and returns the new asset
/// </summary>
/// <param name="room"></param>
/// <param name="uid"></param>
/// <param name="assetName"></param>
/// <param name="type"></param>
/// <param name="instanceId"></param>
/// <returns></returns>
public FusionAsset AddStaticAsset(FusionRoom room, int uid, string assetName, string type, string instanceId)
{
var slotNum = GetNextAvailableAssetNumber(room);
Debug.Console(2, "Adding Fusion Asset: {0} of Type: {1} at Slot Number: {2} with GUID: {3}", assetName, type, slotNum, instanceId);
var tempAsset = new FusionAsset(slotNum, assetName, type, instanceId);
StaticAssets.Add(uid, tempAsset);
return tempAsset;
}
/// <summary>
/// Returns the next available slot number in the Fusion UserConfigurableAssetDetails collection
/// </summary>
/// <param name="room"></param>
/// <returns></returns>
public static uint GetNextAvailableAssetNumber(FusionRoom room)
{
uint slotNum = 0;
foreach (var item in room.UserConfigurableAssetDetails)
{
if(item.Number > slotNum)
slotNum = item.Number;
}
if (slotNum < 5)
{
slotNum = 5;
}
else
slotNum = slotNum + 1;
Debug.Console(2, "#Next available fusion asset number is: {0}", slotNum);
return slotNum;
}
}
public class FusionOccupancySensorAsset
{
// SlotNumber fixed at 4
public uint SlotNumber { get { return 4; } }
public string Name { get { return "Occupancy Sensor"; } }
public eAssetType Type { get; set; }
public string InstanceId { get; set; }
public FusionOccupancySensorAsset()
{
}
public FusionOccupancySensorAsset(eAssetType type)
{
Type = type;
InstanceId = Guid.NewGuid().ToString();
}
}
public class FusionAsset
{
public uint Number { get; set; }
public uint SlotNumber { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string InstanceID { get; set; }
public string Type { get; set; }
public string InstanceId { get;set; }
public FusionAsset()
{
}
public FusionAsset(uint slotNum, string assetName, string type, string instanceID)
public FusionAsset(uint slotNum, string assetName, string type, string instanceId)
{
Number = slotNum;
SlotNumber = slotNum;
Name = assetName;
Type = type;
if (string.IsNullOrEmpty(instanceID))
if (string.IsNullOrEmpty(instanceId))
{
InstanceID = Guid.NewGuid().ToString();
InstanceId = Guid.NewGuid().ToString();
}
else
{
InstanceID = instanceID;
InstanceId = instanceId;
}
}
}

View File

@@ -34,7 +34,7 @@ namespace PepperDash.Essentials.Fusion
Dictionary<Device, BoolInputSig> SourceToFeedbackSigs =
new Dictionary<Device, BoolInputSig>();
BooleanSigData OccupancyStatusSig;
//BooleanSigData OccupancyStatusSig;
StatusMonitorCollection ErrorMessageRollUp;
@@ -103,7 +103,9 @@ namespace PepperDash.Essentials.Fusion
public long PushNotificationTimeout = 5000;
List<FusionAsset> FusionAssets;
Dictionary<int, FusionAsset> FusionStaticAssets;
FusionOccupancySensorAsset FusionOccSensor;
//ScheduleResponseEvent NextMeeting;
@@ -115,7 +117,7 @@ namespace PepperDash.Essentials.Fusion
IpId = ipId;
FusionAssets = new List<FusionAsset>();
FusionStaticAssets = new Dictionary<int, FusionAsset>();
GUIDs = new FusionRoomGuids();
@@ -133,11 +135,7 @@ namespace PepperDash.Essentials.Fusion
}
else
{
IpId = ipId;
Guid roomGuid = Guid.NewGuid();
GUIDs.RoomGuid = string.Format("{0}-{1}-{2}", slot, mac, roomGuid.ToString());
GUIDs = new FusionRoomGuids(Room.Name, ipId, GUIDs.GenerateNewRoomGuid(slot, mac), FusionStaticAssets);
}
CreateSymbolAndBasicSigs(IpId);
@@ -145,7 +143,7 @@ namespace PepperDash.Essentials.Fusion
SetUpCommunitcationMonitors();
SetUpDisplay();
SetUpError();
SetUpOccupancy();
//SetUpOccupancy();
// Make it so!
FusionRVI.GenerateFileForAllFusionDevices();
@@ -154,7 +152,7 @@ namespace PepperDash.Essentials.Fusion
}
/// <summary>
/// Generates the guid file in NVRAM
/// Generates the guid file in NVRAM. If the file already exists it will be overwritten.
/// </summary>
/// <param name="filePath">path for the file</param>
void GenerateGuidFile(string filePath)
@@ -176,7 +174,10 @@ namespace PepperDash.Essentials.Fusion
Debug.Console(1, this, "Writing GUIDs to file");
GUIDs = new FusionRoomGuids(Room.Name, IpId, RoomGuid, FusionAssets);
if (FusionOccSensor == null)
GUIDs = new FusionRoomGuids(Room.Name, IpId, RoomGuid, FusionStaticAssets);
else
GUIDs = new FusionRoomGuids(Room.Name, IpId, RoomGuid, FusionStaticAssets, FusionOccSensor);
var JSON = JsonConvert.SerializeObject(GUIDs, Newtonsoft.Json.Formatting.Indented);
@@ -229,7 +230,7 @@ namespace PepperDash.Essentials.Fusion
IpId = GUIDs.IpId;
FusionAssets = GUIDs.StaticAssets;
FusionStaticAssets = GUIDs.StaticAssets;
}
@@ -237,9 +238,9 @@ namespace PepperDash.Essentials.Fusion
Debug.Console(1, this, "\nRoom Name: {0}\nIPID: {1:x}\n RoomGuid: {2}", Room.Name, IpId, RoomGuid);
foreach (FusionAsset asset in FusionAssets)
foreach (KeyValuePair<int, FusionAsset> item in FusionStaticAssets)
{
Debug.Console(1, this, "\nAsset Name: {0}\nAsset No: {1}\n Guid: {2}", asset.Name, asset.Number, asset.InstanceID);
Debug.Console(1, this, "\nAsset Name: {0}\nAsset No: {1}\n Guid: {2}", item.Value.Name, item.Value.SlotNumber, item.Value.InstanceId);
}
}
catch (Exception e)
@@ -291,6 +292,8 @@ namespace PepperDash.Essentials.Fusion
GetProcessorEthernetValues();
GetSystemInfo();
GetProcessorInfo();
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
@@ -306,9 +309,14 @@ namespace PepperDash.Essentials.Fusion
void GetSystemInfo()
{
SystemName.InputSig.StringValue = Room.Name;
Model.InputSig.StringValue = InitialParametersClass.ControllerPromptName;
//SystemName.InputSig.StringValue = Room.Name;
//Model.InputSig.StringValue = InitialParametersClass.ControllerPromptName;
//SerialNumber.InputSig.StringValue = InitialParametersClass.
string response = string.Empty;
var systemReboot = FusionRoom.CreateOffsetBoolSig(74, "Processor - Reboot", eSigIoMask.OutputSigOnly);
systemReboot.OutputSig.SetSigFalseAction(() => CrestronConsole.SendControlSystemCommand("reboot", ref response));
}
void GetProcessorEthernetValues()
@@ -367,15 +375,15 @@ namespace PepperDash.Essentials.Fusion
Firmware.InputSig.StringValue = InitialParametersClass.FirmwareVersion;
var programs = ProcessorProgReg.GetProcessorProgReg();
//var programs = ProcessorProgReg.GetProcessorProgReg();
for (int i = 1; i < Global.ControlSystem.NumProgramsSupported; i++)
{
var join = 62 + i;
var progNum = i + 1;
if (programs[i].Exists)
Program[i].InputSig.StringValue = programs[i].Name;
}
//for (int i = 1; i < Global.ControlSystem.NumProgramsSupported; i++)
//{
// var join = 62 + i;
// var progNum = i + 1;
// if (programs[i].Exists)
// Program[i].InputSig.StringValue = programs[i].Name;
//}
}
@@ -497,7 +505,7 @@ namespace PepperDash.Essentials.Fusion
Debug.Console(1, this, "No meeting in progress. Unable to modify end time.");
return;
}
#warning Need to add logic to properly extend from the current time. See S+ module for reference.
if (extendMinutes > -1)
{
if(extendMinutes > 0)
@@ -828,7 +836,7 @@ namespace PepperDash.Essentials.Fusion
uint i = 1;
foreach (var kvp in setTopBoxes)
{
TryAddRouteActionSigs("Source - TV " + i, 115 + i, kvp.Key, kvp.Value.SourceDevice);
TryAddRouteActionSigs("Display 1 - Source TV " + i, 188 + i, kvp.Key, kvp.Value.SourceDevice);
i++;
if (i > 5) // We only have five spots
break;
@@ -838,7 +846,7 @@ namespace PepperDash.Essentials.Fusion
i = 1;
foreach (var kvp in discPlayers)
{
TryAddRouteActionSigs("Source - DVD " + i, 120 + i, kvp.Key, kvp.Value.SourceDevice);
TryAddRouteActionSigs("Display 1 - Source DVD " + i, 181 + i, kvp.Key, kvp.Value.SourceDevice);
i++;
if (i > 5) // We only have five spots
break;
@@ -848,7 +856,7 @@ namespace PepperDash.Essentials.Fusion
i = 1;
foreach (var kvp in laptops)
{
TryAddRouteActionSigs("Source - Laptop " + i, 100 + i, kvp.Key, kvp.Value.SourceDevice);
TryAddRouteActionSigs("Display 1 - Source Laptop " + i, 166 + i, kvp.Key, kvp.Value.SourceDevice);
i++;
if (i > 10) // We only have ten spots???
break;
@@ -860,7 +868,7 @@ namespace PepperDash.Essentials.Fusion
if (usageDevice != null)
{
usageDevice.UsageTracker = new UsageTracking();
usageDevice.UsageTracker = new UsageTracking(usageDevice as Device);
usageDevice.UsageTracker.UsageIsTracked = true;
usageDevice.UsageTracker.DeviceUsageEnded += new EventHandler<DeviceUsageEventArgs>(UsageTracker_DeviceUsageEnded);
}
@@ -880,26 +888,28 @@ namespace PepperDash.Essentials.Fusion
/// <param name="sender"></param>
/// <param name="e"></param>
void UsageTracker_DeviceUsageEnded(object sender, DeviceUsageEventArgs e)
{
var device = sender as Device;
{
var deviceTracker = sender as UsageTracking;
var configDevice = ConfigReader.ConfigObject.Devices.Where(d => d.Key.Equals(device.Key));
var configDevice = ConfigReader.ConfigObject.Devices.Where(d => d.Key.Equals(deviceTracker.Parent));
string group = ConfigReader.GetGroupForDeviceKey(device.Key);
string group = ConfigReader.GetGroupForDeviceKey(deviceTracker.Parent.Key);
string currentMeetingId = "";
string currentMeetingId = "-";
if (CurrentMeeting != null)
currentMeetingId = CurrentMeeting.MeetingID;
//String Format: "USAGE||[Date YYYY-MM-DD]||[Time HH-mm-ss]||TIME||[Asset_Type]||[Asset_Name]||[Minutes_used]||[Asset_ID]||[Meeting_ID]"
// [Asset_ID] property does not appear to be used in Crestron SSI examples. They are sending "-" instead so that's what is replicated here
string deviceUsage = string.Format("USAGE||{0}||{1}||TIME||{2}||{3}||{4}||{5}||{6})", e.UsageEndTime.ToString("YYYY-MM-DD"), e.UsageEndTime.ToString("HH-mm-ss"),
group, device.Name, e.MinutesUsed, "-", currentMeetingId);
string deviceUsage = string.Format("USAGE||{0}||{1}||TIME||{2}||{3}||-||{4}||-||{5}||{6}||\r\n", e.UsageEndTime.ToString("yyyy-MM-dd"), e.UsageEndTime.ToString("HH:mm:ss"),
group, deviceTracker.Parent.Name, e.MinutesUsed, "-", currentMeetingId);
Debug.Console(1, this, "Device usage for: {0} ended at {1}. In use for {2} minutes", device.Name, e.UsageEndTime, e.MinutesUsed);
Debug.Console(1, this, "Device usage for: {0} ended at {1}. In use for {2} minutes", deviceTracker.Parent.Name, e.UsageEndTime, e.MinutesUsed);
FusionRoom.DeviceUsage.InputSig.StringValue = deviceUsage;
Debug.Console(1, this, "Device usage string: {0}", deviceUsage);
}
@@ -952,8 +962,7 @@ namespace PepperDash.Essentials.Fusion
if (attrNum > 10)
continue;
attrName = "Online - Touch Panel " + attrNum;
attrNum += 200;
#warning should this be 150
attrNum += 150;
}
// add xpanel here
@@ -963,7 +972,6 @@ namespace PepperDash.Essentials.Fusion
continue;
attrName = "Online - XPanel " + attrNum;
attrNum += 160;
#warning should this be 160
}
//else
@@ -972,8 +980,7 @@ namespace PepperDash.Essentials.Fusion
if (attrNum > 10)
continue;
attrName = "Online - Display " + attrNum;
attrNum += 240;
#warning should this be 170
attrNum += 170;
}
//else if (dev is DvdDeviceBase)
//{
@@ -1003,68 +1010,73 @@ namespace PepperDash.Essentials.Fusion
void SetUpDisplay()
{
//Setup Display Usage Monitoring
var displays = DeviceManager.AllDevices.Where(d => d is DisplayBase);
#warning should work for now in single room systems but will grab all devices regardless of room assignment. In multi-room systems, this will need to be handled differently.
foreach (DisplayBase display in displays)
try
{
display.UsageTracker = new UsageTracking();
display.UsageTracker.UsageIsTracked = true;
display.UsageTracker.DeviceUsageEnded += new EventHandler<DeviceUsageEventArgs>(UsageTracker_DeviceUsageEnded);
//Setup Display Usage Monitoring
var displays = DeviceManager.AllDevices.Where(d => d is DisplayBase);
// Consider updating this in multiple display systems
foreach (DisplayBase display in displays)
{
display.UsageTracker = new UsageTracking(display);
display.UsageTracker.UsageIsTracked = true;
display.UsageTracker.DeviceUsageEnded += new EventHandler<DeviceUsageEventArgs>(UsageTracker_DeviceUsageEnded);
}
var defaultDisplay = Room.DefaultDisplay as DisplayBase;
if (defaultDisplay == null)
{
Debug.Console(1, this, "Cannot link null display to Fusion");
return;
}
var dispPowerOnAction = new Action<bool>(b => { if (!b) defaultDisplay.PowerOn(); });
var dispPowerOffAction = new Action<bool>(b => { if (!b) defaultDisplay.PowerOff(); });
// Display to fusion room sigs
FusionRoom.DisplayPowerOn.OutputSig.UserObject = dispPowerOnAction;
FusionRoom.DisplayPowerOff.OutputSig.UserObject = dispPowerOffAction;
defaultDisplay.PowerIsOnFeedback.LinkInputSig(FusionRoom.DisplayPowerOn.InputSig);
if (defaultDisplay is IDisplayUsage)
(defaultDisplay as IDisplayUsage).LampHours.LinkInputSig(FusionRoom.DisplayUsage.InputSig);
MapDisplayToRoomJoins(1, 158, defaultDisplay);
var deviceConfig = ConfigReader.ConfigObject.Devices.FirstOrDefault(d => d.Key.Equals(defaultDisplay.Key));
//Check for existing asset in GUIDs collection
var tempAsset = new FusionAsset();
if (FusionStaticAssets.ContainsKey(deviceConfig.Uid))
{
tempAsset = FusionStaticAssets[deviceConfig.Uid];
}
else
{
// Create a new asset
tempAsset = new FusionAsset(FusionRoomGuids.GetNextAvailableAssetNumber(FusionRoom), defaultDisplay.Name, "Display", "");
FusionStaticAssets.Add(deviceConfig.Uid, tempAsset);
}
var dispAsset = FusionRoom.CreateStaticAsset(tempAsset.SlotNumber, tempAsset.Name, "Display", tempAsset.InstanceId);
dispAsset.PowerOn.OutputSig.UserObject = dispPowerOnAction;
dispAsset.PowerOff.OutputSig.UserObject = dispPowerOffAction;
defaultDisplay.PowerIsOnFeedback.LinkInputSig(dispAsset.PowerOn.InputSig);
// NO!! display.PowerIsOn.LinkComplementInputSig(dispAsset.PowerOff.InputSig);
// Use extension methods
dispAsset.TrySetMakeModel(defaultDisplay);
dispAsset.TryLinkAssetErrorToCommunication(defaultDisplay);
}
var defaultDisplay = Room.DefaultDisplay as DisplayBase;
if (defaultDisplay == null)
{
Debug.Console(1, this, "Cannot link null display to Fusion");
return;
}
var dispPowerOnAction = new Action<bool>(b => { if (!b) defaultDisplay.PowerOn(); });
var dispPowerOffAction = new Action<bool>(b => { if (!b) defaultDisplay.PowerOff(); });
// Display to fusion room sigs
FusionRoom.DisplayPowerOn.OutputSig.UserObject = dispPowerOnAction;
FusionRoom.DisplayPowerOff.OutputSig.UserObject = dispPowerOffAction;
defaultDisplay.PowerIsOnFeedback.LinkInputSig(FusionRoom.DisplayPowerOn.InputSig);
if (defaultDisplay is IDisplayUsage)
(defaultDisplay as IDisplayUsage).LampHours.LinkInputSig(FusionRoom.DisplayUsage.InputSig);
MapDisplayToRoomJoins(1, 158, defaultDisplay);
//Room.CurrentSingleSourceChange += new SourceInfoChangeHandler(Room_CurrentSingleSourceChange);
// static assets --------------- testing
// Make a display asset
string dispAssetInstanceId;
//Check for existing GUID
var tempAsset = FusionAssets.FirstOrDefault(a => a.Name.Equals("Display"));
if(tempAsset != null)
dispAssetInstanceId = tempAsset.InstanceID;
else
catch (Exception e)
{
var nextSlotNum = FusionAssets.Count + 3; //Account for slot number offset
tempAsset = new FusionAsset((uint)nextSlotNum, defaultDisplay.Name, "Display", "");
FusionAssets.Add(tempAsset);
dispAssetInstanceId = tempAsset.InstanceID;
Debug.Console(1, this, "Error setting up display in Fusion: {0}", e);
}
var dispAsset = FusionRoom.CreateStaticAsset(tempAsset.Number, defaultDisplay.Name, "Display", dispAssetInstanceId);
dispAsset.PowerOn.OutputSig.UserObject = dispPowerOnAction;
dispAsset.PowerOff.OutputSig.UserObject = dispPowerOffAction;
defaultDisplay.PowerIsOnFeedback.LinkInputSig(dispAsset.PowerOn.InputSig);
// NO!! display.PowerIsOn.LinkComplementInputSig(dispAsset.PowerOff.InputSig);
// Use extension methods
dispAsset.TrySetMakeModel(defaultDisplay);
dispAsset.TryLinkAssetErrorToCommunication(defaultDisplay);
}
@@ -1072,39 +1084,46 @@ namespace PepperDash.Essentials.Fusion
/// Maps room attributes to a display at a specified index
/// </summary>
/// <param name="index"></param>
/// <param name="display"></param>
/// <param name="display"></param>a
void MapDisplayToRoomJoins(int displayIndex, int joinOffset, DisplayBase display)
{
string displayName = string.Format("Display {0} - ", displayIndex);
var defaultDisplayPowerOn = FusionRoom.CreateOffsetBoolSig((uint)joinOffset, displayIndex + "Power On", eSigIoMask.InputOutputSig);
defaultDisplayPowerOn.OutputSig.UserObject = new Action<bool>(b => { if (!b) display.PowerOn(); });
display.PowerIsOnFeedback.LinkInputSig(defaultDisplayPowerOn.InputSig);
var defaultDisplayPowerOff = FusionRoom.CreateOffsetBoolSig((uint)joinOffset + 1, displayIndex + "Power Off", eSigIoMask.InputOutputSig);
defaultDisplayPowerOn.OutputSig.UserObject = new Action<bool>(b => { if (!b) display.PowerOff(); }); ;
display.PowerIsOnFeedback.LinkInputSig(defaultDisplayPowerOn.InputSig);
if(display == Room.DefaultDisplay)
{
var defaultDisplaySourceNone = FusionRoom.CreateOffsetBoolSig((uint)joinOffset + 8, displayIndex + "Source None", eSigIoMask.InputOutputSig);
defaultDisplaySourceNone.OutputSig.UserObject = new Action<bool>(b => { if (!b) Room.RunRouteAction("$off"); }); ;
display.PowerIsOnFeedback.LinkInputSig(defaultDisplaySourceNone.InputSig);
// Display volume
var defaultDisplayVolume = FusionRoom.CreateOffsetUshortSig(50, "Volume - Fader01", eSigIoMask.InputOutputSig);
defaultDisplayVolume.OutputSig.UserObject = new Action<ushort>(b => (display as IBasicVolumeWithFeedback).SetVolume(b));
(display as IBasicVolumeWithFeedback).VolumeLevelFeedback.LinkInputSig(defaultDisplayVolume.InputSig);
var dict = ConfigReader.ConfigObject.GetSourceListForKey(Room.SourceListKey);
// Power on
var defaultDisplayPowerOn = FusionRoom.CreateOffsetBoolSig((uint)joinOffset, displayName + "Power On", eSigIoMask.InputOutputSig);
defaultDisplayPowerOn.OutputSig.UserObject = new Action<bool>(b => { if (!b) display.PowerOn(); });
display.PowerIsOnFeedback.LinkInputSig(defaultDisplayPowerOn.InputSig);
foreach (var item in dict)
{
if(item.Key != "roomOff")
{
var defaultDisplaySource = FusionRoom.CreateOffsetBoolSig((uint)joinOffset + (uint)item.Value.Order + 9 , string.Format("{0}Source {1}", displayIndex, item.Value.Order), eSigIoMask.InputOutputSig);
defaultDisplaySource.OutputSig.UserObject = new Action<bool>(b => { if (!b) Room.RunRouteAction(item.Value.SourceKey); }); ;
// Power Off
var defaultDisplayPowerOff = FusionRoom.CreateOffsetBoolSig((uint)joinOffset + 1, displayName + "Power Off", eSigIoMask.InputOutputSig);
defaultDisplayPowerOn.OutputSig.UserObject = new Action<bool>(b => { if (!b) display.PowerOff(); }); ;
display.PowerIsOnFeedback.LinkInputSig(defaultDisplayPowerOn.InputSig);
#warning Figure out how to link these sigs together
//defaultDisplaySource.InputSig = Source[item.Value.Order].InputSig;
}
// Current Source
var defaultDisplaySourceNone = FusionRoom.CreateOffsetBoolSig((uint)joinOffset + 8, displayName + "Source None", eSigIoMask.InputOutputSig);
defaultDisplaySourceNone.OutputSig.UserObject = new Action<bool>(b => { if (!b) Room.RunRouteAction("roomOff"); }); ;
}
//var dict = ConfigReader.ConfigObject.GetSourceListForKey(Room.SourceListKey);
//foreach (var item in dict)
//{
// if(item.Key != "roomOff")
// {
// var defaultDisplaySource = FusionRoom.CreateOffsetBoolSig((uint)joinOffset + (uint)item.Value.Order + 9 , string.Format("{0}Source {1}", displayIndex, item.Value.Order), eSigIoMask.InputOutputSig);
// defaultDisplaySource.OutputSig.UserObject = new Action<bool>(b => { if (!b) Room.RunRouteAction(item.Key); });
// //defaultDisplaySource.InputSig = Source[item.Value.Order].InputSig;
// }
//}
}
}
@@ -1144,31 +1163,32 @@ namespace PepperDash.Essentials.Fusion
}
void SetUpOccupancy()
{
{
// Need to have the room occupancy object first and somehow determine the slot number of the Occupancy asset but will not be able to use the UID from config likely.
// Consider defining an object just for Room Occupancy (either eAssetType.Occupancy Sensor (local) or eAssetType.RemoteOccupancySensor (from Fusion sched. panel)) and reserving slot 4 for that asset (statics would start at 5)
#warning Add actual object logic check here
//if (Room.OccupancyObj != null)
//{
string occAssetId;
var tempAsset = FusionAssets.FirstOrDefault(a => a.Type.Equals("Occupancy Sensor"));
var tempOccAsset = GUIDs.OccupancyAsset;
if(tempAsset != null)
occAssetId = tempAsset.InstanceID;
else
if(tempOccAsset == null)
{
var nextAssetNum = FusionAssets.Count + 3; //Account for slot number offset
tempAsset = new FusionAsset((uint)nextAssetNum, "Occupancy Sensor", "Occupancy Sensor", "");
FusionAssets.Add(tempAsset);
occAssetId = tempAsset.InstanceID;
FusionOccSensor = new FusionOccupancySensorAsset(eAssetType.OccupancySensor);
tempOccAsset = FusionOccSensor;
}
var occSensorAsset = FusionRoom.CreateOccupancySensorAsset(tempAsset.Number, tempAsset.Name, tempAsset.Type, occAssetId);
//FusionRoom.AddAsset(eAssetType.OccupancySensor, tempAsset.Number, tempAsset.Name, tempAsset.Type, tempAsset.InstanceID);
var occSensorAsset = FusionRoom.CreateOccupancySensorAsset(tempOccAsset.SlotNumber, tempOccAsset.Name, "Occupancy Sensor", tempOccAsset.InstanceId);
occSensorAsset.RoomOccupied.AddSigToRVIFile = true;
var occSensorShutdownMinutes = FusionRoom.CreateOffsetUshortSig(70, "Occ Shutdown - Minutes", eSigIoMask.InputOutputSig);
// Tie to method on occupancy object
//occSensorShutdownMinutes.OutputSig.UserObject(new Action(ushort)(b => Room.OccupancyObj.SetShutdownMinutes(b));
// use Room.OccObject.RoomOccupiedFeedback.LinkInputSig(occSensorAsset.InputSig);
//}
}

File diff suppressed because it is too large Load Diff

View File

@@ -26,7 +26,7 @@ namespace PepperDash.Essentials.Room.Cotija
controller.AddAction(prefix + "num9", new PressAndHoldAction(dev.Digit0));
controller.AddAction(prefix + "dash", new PressAndHoldAction(dev.KeypadAccessoryButton1));
controller.AddAction(prefix + "enter", new PressAndHoldAction(dev.KeypadAccessoryButton2));
#warning Deal with the Accessory functions on the numpad later
// Deal with the Accessory functions on the numpad later
}
public static void UnlinkActions(this INumericKeypad dev, CotijaSystemController controller)