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

@@ -45,6 +45,6 @@ namespace PepperDash.Essentials.Core
triList.ClearBoolSigAction(142); triList.ClearBoolSigAction(142);
triList.ClearBoolSigAction(130); triList.ClearBoolSigAction(130);
triList.ClearBoolSigAction(134); triList.ClearBoolSigAction(134);
} }
} }
} }

View File

@@ -34,6 +34,8 @@ namespace PepperDash.Essentials.Core
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } } protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } } protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
int VolumeHeldRepeatInterval = 200;
ushort VolumeInterval = 655;
ushort _FakeVolumeLevel = 31768; ushort _FakeVolumeLevel = 31768;
bool _IsMuted; bool _IsMuted;
@@ -138,22 +140,30 @@ namespace PepperDash.Essentials.Core
public void VolumeUp(bool pressRelease) public void VolumeUp(bool pressRelease)
{ {
Debug.Console(2, this, "Volume Down {0}", pressRelease); //while (pressRelease)
if (pressRelease) //{
{ Debug.Console(2, this, "Volume Down {0}", pressRelease);
var newLevel = _FakeVolumeLevel + 655; if (pressRelease)
SetVolume((ushort)newLevel); {
} var newLevel = _FakeVolumeLevel + VolumeInterval;
SetVolume((ushort)newLevel);
CrestronEnvironment.Sleep(VolumeHeldRepeatInterval);
}
//}
} }
public void VolumeDown(bool pressRelease) public void VolumeDown(bool pressRelease)
{ {
Debug.Console(2, this, "Volume Up {0}", pressRelease); //while (pressRelease)
if (pressRelease) //{
{ Debug.Console(2, this, "Volume Up {0}", pressRelease);
var newLevel = _FakeVolumeLevel - 655; if (pressRelease)
SetVolume((ushort)newLevel); {
} var newLevel = _FakeVolumeLevel - VolumeInterval;
SetVolume((ushort)newLevel);
CrestronEnvironment.Sleep(VolumeHeldRepeatInterval);
}
//}
} }
public void MuteToggle() public void MuteToggle()

View File

@@ -1,354 +1,354 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Routing; using PepperDash.Essentials.Core.Routing;
namespace PepperDash.Essentials.Devices.Displays namespace PepperDash.Essentials.Devices.Displays
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class NecPSXMDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor public class NecPSXMDisplay : TwoWayDisplayBase, IBasicVolumeWithFeedback, ICommunicationMonitor
{ {
public IBasicCommunication Communication { get; private set; } public IBasicCommunication Communication { get; private set; }
public CommunicationGather PortGather { get; private set; } public CommunicationGather PortGather { get; private set; }
public StatusMonitorBase CommunicationMonitor { get; private set; } public StatusMonitorBase CommunicationMonitor { get; private set; }
#region Command constants #region Command constants
public const string InputGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x36\x30\x03\x03\x0D"; public const string InputGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x36\x30\x03\x03\x0D";
public const string Hdmi1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x31\x03\x72\x0d"; public const string Hdmi1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x31\x03\x72\x0d";
public const string Hdmi2Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x32\x03\x71\x0D"; public const string Hdmi2Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x32\x03\x71\x0D";
public const string Hdmi3Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x38\x32\x03\x78\x0D"; public const string Hdmi3Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x38\x32\x03\x78\x0D";
public const string Hdmi4Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x38\x33\x03\x79\x0D"; public const string Hdmi4Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x38\x33\x03\x79\x0D";
public const string Dp1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x46\x03\x04\x0D"; public const string Dp1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x46\x03\x04\x0D";
public const string Dp2Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x30\x03\x73\x0D"; public const string Dp2Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x31\x30\x03\x73\x0D";
public const string Dvi1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x33\x03\x71\x0d"; public const string Dvi1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x33\x03\x71\x0d";
public const string Video1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x35\x03\x77\x0D"; public const string Video1Cmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x35\x03\x77\x0D";
public const string VgaCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x31\x03\x73\x0D"; public const string VgaCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x31\x03\x73\x0D";
public const string RgbCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x32\x03\x70\x0D"; public const string RgbCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x30\x30\x30\x30\x32\x03\x70\x0D";
public const string PowerOnCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x30\x33\x44\x36\x30\x30\x30\x31\x03\x73\x0D"; public const string PowerOnCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x30\x33\x44\x36\x30\x30\x30\x31\x03\x73\x0D";
public const string PowerOffCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x30\x33\x44\x36\x30\x30\x30\x34\x03\x76\x0D"; public const string PowerOffCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x30\x33\x44\x36\x30\x30\x30\x34\x03\x76\x0D";
public const string PowerToggleIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x30\x33\x30\x33\x03\x02\x0D"; public const string PowerToggleIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x30\x33\x30\x33\x03\x02\x0D";
public const string MuteOffCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x38\x44\x30\x30\x30\x30\x03\x08\x0D"; public const string MuteOffCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x38\x44\x30\x30\x30\x30\x03\x08\x0D";
public const string MuteOnCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x38\x44\x30\x30\x30\x31\x03\x09\x0D"; public const string MuteOnCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x38\x44\x30\x30\x30\x31\x03\x09\x0D";
public const string MuteToggleIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x42\x30\x33\x03\x72\x0D"; public const string MuteToggleIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x42\x30\x33\x03\x72\x0D";
public const string MuteGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x38\x44\x03\x79\x0D"; public const string MuteGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x38\x44\x03\x79\x0D";
public const string VolumeGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x36\x32\x03\x01\x0D"; public const string VolumeGetCmd = "\x01\x30\x41\x30\x43\x30\x36\x02\x30\x30\x36\x32\x03\x01\x0D";
public const string VolumeLevelPartialCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x32"; //\x46\x46\x46\x46\x03\xNN\x0D public const string VolumeLevelPartialCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x30\x30\x36\x32"; //\x46\x46\x46\x46\x03\xNN\x0D
public const string VolumeUpCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x31\x30\x41\x44\x30\x30\x30\x31\x03\x71\x0D"; public const string VolumeUpCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x31\x30\x41\x44\x30\x30\x30\x31\x03\x71\x0D";
public const string VolumeDownCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x31\x30\x41\x44\x30\x30\x30\x32\x03\x72\x0D"; public const string VolumeDownCmd = "\x01\x30\x41\x30\x45\x30\x41\x02\x31\x30\x41\x44\x30\x30\x30\x32\x03\x72\x0D";
public const string MenuIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x30\x30\x33\x03\x03\x0D"; public const string MenuIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x30\x30\x33\x03\x03\x0D";
public const string UpIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x35\x30\x33\x03\x05\x0D"; public const string UpIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x35\x30\x33\x03\x05\x0D";
public const string DownIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x34\x30\x33\x03\x04\x0D"; public const string DownIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x34\x30\x33\x03\x04\x0D";
public const string LeftIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x31\x30\x33\x03\x02\x0D"; public const string LeftIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x31\x30\x33\x03\x02\x0D";
public const string RightIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x32\x30\x33\x03\x01\x0D"; public const string RightIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x32\x30\x33\x03\x01\x0D";
public const string SelectIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x33\x30\x33\x03\x00\x0D"; public const string SelectIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x32\x33\x30\x33\x03\x00\x0D";
public const string ExitIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x46\x30\x33\x03\x76\x0D"; public const string ExitIrCmd = "\x01\x30\x41\x30\x41\x30\x43\x02\x43\x32\x31\x30\x30\x30\x31\x46\x30\x33\x03\x76\x0D";
#endregion #endregion
bool _PowerIsOn; bool _PowerIsOn;
bool _IsWarmingUp; bool _IsWarmingUp;
bool _IsCoolingDown; bool _IsCoolingDown;
ushort _VolumeLevel; ushort _VolumeLevel;
bool _IsMuted; bool _IsMuted;
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } } protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } } protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } } protected override Func<bool> IsWarmingUpFeedbackFunc { get { return () => _IsWarmingUp; } }
/// <summary> /// <summary>
/// Constructor for IBasicCommunication /// Constructor for IBasicCommunication
/// </summary> /// </summary>
public NecPSXMDisplay(string key, string name, IBasicCommunication comm) public NecPSXMDisplay(string key, string name, IBasicCommunication comm)
: base(key, name) : base(key, name)
{ {
Communication = comm; Communication = comm;
Init(); Init();
} }
/// <summary> /// <summary>
/// Constructor for TCP /// Constructor for TCP
/// </summary> /// </summary>
public NecPSXMDisplay(string key, string name, string hostname, int port) public NecPSXMDisplay(string key, string name, string hostname, int port)
: base(key, name) : base(key, name)
{ {
Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000); Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000);
Init(); Init();
} }
/// <summary> /// <summary>
/// Constructor for COM /// Constructor for COM
/// </summary> /// </summary>
public NecPSXMDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec) public NecPSXMDisplay(string key, string name, ComPort port, ComPort.ComPortSpec spec)
: base(key, name) : base(key, name)
{ {
Communication = new ComPortController(key + "-com", port, spec); Communication = new ComPortController(key + "-com", port, spec);
Init(); Init();
} }
void Init() void Init()
{ {
PortGather = new CommunicationGather(Communication, '\x0d'); PortGather = new CommunicationGather(Communication, '\x0d');
PortGather.LineReceived += this.Port_LineReceived; PortGather.LineReceived += this.Port_LineReceived;
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 120000, 300000, "xx\x0d"); CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 120000, 300000, "xx\x0d");
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.AudioVideo, InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this)); eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.AudioVideo, InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this)); eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo, InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this)); eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn4, eRoutingSignalType.AudioVideo, InputPorts.Add(new RoutingInputPort(RoutingPortNames.HdmiIn4, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi4), this)); eRoutingPortConnectionType.Hdmi, new Action(InputHdmi4), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.AudioVideo, InputPorts.Add(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this)); eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DisplayPortIn2, eRoutingSignalType.AudioVideo, InputPorts.Add(new RoutingInputPort(RoutingPortNames.DisplayPortIn2, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort2), this)); eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort2), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.AudioVideo, InputPorts.Add(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this)); eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.AudioVideo, InputPorts.Add(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Composite, new Action(InputVideo1), this)); eRoutingPortConnectionType.Composite, new Action(InputVideo1), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.VgaIn, eRoutingSignalType.Video, InputPorts.Add(new RoutingInputPort(RoutingPortNames.VgaIn, eRoutingSignalType.Video,
eRoutingPortConnectionType.Vga, new Action(InputVga), this)); eRoutingPortConnectionType.Vga, new Action(InputVga), this));
InputPorts.Add(new RoutingInputPort(RoutingPortNames.RgbIn, eRoutingSignalType.Video, InputPorts.Add(new RoutingInputPort(RoutingPortNames.RgbIn, eRoutingSignalType.Video,
eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb)), this)); eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb)), this));
VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevel; }); VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevel; });
MuteFeedback = new BoolFeedback(() => _IsMuted); MuteFeedback = new BoolFeedback(() => _IsMuted);
// new BoolCueActionPair(CommonBoolCue.Menu, b => { if(b) Send(MenuIrCmd); }), // new BoolCueActionPair(CommonBoolCue.Menu, b => { if(b) Send(MenuIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Up, b => { if(b) Send(UpIrCmd); }), // new BoolCueActionPair(CommonBoolCue.Up, b => { if(b) Send(UpIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Down, b => { if(b) Send(DownIrCmd); }), // new BoolCueActionPair(CommonBoolCue.Down, b => { if(b) Send(DownIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Left, b => { if(b) Send(LeftIrCmd); }), // new BoolCueActionPair(CommonBoolCue.Left, b => { if(b) Send(LeftIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Right, b => { if(b) Send(RightIrCmd); }), // new BoolCueActionPair(CommonBoolCue.Right, b => { if(b) Send(RightIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Select, b => { if(b) Send(SelectIrCmd); }), // new BoolCueActionPair(CommonBoolCue.Select, b => { if(b) Send(SelectIrCmd); }),
// new BoolCueActionPair(CommonBoolCue.Exit, b => { if(b) Send(ExitIrCmd); }), // new BoolCueActionPair(CommonBoolCue.Exit, b => { if(b) Send(ExitIrCmd); }),
//}; //};
} }
~NecPSXMDisplay() ~NecPSXMDisplay()
{ {
PortGather = null; PortGather = null;
} }
public override bool CustomActivate() public override bool CustomActivate()
{ {
Communication.Connect(); Communication.Connect();
CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); }; CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); };
CommunicationMonitor.Start(); CommunicationMonitor.Start();
return true; return true;
} }
public override List<Feedback> Feedbacks public override List<Feedback> Feedbacks
{ {
get get
{ {
var list = base.Feedbacks; var list = base.Feedbacks;
list.AddRange(new List<Feedback> list.AddRange(new List<Feedback>
{ {
}); });
return list; return list;
} }
} }
void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args) void Port_LineReceived(object dev, GenericCommMethodReceiveTextArgs args)
{ {
if (Debug.Level == 2) if (Debug.Level == 2)
Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(args.Text)); Debug.Console(2, this, "Received: '{0}'", ComTextHelper.GetEscapedText(args.Text));
if (args.Text=="DO SOMETHING HERE EVENTUALLY") if (args.Text=="DO SOMETHING HERE EVENTUALLY")
{ {
_IsMuted = true; _IsMuted = true;
MuteFeedback.FireUpdate(); MuteFeedback.FireUpdate();
} }
} }
void AppendChecksumAndSend(string s) void AppendChecksumAndSend(string s)
{ {
int x = 0; int x = 0;
for (int i = 1; i < s.Length; i++) for (int i = 1; i < s.Length; i++)
x = x ^ s[i]; x = x ^ s[i];
string send = s + (char)x + '\x0d'; string send = s + (char)x + '\x0d';
Send(send); Send(send);
} }
void Send(string s) void Send(string s)
{ {
if (Debug.Level == 2) if (Debug.Level == 2)
Debug.Console(2, this, "Send: '{0}'", ComTextHelper.GetEscapedText(s)); Debug.Console(2, this, "Send: '{0}'", ComTextHelper.GetEscapedText(s));
Communication.SendText(s); Communication.SendText(s);
} }
public override void PowerOn() public override void PowerOn()
{ {
Send(PowerOnCmd); Send(PowerOnCmd);
if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown) if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
{ {
_IsWarmingUp = true; _IsWarmingUp = true;
IsWarmingUpFeedback.FireUpdate(); IsWarmingUpFeedback.FireUpdate();
// Fake power-up cycle // Fake power-up cycle
WarmupTimer = new CTimer(o => WarmupTimer = new CTimer(o =>
{ {
_IsWarmingUp = false; _IsWarmingUp = false;
_PowerIsOn = true; _PowerIsOn = true;
IsWarmingUpFeedback.FireUpdate(); IsWarmingUpFeedback.FireUpdate();
PowerIsOnFeedback.FireUpdate(); PowerIsOnFeedback.FireUpdate();
}, WarmupTime); }, WarmupTime);
} }
} }
public override void PowerOff() public override void PowerOff()
{ {
// If a display has unreliable-power off feedback, just override this and // If a display has unreliable-power off feedback, just override this and
// remove this check. // remove this check.
if (PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown) if (PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
{ {
Send(PowerOffCmd); Send(PowerOffCmd);
_IsCoolingDown = true; _IsCoolingDown = true;
_PowerIsOn = false; _PowerIsOn = false;
PowerIsOnFeedback.FireUpdate(); PowerIsOnFeedback.FireUpdate();
IsCoolingDownFeedback.FireUpdate(); IsCoolingDownFeedback.FireUpdate();
// Fake cool-down cycle // Fake cool-down cycle
CooldownTimer = new CTimer(o => CooldownTimer = new CTimer(o =>
{ {
Debug.Console(2, this, "Cooldown timer ending"); Debug.Console(2, this, "Cooldown timer ending");
_IsCoolingDown = false; _IsCoolingDown = false;
IsCoolingDownFeedback.FireUpdate(); IsCoolingDownFeedback.FireUpdate();
}, CooldownTime); }, CooldownTime);
} }
} }
public override void PowerToggle() public override void PowerToggle()
{ {
if (PowerIsOnFeedback.BoolValue && !IsWarmingUpFeedback.BoolValue) if (PowerIsOnFeedback.BoolValue && !IsWarmingUpFeedback.BoolValue)
PowerOff(); PowerOff();
else if (!PowerIsOnFeedback.BoolValue && !IsCoolingDownFeedback.BoolValue) else if (!PowerIsOnFeedback.BoolValue && !IsCoolingDownFeedback.BoolValue)
PowerOn(); PowerOn();
} }
public void InputHdmi1() public void InputHdmi1()
{ {
Send(Hdmi1Cmd); Send(Hdmi1Cmd);
} }
public void InputHdmi2() public void InputHdmi2()
{ {
Send(Hdmi2Cmd); Send(Hdmi2Cmd);
} }
public void InputHdmi3() public void InputHdmi3()
{ {
Send(Hdmi3Cmd); Send(Hdmi3Cmd);
} }
public void InputHdmi4() public void InputHdmi4()
{ {
Send(Hdmi4Cmd); Send(Hdmi4Cmd);
} }
public void InputDisplayPort1() public void InputDisplayPort1()
{ {
Send(Dp1Cmd); Send(Dp1Cmd);
} }
public void InputDisplayPort2() public void InputDisplayPort2()
{ {
Send(Dp2Cmd); Send(Dp2Cmd);
} }
public void InputDvi1() public void InputDvi1()
{ {
Send(Dvi1Cmd); Send(Dvi1Cmd);
} }
public void InputVideo1() public void InputVideo1()
{ {
Send(Video1Cmd); Send(Video1Cmd);
} }
public void InputVga() public void InputVga()
{ {
Send(VgaCmd); Send(VgaCmd);
} }
public void InputRgb() public void InputRgb()
{ {
Send(RgbCmd); Send(RgbCmd);
} }
public override void ExecuteSwitch(object selector) public override void ExecuteSwitch(object selector)
{ {
if (selector is Action) if (selector is Action)
(selector as Action).Invoke(); (selector as Action).Invoke();
else else
Debug.Console(1, this, "WARNING: ExecuteSwitch cannot handle type {0}", selector.GetType()); Debug.Console(1, this, "WARNING: ExecuteSwitch cannot handle type {0}", selector.GetType());
//Send((string)selector); //Send((string)selector);
} }
void SetVolume(ushort level) void SetVolume(ushort level)
{ {
var levelString = string.Format("{0}{1:X4}\x03", VolumeLevelPartialCmd, level); var levelString = string.Format("{0}{1:X4}\x03", VolumeLevelPartialCmd, level);
AppendChecksumAndSend(levelString); AppendChecksumAndSend(levelString);
//Debug.Console(2, this, "Volume:{0}", ComTextHelper.GetEscapedText(levelString)); //Debug.Console(2, this, "Volume:{0}", ComTextHelper.GetEscapedText(levelString));
_VolumeLevel = level; _VolumeLevel = level;
VolumeLevelFeedback.FireUpdate(); VolumeLevelFeedback.FireUpdate();
} }
#region IBasicVolumeWithFeedback Members #region IBasicVolumeWithFeedback Members
public IntFeedback VolumeLevelFeedback { get; private set; } public IntFeedback VolumeLevelFeedback { get; private set; }
public BoolFeedback MuteFeedback { get; private set; } public BoolFeedback MuteFeedback { get; private set; }
public void MuteOff() public void MuteOff()
{ {
Send(MuteOffCmd); Send(MuteOffCmd);
} }
public void MuteOn() public void MuteOn()
{ {
Send(MuteOnCmd); Send(MuteOnCmd);
} }
void IBasicVolumeWithFeedback.SetVolume(ushort level) void IBasicVolumeWithFeedback.SetVolume(ushort level)
{ {
SetVolume(level); SetVolume(level);
} }
#endregion #endregion
#region IBasicVolumeControls Members #region IBasicVolumeControls Members
public void MuteToggle() public void MuteToggle()
{ {
Send(MuteToggleIrCmd); Send(MuteToggleIrCmd);
} }
public void VolumeDown(bool pressRelease) public void VolumeDown(bool pressRelease)
{ {
//throw new NotImplementedException();
//#warning need incrementer for these
SetVolume(_VolumeLevel++);
}
public void VolumeUp(bool pressRelease)
{
//throw new NotImplementedException(); //throw new NotImplementedException();
SetVolume(_VolumeLevel--); //#warning need incrementer for these
} SetVolume(_VolumeLevel++);
}
#endregion
} public void VolumeUp(bool pressRelease)
{
//throw new NotImplementedException();
SetVolume(_VolumeLevel--);
}
#endregion
}
} }

View File

@@ -142,6 +142,7 @@
<Compile Include="FOR REFERENCE Room\EssentialsRoom.cs" /> <Compile Include="FOR REFERENCE Room\EssentialsRoom.cs" />
<Compile Include="Room\Cotija\CotijaConfig.cs" /> <Compile Include="Room\Cotija\CotijaConfig.cs" />
<Compile Include="Room\Cotija\CotijaRoomBridge.cs" /> <Compile Include="Room\Cotija\CotijaRoomBridge.cs" />
<Compile Include="Room\Cotija\DeviceTypeInterfaces\IDPadExtensions.cs" />
<Compile Include="Room\EssentialsPresentationRoom.cs" /> <Compile Include="Room\EssentialsPresentationRoom.cs" />
<Compile Include="Room\EssentialsRoomBase.cs" /> <Compile Include="Room\EssentialsRoomBase.cs" />
<Compile Include="Room\EssentialsRoomConfig.cs" /> <Compile Include="Room\EssentialsRoomConfig.cs" />

View File

@@ -135,22 +135,73 @@ namespace PepperDash.Essentials
} }
} }
*/ */
if (type == ChangeType.WillChange)
{
// Disconnect from previous source
if (type != ChangeType.DidChange) if (info != null)
return; {
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; JObject roomStatus = new JObject();
//roomStatus.Add("isOn", huddleRoom.OnFeedback.BoolValue);
roomStatus.Add("selectedSourceKey", huddleRoom.CurrentSourceInfoKey);
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/"); JObject message = new JObject();
message.Add("content", roomStatus);
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> /// <summary>

View File

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

View File

@@ -1,161 +1,161 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
namespace PepperDash.Essentials namespace PepperDash.Essentials
{ {
public class EssentialsHuddleSpaceRoom : EssentialsRoomBase, IHasCurrentSourceInfoChange public class EssentialsHuddleSpaceRoom : EssentialsRoomBase, IHasCurrentSourceInfoChange
{ {
public event EventHandler<VolumeDeviceChangeEventArgs> CurrentVolumeDeviceChange; public event EventHandler<VolumeDeviceChangeEventArgs> CurrentVolumeDeviceChange;
public event SourceInfoChangeHandler CurrentSingleSourceChange; public event SourceInfoChangeHandler CurrentSingleSourceChange;
public EssentialsRoomPropertiesConfig Config { get; private set; } public EssentialsRoomPropertiesConfig Config { get; private set; }
public IRoutingSinkWithSwitching DefaultDisplay { get; private set; } public IRoutingSinkWithSwitching DefaultDisplay { get; private set; }
public IRoutingSinkNoSwitching DefaultAudioDevice { get; private set; } public IRoutingSinkNoSwitching DefaultAudioDevice { get; private set; }
public IBasicVolumeControls DefaultVolumeControls { get; private set; } public IBasicVolumeControls DefaultVolumeControls { get; private set; }
public bool ExcludeFromGlobalFunctions { get; set; } public bool ExcludeFromGlobalFunctions { get; set; }
/// <summary> /// <summary>
/// The config name of the source list /// The config name of the source list
/// </summary> /// </summary>
public string SourceListKey { get; set; } public string SourceListKey { get; set; }
/// <summary> /// <summary>
/// If room is off, enables power on to last source. Default true /// If room is off, enables power on to last source. Default true
/// </summary> /// </summary>
public bool EnablePowerOnToLastSource { get; set; } public bool EnablePowerOnToLastSource { get; set; }
string LastSourceKey; string LastSourceKey;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public IBasicVolumeControls CurrentVolumeControls public IBasicVolumeControls CurrentVolumeControls
{ {
get { return _CurrentAudioDevice; } get { return _CurrentAudioDevice; }
set set
{ {
if (value == _CurrentAudioDevice) return; if (value == _CurrentAudioDevice) return;
var oldDev = _CurrentAudioDevice; var oldDev = _CurrentAudioDevice;
// derigister this room from the device, if it can // derigister this room from the device, if it can
if (oldDev is IInUseTracking) if (oldDev is IInUseTracking)
(oldDev as IInUseTracking).InUseTracker.RemoveUser(this, "audio"); (oldDev as IInUseTracking).InUseTracker.RemoveUser(this, "audio");
var handler = CurrentVolumeDeviceChange; var handler = CurrentVolumeDeviceChange;
if (handler != null) if (handler != null)
CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.WillChange)); CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.WillChange));
_CurrentAudioDevice = value; _CurrentAudioDevice = value;
if (handler != null) if (handler != null)
CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.DidChange)); CurrentVolumeDeviceChange(this, new VolumeDeviceChangeEventArgs(oldDev, value, ChangeType.DidChange));
// register this room with new device, if it can // register this room with new device, if it can
if (_CurrentAudioDevice is IInUseTracking) if (_CurrentAudioDevice is IInUseTracking)
(_CurrentAudioDevice as IInUseTracking).InUseTracker.AddUser(this, "audio"); (_CurrentAudioDevice as IInUseTracking).InUseTracker.AddUser(this, "audio");
} }
} }
IBasicVolumeControls _CurrentAudioDevice; IBasicVolumeControls _CurrentAudioDevice;
/// <summary> /// <summary>
/// The SourceListItem last run - containing names and icons /// The SourceListItem last run - containing names and icons
/// </summary> /// </summary>
public SourceListItem CurrentSourceInfo public SourceListItem CurrentSourceInfo
{ {
get { return _CurrentSourceInfo; } get { return _CurrentSourceInfo; }
private set private set
{ {
if (value == _CurrentSourceInfo) return; if (value == _CurrentSourceInfo) return;
var handler = CurrentSingleSourceChange; var handler = CurrentSingleSourceChange;
// remove from in-use tracker, if so equipped // remove from in-use tracker, if so equipped
if(_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking) if(_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking)
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.RemoveUser(this, "control"); (_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.RemoveUser(this, "control");
if (handler != null) if (handler != null)
handler(this, _CurrentSourceInfo, ChangeType.WillChange); handler(this, _CurrentSourceInfo, ChangeType.WillChange);
_CurrentSourceInfo = value; _CurrentSourceInfo = value;
// add to in-use tracking // add to in-use tracking
if (_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking) if (_CurrentSourceInfo != null && _CurrentSourceInfo.SourceDevice is IInUseTracking)
(_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.AddUser(this, "control"); (_CurrentSourceInfo.SourceDevice as IInUseTracking).InUseTracker.AddUser(this, "control");
if (handler != null) if (handler != null)
handler(this, _CurrentSourceInfo, ChangeType.DidChange); handler(this, _CurrentSourceInfo, ChangeType.DidChange);
} }
} }
SourceListItem _CurrentSourceInfo; SourceListItem _CurrentSourceInfo;
public string CurrentSourceInfoKey { get; private set; } public string CurrentSourceInfoKey { get; private set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public BoolFeedback OnFeedback { get; private set; } public BoolFeedback OnFeedback { get; private set; }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="key"></param> /// <param name="key"></param>
/// <param name="name"></param> /// <param name="name"></param>
public EssentialsHuddleSpaceRoom(string key, string name, IRoutingSinkWithSwitching defaultDisplay, public EssentialsHuddleSpaceRoom(string key, string name, IRoutingSinkWithSwitching defaultDisplay,
IRoutingSinkNoSwitching defaultAudio, EssentialsRoomPropertiesConfig config) IRoutingSinkNoSwitching defaultAudio, EssentialsRoomPropertiesConfig config)
: base(key, name) : base(key, name)
{ {
Config = config; Config = config;
DefaultDisplay = defaultDisplay; DefaultDisplay = defaultDisplay;
DefaultAudioDevice = defaultAudio; DefaultAudioDevice = defaultAudio;
if (defaultAudio is IBasicVolumeControls) if (defaultAudio is IBasicVolumeControls)
DefaultVolumeControls = defaultAudio as IBasicVolumeControls; DefaultVolumeControls = defaultAudio as IBasicVolumeControls;
else if (defaultAudio is IHasVolumeDevice) else if (defaultAudio is IHasVolumeDevice)
DefaultVolumeControls = (defaultAudio as IHasVolumeDevice).VolumeDevice; DefaultVolumeControls = (defaultAudio as IHasVolumeDevice).VolumeDevice;
CurrentVolumeControls = DefaultVolumeControls; CurrentVolumeControls = DefaultVolumeControls;
OnFeedback = new BoolFeedback(() => OnFeedback = new BoolFeedback(() =>
{ return CurrentSourceInfo != null { return CurrentSourceInfo != null
&& CurrentSourceInfo.Type == eSourceListItemType.Route; }); && CurrentSourceInfo.Type == eSourceListItemType.Route; });
SourceListKey = "default"; SourceListKey = "default";
EnablePowerOnToLastSource = true; EnablePowerOnToLastSource = true;
} }
public void RunRouteAction(string routeKey) public void RunRouteAction(string routeKey)
{ {
RunRouteAction(routeKey, null); RunRouteAction(routeKey, null);
} }
/// <summary> /// <summary>
/// Gets a source from config list SourceListKey and dynamically build and executes the /// Gets a source from config list SourceListKey and dynamically build and executes the
/// route or commands /// route or commands
/// </summary> /// </summary>
/// <param name="name"></param> /// <param name="name"></param>
public void RunRouteAction(string routeKey, Action successCallback) public void RunRouteAction(string routeKey, Action successCallback)
{ {
// Run this on a separate thread // Run this on a separate thread
new CTimer(o => new CTimer(o =>
{ {
Debug.Console(1, this, "Run room action '{0}'", routeKey); Debug.Console(1, this, "Run room action '{0}'", routeKey);
var dict = ConfigReader.ConfigObject.GetSourceListForKey(SourceListKey); var dict = ConfigReader.ConfigObject.GetSourceListForKey(SourceListKey);
if(dict == null) if(dict == null)
{ {
Debug.Console(1, this, "WARNING: Config source list '{0}' not found", SourceListKey); Debug.Console(1, this, "WARNING: Config source list '{0}' not found", SourceListKey);
return; return;
} }
// Try to get the list item by it's string key // Try to get the list item by it's string key
if (!dict.ContainsKey(routeKey)) if (!dict.ContainsKey(routeKey))
{ {
Debug.Console(1, this, "WARNING: No item '{0}' found on config list '{1}'", Debug.Console(1, this, "WARNING: No item '{0}' found on config list '{1}'",
routeKey, SourceListKey); routeKey, SourceListKey);
return; return;
} }
var item = dict[routeKey]; var item = dict[routeKey];
Debug.Console(2, this, "Action {0} has {1} steps", Debug.Console(2, this, "Action {0} has {1} steps",
item.SourceKey, item.RouteList.Count); item.SourceKey, item.RouteList.Count);
// Let's run it // Let's run it
if (routeKey.ToLower() != "roomoff") if (routeKey.ToLower() != "roomoff")
{ {
@@ -164,133 +164,133 @@ namespace PepperDash.Essentials
else else
{ {
CurrentSourceInfoKey = null; CurrentSourceInfoKey = null;
} }
foreach (var route in item.RouteList) foreach (var route in item.RouteList)
{ {
// if there is a $defaultAll on route, run two separate // if there is a $defaultAll on route, run two separate
if (route.DestinationKey.Equals("$defaultAll", StringComparison.OrdinalIgnoreCase)) if (route.DestinationKey.Equals("$defaultAll", StringComparison.OrdinalIgnoreCase))
{ {
var tempAudio = new SourceRouteListItem var tempAudio = new SourceRouteListItem
{ {
DestinationKey = "$defaultDisplay", DestinationKey = "$defaultDisplay",
SourceKey = route.SourceKey, SourceKey = route.SourceKey,
Type = eRoutingSignalType.Video Type = eRoutingSignalType.Video
}; };
DoRoute(tempAudio); DoRoute(tempAudio);
var tempVideo = new SourceRouteListItem var tempVideo = new SourceRouteListItem
{ {
DestinationKey = "$defaultAudio", DestinationKey = "$defaultAudio",
SourceKey = route.SourceKey, SourceKey = route.SourceKey,
Type = eRoutingSignalType.Audio Type = eRoutingSignalType.Audio
}; };
DoRoute(tempVideo); DoRoute(tempVideo);
continue; continue;
} }
else else
DoRoute(route); DoRoute(route);
} }
// Set volume control on room, using default if non provided // Set volume control on room, using default if non provided
IBasicVolumeControls volDev = null; IBasicVolumeControls volDev = null;
// Handle special cases for volume control // Handle special cases for volume control
if (string.IsNullOrEmpty(item.VolumeControlKey) if (string.IsNullOrEmpty(item.VolumeControlKey)
|| item.VolumeControlKey.Equals("$defaultAudio", StringComparison.OrdinalIgnoreCase)) || item.VolumeControlKey.Equals("$defaultAudio", StringComparison.OrdinalIgnoreCase))
volDev = DefaultVolumeControls; volDev = DefaultVolumeControls;
else if (item.VolumeControlKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase)) else if (item.VolumeControlKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
volDev = DefaultDisplay as IBasicVolumeControls; volDev = DefaultDisplay as IBasicVolumeControls;
// Or a specific device, probably rarely used. // Or a specific device, probably rarely used.
else else
{ {
var dev = DeviceManager.GetDeviceForKey(item.VolumeControlKey); var dev = DeviceManager.GetDeviceForKey(item.VolumeControlKey);
if (dev is IBasicVolumeControls) if (dev is IBasicVolumeControls)
volDev = dev as IBasicVolumeControls; volDev = dev as IBasicVolumeControls;
else if (dev is IHasVolumeDevice) else if (dev is IHasVolumeDevice)
volDev = (dev as IHasVolumeDevice).VolumeDevice; volDev = (dev as IHasVolumeDevice).VolumeDevice;
} }
CurrentVolumeControls = volDev; CurrentVolumeControls = volDev;
// store the name and UI info for routes // store the name and UI info for routes
if (item.SourceKey != null) if (item.SourceKey != null)
{ {
CurrentSourceInfoKey = routeKey; CurrentSourceInfoKey = routeKey;
CurrentSourceInfo = item; CurrentSourceInfo = item;
} }
// And finally, set the "control". This will trigger event // And finally, set the "control". This will trigger event
//CurrentControlDevice = DeviceManager.GetDeviceForKey(item.SourceKey) as Device; //CurrentControlDevice = DeviceManager.GetDeviceForKey(item.SourceKey) as Device;
OnFeedback.FireUpdate(); OnFeedback.FireUpdate();
// report back when done // report back when done
if (successCallback != null) if (successCallback != null)
successCallback(); successCallback();
#warning Need to again handle special commands in here. #warning Need to again handle special commands in here.
}, 0); // end of CTimer }, 0); // end of CTimer
} }
/// <summary> /// <summary>
/// Will power the room on with the last-used source /// Will power the room on with the last-used source
/// </summary> /// </summary>
public void PowerOnToDefaultOrLastSource() public void PowerOnToDefaultOrLastSource()
{ {
if (!EnablePowerOnToLastSource || LastSourceKey == null) if (!EnablePowerOnToLastSource || LastSourceKey == null)
return; return;
RunRouteAction(LastSourceKey); RunRouteAction(LastSourceKey);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="route"></param> /// <param name="route"></param>
/// <returns></returns> /// <returns></returns>
bool DoRoute(SourceRouteListItem route) bool DoRoute(SourceRouteListItem route)
{ {
IRoutingSinkNoSwitching dest = null; IRoutingSinkNoSwitching dest = null;
if (route.DestinationKey.Equals("$defaultaudio", StringComparison.OrdinalIgnoreCase)) if (route.DestinationKey.Equals("$defaultaudio", StringComparison.OrdinalIgnoreCase))
dest = DefaultAudioDevice; dest = DefaultAudioDevice;
else if (route.DestinationKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase)) else if (route.DestinationKey.Equals("$defaultDisplay", StringComparison.OrdinalIgnoreCase))
dest = DefaultDisplay; dest = DefaultDisplay;
else else
dest = DeviceManager.GetDeviceForKey(route.DestinationKey) as IRoutingSinkNoSwitching; dest = DeviceManager.GetDeviceForKey(route.DestinationKey) as IRoutingSinkNoSwitching;
if (dest == null) if (dest == null)
{ {
Debug.Console(1, this, "Cannot route, unknown destination '{0}'", route.DestinationKey); Debug.Console(1, this, "Cannot route, unknown destination '{0}'", route.DestinationKey);
return false; return false;
} }
if (route.SourceKey.Equals("$off", StringComparison.OrdinalIgnoreCase)) if (route.SourceKey.Equals("$off", StringComparison.OrdinalIgnoreCase))
{ {
dest.ReleaseRoute(); dest.ReleaseRoute();
if (dest is IPower) if (dest is IPower)
(dest as IPower).PowerOff(); (dest as IPower).PowerOff();
} }
else else
{ {
var source = DeviceManager.GetDeviceForKey(route.SourceKey) as IRoutingOutputs; var source = DeviceManager.GetDeviceForKey(route.SourceKey) as IRoutingOutputs;
if (source == null) if (source == null)
{ {
Debug.Console(1, this, "Cannot route unknown source '{0}' to {1}", route.SourceKey, route.DestinationKey); Debug.Console(1, this, "Cannot route unknown source '{0}' to {1}", route.SourceKey, route.DestinationKey);
return false; return false;
} }
dest.ReleaseAndMakeRoute(source, route.Type); dest.ReleaseAndMakeRoute(source, route.Type);
} }
return true; return true;
} }
/// <summary> /// <summary>
/// Runs "roomOff" action on all rooms not set to ExcludeFromGlobalFunctions /// Runs "roomOff" action on all rooms not set to ExcludeFromGlobalFunctions
/// </summary> /// </summary>
public static void AllRoomsOff() public static void AllRoomsOff()
{ {
var allRooms = DeviceManager.AllDevices.Where(d => var allRooms = DeviceManager.AllDevices.Where(d =>
d is EssentialsHuddleSpaceRoom && !(d as EssentialsHuddleSpaceRoom).ExcludeFromGlobalFunctions); d is EssentialsHuddleSpaceRoom && !(d as EssentialsHuddleSpaceRoom).ExcludeFromGlobalFunctions);
foreach (var room in allRooms) foreach (var room in allRooms)
(room as EssentialsHuddleSpaceRoom).RunRouteAction("roomOff"); (room as EssentialsHuddleSpaceRoom).RunRouteAction("roomOff");
} }
} }
} }

View File

@@ -1,196 +1,196 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharpPro; using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.UI; using Crestron.SimplSharpPro.UI;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.PageManagers; using PepperDash.Essentials.Core.PageManagers;
namespace PepperDash.Essentials namespace PepperDash.Essentials
{ {
public class EssentialsTouchpanelController : Device public class EssentialsTouchpanelController : Device
{ {
public BasicTriListWithSmartObject Panel { get; private set; } public BasicTriListWithSmartObject Panel { get; private set; }
public PanelDriverBase PanelDriver { get; private set; } public PanelDriverBase PanelDriver { get; private set; }
CTimer BacklightTransitionedOnTimer; CTimer BacklightTransitionedOnTimer;
public EssentialsTouchpanelController(string key, string name, Tswx52ButtonVoiceControl tsw, public EssentialsTouchpanelController(string key, string name, Tswx52ButtonVoiceControl tsw,
string projectName, string sgdPath) string projectName, string sgdPath)
: base(key, name) : base(key, name)
{ {
Panel = tsw; Panel = tsw;
tsw.LoadSmartObjects(sgdPath); tsw.LoadSmartObjects(sgdPath);
tsw.SigChange += new Crestron.SimplSharpPro.DeviceSupport.SigEventHandler(Tsw_SigChange); tsw.SigChange += new Crestron.SimplSharpPro.DeviceSupport.SigEventHandler(Tsw_SigChange);
} }
/// <summary> /// <summary>
/// Config constructor /// Config constructor
/// </summary> /// </summary>
public EssentialsTouchpanelController(string key, string name, string type, CrestronTouchpanelPropertiesConfig props, uint id) public EssentialsTouchpanelController(string key, string name, string type, CrestronTouchpanelPropertiesConfig props, uint id)
: base(key, name) : base(key, name)
{ {
AddPostActivationAction(() => AddPostActivationAction(() =>
{ {
Debug.Console(2, this, "post-activation linking"); Debug.Console(2, this, "post-activation linking");
type = type.ToLower(); type = type.ToLower();
try try
{ {
if (type == "crestronapp") if (type == "crestronapp")
{ {
var app = new CrestronApp(id, Global.ControlSystem); var app = new CrestronApp(id, Global.ControlSystem);
app.ParameterProjectName.Value = props.ProjectName; app.ParameterProjectName.Value = props.ProjectName;
Panel = app; Panel = app;
} }
else if (type == "tsw752") else if (type == "tsw752")
Panel = new Tsw752(id, Global.ControlSystem); Panel = new Tsw752(id, Global.ControlSystem);
else if (type == "tsw1052") else if (type == "tsw1052")
Panel = new Tsw1052(id, Global.ControlSystem); Panel = new Tsw1052(id, Global.ControlSystem);
else else
{ {
Debug.Console(0, this, "WARNING: Cannot create TSW controller with type '{0}'", type); Debug.Console(0, this, "WARNING: Cannot create TSW controller with type '{0}'", type);
return; return;
} }
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(0, this, "WARNING: Cannot create TSW base class. Panel will not function: {0}", e.Message); Debug.Console(0, this, "WARNING: Cannot create TSW base class. Panel will not function: {0}", e.Message);
return; return;
} }
// Reserved sigs // Reserved sigs
if (Panel is TswFt5ButtonSystem) if (Panel is TswFt5ButtonSystem)
{ {
var tsw = Panel as TswFt5ButtonSystem; var tsw = Panel as TswFt5ButtonSystem;
tsw.ExtenderSystemReservedSigs.Use(); tsw.ExtenderSystemReservedSigs.Use();
tsw.ExtenderSystemReservedSigs.DeviceExtenderSigChange tsw.ExtenderSystemReservedSigs.DeviceExtenderSigChange
+= ExtenderSystemReservedSigs_DeviceExtenderSigChange; += ExtenderSystemReservedSigs_DeviceExtenderSigChange;
} }
new CTimer(o => new CTimer(o =>
{ {
var regSuccess = Panel.Register(); var regSuccess = Panel.Register();
if (regSuccess != eDeviceRegistrationUnRegistrationResponse.Success) if (regSuccess != eDeviceRegistrationUnRegistrationResponse.Success)
Debug.Console(0, this, "WARNING: Registration failed. Continuing, but panel may not function: {0}", regSuccess); Debug.Console(0, this, "WARNING: Registration failed. Continuing, but panel may not function: {0}", regSuccess);
// Give up cleanly if SGD is not present. // Give up cleanly if SGD is not present.
var sgdName = @"\NVRAM\Program" + InitialParametersClass.ApplicationNumber var sgdName = @"\NVRAM\Program" + InitialParametersClass.ApplicationNumber
+ @"\sgd\" + props.SgdFile; + @"\sgd\" + props.SgdFile;
if (!File.Exists(sgdName)) if (!File.Exists(sgdName))
{ {
Debug.Console(0, this, "WARNING: Smart object file '{0}' not present. Exiting TSW load", sgdName); Debug.Console(0, this, "WARNING: Smart object file '{0}' not present. Exiting TSW load", sgdName);
return; return;
} }
Panel.LoadSmartObjects(sgdName); Panel.LoadSmartObjects(sgdName);
Panel.SigChange += Tsw_SigChange; Panel.SigChange += Tsw_SigChange;
var mainDriver = new EssentialsPanelMainInterfaceDriver(Panel, props); var mainDriver = new EssentialsPanelMainInterfaceDriver(Panel, props);
// Then the AV driver // Then the AV driver
// spin up different room drivers depending on room type // spin up different room drivers depending on room type
var room = DeviceManager.GetDeviceForKey(props.DefaultRoomKey); var room = DeviceManager.GetDeviceForKey(props.DefaultRoomKey);
if (room is EssentialsHuddleSpaceRoom) if (room is EssentialsHuddleSpaceRoom)
{ {
Debug.Console(0, this, "Adding huddle space driver"); Debug.Console(0, this, "Adding huddle space driver");
var avDriver = new EssentialsHuddlePanelAvFunctionsDriver(mainDriver, props); var avDriver = new EssentialsHuddlePanelAvFunctionsDriver(mainDriver, props);
avDriver.CurrentRoom = room as EssentialsHuddleSpaceRoom; avDriver.CurrentRoom = room as EssentialsHuddleSpaceRoom;
avDriver.DefaultRoomKey = props.DefaultRoomKey; avDriver.DefaultRoomKey = props.DefaultRoomKey;
mainDriver.AvDriver = avDriver; mainDriver.AvDriver = avDriver;
LoadAndShowDriver(mainDriver); // This is a little convoluted. LoadAndShowDriver(mainDriver); // This is a little convoluted.
if (Panel is TswFt5ButtonSystem) if (Panel is TswFt5ButtonSystem)
{ {
var tsw = Panel as TswFt5ButtonSystem; var tsw = Panel as TswFt5ButtonSystem;
// Wire up hard keys // Wire up hard keys
tsw.Power.UserObject = new Action<bool>(b => { if (!b) avDriver.PowerButtonPressed(); }); tsw.Power.UserObject = new Action<bool>(b => { if (!b) avDriver.PowerButtonPressed(); });
//tsw.Home.UserObject = new Action<bool>(b => { if (!b) HomePressed(); }); //tsw.Home.UserObject = new Action<bool>(b => { if (!b) HomePressed(); });
tsw.Up.UserObject = new Action<bool>(avDriver.VolumeUpPress); tsw.Up.UserObject = new Action<bool>(avDriver.VolumeUpPress);
tsw.Down.UserObject = new Action<bool>(avDriver.VolumeDownPress); tsw.Down.UserObject = new Action<bool>(avDriver.VolumeDownPress);
tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange);
} }
} }
else if (room is EssentialsPresentationRoom) else if (room is EssentialsPresentationRoom)
{ {
Debug.Console(0, this, "Adding presentation room driver"); Debug.Console(0, this, "Adding presentation room driver");
var avDriver = new EssentialsPresentationPanelAvFunctionsDriver(mainDriver, props); var avDriver = new EssentialsPresentationPanelAvFunctionsDriver(mainDriver, props);
avDriver.CurrentRoom = room as EssentialsPresentationRoom; avDriver.CurrentRoom = room as EssentialsPresentationRoom;
avDriver.DefaultRoomKey = props.DefaultRoomKey; avDriver.DefaultRoomKey = props.DefaultRoomKey;
mainDriver.AvDriver = avDriver; mainDriver.AvDriver = avDriver;
LoadAndShowDriver(mainDriver); LoadAndShowDriver(mainDriver);
if (Panel is TswFt5ButtonSystem) if (Panel is TswFt5ButtonSystem)
{ {
var tsw = Panel as TswFt5ButtonSystem; var tsw = Panel as TswFt5ButtonSystem;
// Wire up hard keys // Wire up hard keys
tsw.Power.UserObject = new Action<bool>(b => { if (!b) avDriver.PowerButtonPressed(); }); tsw.Power.UserObject = new Action<bool>(b => { if (!b) avDriver.PowerButtonPressed(); });
//tsw.Home.UserObject = new Action<bool>(b => { if (!b) HomePressed(); }); //tsw.Home.UserObject = new Action<bool>(b => { if (!b) HomePressed(); });
tsw.Up.UserObject = new Action<bool>(avDriver.VolumeUpPress); tsw.Up.UserObject = new Action<bool>(avDriver.VolumeUpPress);
tsw.Down.UserObject = new Action<bool>(avDriver.VolumeDownPress); tsw.Down.UserObject = new Action<bool>(avDriver.VolumeDownPress);
tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange); tsw.ButtonStateChange += new ButtonEventHandler(Tsw_ButtonStateChange);
} }
} }
else else
{ {
Debug.Console(0, this, "ERROR: Cannot load AvFunctionsDriver for room '{0}'", props.DefaultRoomKey); Debug.Console(0, this, "ERROR: Cannot load AvFunctionsDriver for room '{0}'", props.DefaultRoomKey);
} }
}, 0); }, 0);
}); });
} }
public void LoadAndShowDriver(PanelDriverBase driver) public void LoadAndShowDriver(PanelDriverBase driver)
{ {
PanelDriver = driver; PanelDriver = driver;
driver.Show(); driver.Show();
} }
void HomePressed() void HomePressed()
{ {
if (BacklightTransitionedOnTimer != null) if (BacklightTransitionedOnTimer != null)
Debug.Console(2, this, "Home pressed from dark screen"); Debug.Console(2, this, "Home pressed from dark screen");
else else
PanelDriver.BackButtonPressed(); PanelDriver.BackButtonPressed();
} }
void ExtenderSystemReservedSigs_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender, SigEventArgs args) void ExtenderSystemReservedSigs_DeviceExtenderSigChange(DeviceExtender currentDeviceExtender, SigEventArgs args)
{ {
// If the sig is transitioning on, mark it in case it was home button that transitioned it // If the sig is transitioning on, mark it in case it was home button that transitioned it
var blOnSig = (Panel as TswFt5ButtonSystem).ExtenderSystemReservedSigs.BacklightOnFeedback; var blOnSig = (Panel as TswFt5ButtonSystem).ExtenderSystemReservedSigs.BacklightOnFeedback;
if (args.Sig == blOnSig && blOnSig.BoolValue) if (args.Sig == blOnSig && blOnSig.BoolValue)
{ {
Debug.Console(2, this, "Backlight transitioning on"); Debug.Console(2, this, "Backlight transitioning on");
BacklightTransitionedOnTimer = new CTimer(o => BacklightTransitionedOnTimer = new CTimer(o =>
{ {
BacklightTransitionedOnTimer = null; BacklightTransitionedOnTimer = null;
}, 200); }, 200);
} }
} }
void Tsw_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args) void Tsw_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args)
{ {
if (Debug.Level == 2) if (Debug.Level == 2)
Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue); Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
var uo = args.Sig.UserObject; var uo = args.Sig.UserObject;
if (uo is Action<bool>) if (uo is Action<bool>)
(uo as Action<bool>)(args.Sig.BoolValue); (uo as Action<bool>)(args.Sig.BoolValue);
else if (uo is Action<ushort>) else if (uo is Action<ushort>)
(uo as Action<ushort>)(args.Sig.UShortValue); (uo as Action<ushort>)(args.Sig.UShortValue);
else if (uo is Action<string>) else if (uo is Action<string>)
(uo as Action<string>)(args.Sig.StringValue); (uo as Action<string>)(args.Sig.StringValue);
} }
void Tsw_ButtonStateChange(GenericBase device, ButtonEventArgs args) void Tsw_ButtonStateChange(GenericBase device, ButtonEventArgs args)
{ {
var uo = args.Button.UserObject; var uo = args.Button.UserObject;
if(uo is Action<bool>) if(uo is Action<bool>)
(uo as Action<bool>)(args.Button.State == eButtonState.Pressed); (uo as Action<bool>)(args.Button.State == eButtonState.Pressed);
} }
} }
} }