mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 12:44:58 +00:00
Compare commits
6 Commits
v2.17.1-fe
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c284c4275f | ||
|
|
0418f8a7cc | ||
|
|
419177ccd5 | ||
|
|
bd01e2bacc | ||
|
|
2928c5cf94 | ||
|
|
82b5dc96c1 |
@@ -131,14 +131,14 @@ namespace PepperDash.Core
|
|||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="address"></param>
|
/// <param name="address"></param>
|
||||||
/// <param name="port"></param>
|
/// <param name="port"></param>
|
||||||
/// <param name="buffefSize"></param>
|
/// <param name="bufferSize"></param>
|
||||||
public GenericUdpServer(string key, string address, int port, int buffefSize)
|
public GenericUdpServer(string key, string address, int port, int bufferSize)
|
||||||
: base(key)
|
: base(key)
|
||||||
{
|
{
|
||||||
StreamDebugging = new CommunicationStreamDebugging(key);
|
StreamDebugging = new CommunicationStreamDebugging(key);
|
||||||
Hostname = address;
|
Hostname = address;
|
||||||
Port = port;
|
Port = port;
|
||||||
BufferSize = buffefSize;
|
BufferSize = bufferSize;
|
||||||
|
|
||||||
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(CrestronEnvironment_ProgramStatusEventHandler);
|
||||||
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
CrestronEnvironment.EthernetEventHandler += new EthernetEventHandler(CrestronEnvironment_EthernetEventHandler);
|
||||||
@@ -194,7 +194,21 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (Server == null)
|
if (Server == null)
|
||||||
{
|
{
|
||||||
Server = new UDPServer();
|
try
|
||||||
|
{
|
||||||
|
var address = IPAddress.Parse(Hostname);
|
||||||
|
|
||||||
|
Server = new UDPServer(address, Port, BufferSize);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.LogError("Error parsing IP Address '{ipAddress}': message: {message}", Hostname, ex.Message);
|
||||||
|
this.LogInformation("Creating UDPServer with default buffersize");
|
||||||
|
|
||||||
|
Server = new UDPServer();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(Hostname))
|
if (string.IsNullOrEmpty(Hostname))
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using PepperDash.Core;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.Devices.Common.Cameras
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for camera capabilities
|
||||||
|
/// </summary>
|
||||||
|
public interface ICameraCapabilities: IKeyName
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera can pan
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("canPan", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
bool CanPan { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera can tilt
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("canTilt", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
bool CanTilt { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera can zoom
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("canZoom", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
bool CanZoom { get; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera can focus
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("canFocus", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
bool CanFocus { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates the capabilities of a camera
|
||||||
|
/// </summary>
|
||||||
|
public class CameraCapabilities : ICameraCapabilities
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unique Key
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("key", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public string Key { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Isn't it obvious :)
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera can pan
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("canPan", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool CanPan { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera can tilt
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("canTilt", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool CanTilt { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera can zoom
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("canZoom", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool CanZoom { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera can focus
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("canFocus", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool CanFocus { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using PepperDash.Core;
|
using Newtonsoft.Json;
|
||||||
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace PepperDash.Essentials.Devices.Common.Cameras
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of cameras on the device. This should be a list of IHasCameraControls objects
|
/// List of cameras on the device. This should be a list of IHasCameraControls objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
List<IHasCameraControls> Cameras { get; }
|
List<IHasCameraControls> Cameras { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using PepperDash.Core;
|
||||||
using PepperDash.Essentials.Core;
|
using PepperDash.Essentials.Core;
|
||||||
using PepperDash.Essentials.Devices.Common.Cameras;
|
using PepperDash.Essentials.Devices.Common.Cameras;
|
||||||
|
|
||||||
@@ -9,12 +11,12 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Messenger for a CameraBase device
|
/// Messenger for a CameraBase device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CameraBaseMessenger : MessengerBase
|
public class CameraBaseMessenger<T> : MessengerBase where T : IKeyed
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the Camera
|
/// Gets or sets the Camera
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CameraBase Camera { get; set; }
|
public T Camera { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
@@ -22,10 +24,13 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
/// <param name="key"></param>
|
/// <param name="key"></param>
|
||||||
/// <param name="camera"></param>
|
/// <param name="camera"></param>
|
||||||
/// <param name="messagePath"></param>
|
/// <param name="messagePath"></param>
|
||||||
public CameraBaseMessenger(string key, CameraBase camera, string messagePath)
|
public CameraBaseMessenger(string key, T camera, string messagePath)
|
||||||
: base(key, messagePath, camera)
|
: base(key, messagePath, camera as IKeyName)
|
||||||
{
|
{
|
||||||
Camera = camera ?? throw new ArgumentNullException("camera");
|
if (camera == null)
|
||||||
|
throw new ArgumentNullException(nameof(camera));
|
||||||
|
|
||||||
|
Camera = camera;
|
||||||
|
|
||||||
|
|
||||||
if (Camera is IHasCameraPresets presetsCamera)
|
if (Camera is IHasCameraPresets presetsCamera)
|
||||||
@@ -178,19 +183,44 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
private void SendCameraFullMessageObject(string id = null)
|
private void SendCameraFullMessageObject(string id = null)
|
||||||
{
|
{
|
||||||
var presetList = new List<CameraPreset>();
|
var presetList = new List<CameraPreset>();
|
||||||
|
CameraCapabilities capabilities = null;
|
||||||
|
|
||||||
if (Camera is IHasCameraPresets presetsCamera)
|
if (Camera is IHasCameraPresets presetsCamera)
|
||||||
presetList = presetsCamera.Presets;
|
presetList = presetsCamera.Presets;
|
||||||
|
|
||||||
PostStatusMessage(JToken.FromObject(new
|
if (Camera is ICameraCapabilities cameraCapabilities)
|
||||||
|
capabilities = new CameraCapabilities
|
||||||
|
{
|
||||||
|
CanPan = cameraCapabilities.CanPan,
|
||||||
|
CanTilt = cameraCapabilities.CanTilt,
|
||||||
|
CanZoom = cameraCapabilities.CanZoom,
|
||||||
|
CanFocus = cameraCapabilities.CanFocus
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
if (Camera is CameraBase cameraBase)
|
||||||
|
capabilities = new CameraCapabilities
|
||||||
|
{
|
||||||
|
CanPan = cameraBase.CanPan,
|
||||||
|
CanTilt = cameraBase.CanTilt,
|
||||||
|
CanZoom = cameraBase.CanZoom,
|
||||||
|
CanFocus = cameraBase.CanFocus
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var message = new CameraStateMessage
|
||||||
{
|
{
|
||||||
cameraManualSupported = Camera is IHasCameraControls,
|
CameraManualSupported = Camera is IHasCameraControls,
|
||||||
cameraAutoSupported = Camera is IHasCameraAutoMode,
|
CameraAutoSupported = Camera is IHasCameraAutoMode,
|
||||||
cameraOffSupported = Camera is IHasCameraOff,
|
CameraOffSupported = Camera is IHasCameraOff,
|
||||||
cameraMode = GetCameraMode(),
|
CameraMode = (eCameraControlMode)Enum.Parse(typeof(eCameraControlMode), GetCameraMode(), true),
|
||||||
hasPresets = Camera is IHasCameraPresets,
|
HasPresets = Camera is IHasCameraPresets,
|
||||||
presets = presetList
|
Presets = presetList,
|
||||||
}), id
|
Capabilities = capabilities,
|
||||||
|
IsFarEnd = Camera is IAmFarEndCamera
|
||||||
|
};
|
||||||
|
|
||||||
|
PostStatusMessage(message, id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,4 +240,59 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// State message for a camera device
|
||||||
|
/// </summary>
|
||||||
|
public class CameraStateMessage : DeviceStateMessageBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera supports manual control
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("cameraManualSupported", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool CameraManualSupported { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera supports auto control
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("cameraAutoSupported", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool CameraAutoSupported { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera supports off control
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("cameraOffSupported", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool CameraOffSupported { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates the current camera control mode
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("cameraMode", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
[JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
|
||||||
|
public eCameraControlMode CameraMode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera has presets
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("hasPresets", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool HasPresets { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List of presets if the camera supports them
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("presets", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public List<CameraPreset> Presets { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates the capabilities of the camera
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("capabilities", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public CameraCapabilities Capabilities { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the camera is a far end camera
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("isFarEnd", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public bool IsFarEnd { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
using System;
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using PepperDash.Essentials.Devices.Common.Cameras;
|
using PepperDash.Essentials.Devices.Common.Cameras;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace PepperDash.Essentials.AppServer.Messengers
|
namespace PepperDash.Essentials.AppServer.Messengers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Messenger for devices that implement the IHasCameras interface.
|
/// Messenger for devices that implement the IHasCameras interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Obsolete("Use IHasCamerasWithControlsMessenger instead. This class will be removed in a future version")]
|
||||||
public class IHasCamerasMessenger : MessengerBase
|
public class IHasCamerasMessenger : MessengerBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using PepperDash.Core;
|
||||||
|
using PepperDash.Core.Logging;
|
||||||
|
using PepperDash.Essentials.Core;
|
||||||
|
using PepperDash.Essentials.Devices.Common.Cameras;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace PepperDash.Essentials.AppServer.Messengers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Messenger for devices that implement the IHasCameras interface.
|
||||||
|
/// </summary>
|
||||||
|
public class IHasCamerasWithControlMessenger : MessengerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Device being bridged that implements IHasCameras interface.
|
||||||
|
/// </summary>
|
||||||
|
public IHasCamerasWithControls CameraController { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Messenger for devices that implement IHasCameras interface.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="cameraController"></param>
|
||||||
|
/// <param name="messagePath"></param>
|
||||||
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
|
public IHasCamerasWithControlMessenger(string key, string messagePath, IHasCamerasWithControls cameraController)
|
||||||
|
: base(key, messagePath, cameraController)
|
||||||
|
{
|
||||||
|
CameraController = cameraController ?? throw new ArgumentNullException("cameraController");
|
||||||
|
CameraController.CameraSelected += CameraController_CameraSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CameraController_CameraSelected(object sender, CameraSelectedEventArgs<IHasCameraControls> e)
|
||||||
|
{
|
||||||
|
var selectedCamera = new KeyName
|
||||||
|
{
|
||||||
|
Key = e.SelectedCamera.Key,
|
||||||
|
Name = e.SelectedCamera.Name
|
||||||
|
};
|
||||||
|
|
||||||
|
PostStatusMessage(new IHasCamerasWithControlsStateMessage
|
||||||
|
{
|
||||||
|
SelectedCamera = selectedCamera
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers the actions for this messenger.
|
||||||
|
/// </summary>
|
||||||
|
/// <exception cref="ArgumentException"></exception>
|
||||||
|
protected override void RegisterActions()
|
||||||
|
{
|
||||||
|
base.RegisterActions();
|
||||||
|
|
||||||
|
AddAction("/fullStatus", (id, context) => SendFullStatus(id));
|
||||||
|
|
||||||
|
AddAction("/cameraListStatus", (id, content) => SendFullStatus(id));
|
||||||
|
|
||||||
|
AddAction("/selectCamera", (id, content) =>
|
||||||
|
{
|
||||||
|
var cameraKey = content?.ToObject<string>();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(cameraKey))
|
||||||
|
{
|
||||||
|
CameraController.SelectCamera(cameraKey);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Content must be a string representing the camera key");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendFullStatus(string clientId)
|
||||||
|
{
|
||||||
|
var cameraList = new List<IKeyName>();
|
||||||
|
KeyName selectedCamera = null;
|
||||||
|
|
||||||
|
foreach (var cam in CameraController.Cameras)
|
||||||
|
{
|
||||||
|
cameraList.Add(new KeyName{
|
||||||
|
Key = cam.Key,
|
||||||
|
Name = cam.Name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CameraController.SelectedCamera != null)
|
||||||
|
{
|
||||||
|
selectedCamera = new KeyName
|
||||||
|
{
|
||||||
|
Key = CameraController.SelectedCamera.Key,
|
||||||
|
Name = CameraController.SelectedCamera.Name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var state = new IHasCamerasWithControlsStateMessage
|
||||||
|
{
|
||||||
|
CameraList = cameraList,
|
||||||
|
SelectedCamera = selectedCamera
|
||||||
|
};
|
||||||
|
|
||||||
|
PostStatusMessage(state, clientId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// State message for devices that implement the IHasCameras interface.
|
||||||
|
/// </summary>
|
||||||
|
public class IHasCamerasWithControlsStateMessage : DeviceStateMessageBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// List of cameras available in the device.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("cameraList", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public List<IKeyName> CameraList { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The currently selected camera on the device.
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("selectedCamera", NullValueHandling = NullValueHandling.Ignore)]
|
||||||
|
public IKeyName SelectedCamera { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class KeyName : IKeyName
|
||||||
|
{
|
||||||
|
public string Key { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public KeyName()
|
||||||
|
{
|
||||||
|
Key = "";
|
||||||
|
Name = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,8 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
|
|
||||||
private readonly string _propName;
|
private readonly string _propName;
|
||||||
|
|
||||||
|
private List<string> _itemKeys = new List<string>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a messenger for a device that implements ISelectableItems<typeparamref name="TKey"/>
|
/// Constructs a messenger for a device that implements ISelectableItems<typeparamref name="TKey"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,9 +41,35 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
|
|
||||||
AddAction("/itemsStatus", (id, content) => SendFullStatus(id));
|
AddAction("/itemsStatus", (id, content) => SendFullStatus(id));
|
||||||
|
|
||||||
|
AddAction("/selectItem", (id, content) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var key = content.ToObject<TKey>();
|
||||||
|
|
||||||
|
if (key == null)
|
||||||
|
{
|
||||||
|
this.LogError("No key specified to select");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (itemDevice.Items.ContainsKey((TKey)Convert.ChangeType(key, typeof(TKey))))
|
||||||
|
{
|
||||||
|
itemDevice.Items[(TKey)Convert.ChangeType(key, typeof(TKey))].Select();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.LogError("Key {0} not found in items", key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
this.LogError("Error selecting item: {0}", e.Message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
itemDevice.ItemsUpdated += (sender, args) =>
|
itemDevice.ItemsUpdated += (sender, args) =>
|
||||||
{
|
{
|
||||||
SendFullStatus();
|
SetItems();
|
||||||
};
|
};
|
||||||
|
|
||||||
itemDevice.CurrentItemChanged += (sender, args) =>
|
itemDevice.CurrentItemChanged += (sender, args) =>
|
||||||
@@ -49,23 +77,47 @@ namespace PepperDash.Essentials.AppServer.Messengers
|
|||||||
SendFullStatus();
|
SendFullStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var input in itemDevice.Items)
|
SetItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the items and registers their update events
|
||||||
|
/// </summary>
|
||||||
|
private void SetItems()
|
||||||
|
{
|
||||||
|
if (_itemKeys != null && _itemKeys.Count > 0)
|
||||||
{
|
{
|
||||||
var key = input.Key;
|
/// Clear out any existing item actions
|
||||||
var localItem = input.Value;
|
foreach (var item in _itemKeys)
|
||||||
|
{
|
||||||
|
RemoveAction($"/{item}");
|
||||||
|
}
|
||||||
|
|
||||||
|
_itemKeys.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var item in itemDevice.Items)
|
||||||
|
{
|
||||||
|
var key = item.Key;
|
||||||
|
var localItem = item.Value;
|
||||||
|
|
||||||
AddAction($"/{key}", (id, content) =>
|
AddAction($"/{key}", (id, content) =>
|
||||||
{
|
{
|
||||||
localItem.Select();
|
localItem.Select();
|
||||||
});
|
});
|
||||||
|
|
||||||
localItem.ItemUpdated += (sender, args) =>
|
_itemKeys.Add(key.ToString());
|
||||||
{
|
|
||||||
SendFullStatus();
|
localItem.ItemUpdated -= LocalItem_ItemUpdated;
|
||||||
};
|
localItem.ItemUpdated += LocalItem_ItemUpdated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LocalItem_ItemUpdated(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SendFullStatus();
|
||||||
|
}
|
||||||
|
|
||||||
private void SendFullStatus(string id = null)
|
private void SendFullStatus(string id = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -405,14 +405,15 @@ namespace PepperDash.Essentials
|
|||||||
messengerAdded = true;
|
messengerAdded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device is CameraBase cameraDevice)
|
// Default to IHasCameraControls if CameraBase and IHasCameraControls
|
||||||
|
if (device is CameraBase cameraDevice && !(device is IHasCameraControls))
|
||||||
{
|
{
|
||||||
this.LogVerbose(
|
this.LogVerbose(
|
||||||
"Adding CameraBaseMessenger for {deviceKey}",
|
"Adding CameraBaseMessenger for {deviceKey}",
|
||||||
device.Key
|
device.Key
|
||||||
);
|
);
|
||||||
|
|
||||||
var cameraMessenger = new CameraBaseMessenger(
|
var cameraMessenger = new CameraBaseMessenger<CameraBase>(
|
||||||
$"{device.Key}-cameraBase-{Key}",
|
$"{device.Key}-cameraBase-{Key}",
|
||||||
cameraDevice,
|
cameraDevice,
|
||||||
$"/device/{device.Key}"
|
$"/device/{device.Key}"
|
||||||
@@ -423,6 +424,21 @@ namespace PepperDash.Essentials
|
|||||||
messengerAdded = true;
|
messengerAdded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device is IHasCameraControls cameraControlDev)
|
||||||
|
{
|
||||||
|
this.LogVerbose(
|
||||||
|
"Adding IHasCamerasWithControlMessenger for {deviceKey}",
|
||||||
|
device.Key
|
||||||
|
);
|
||||||
|
var cameraControlMessenger = new CameraBaseMessenger<IHasCameraControls>(
|
||||||
|
$"{device.Key}-hasCamerasWithControls-{Key}",
|
||||||
|
cameraControlDev,
|
||||||
|
$"/device/{device.Key}"
|
||||||
|
);
|
||||||
|
AddDefaultDeviceMessenger(cameraControlMessenger);
|
||||||
|
messengerAdded = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (device is BlueJeansPc)
|
if (device is BlueJeansPc)
|
||||||
{
|
{
|
||||||
this.LogVerbose(
|
this.LogVerbose(
|
||||||
@@ -975,6 +991,19 @@ namespace PepperDash.Essentials
|
|||||||
messengerAdded = true;
|
messengerAdded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (device is IHasCamerasWithControls cameras2)
|
||||||
|
{
|
||||||
|
this.LogVerbose("Adding IHasCamerasWithControlsMessenger for {deviceKey}", device.Key
|
||||||
|
);
|
||||||
|
var messenger = new IHasCamerasWithControlMessenger(
|
||||||
|
$"{device.Key}-cameras-{Key}",
|
||||||
|
$"/device/{device.Key}",
|
||||||
|
cameras2
|
||||||
|
);
|
||||||
|
AddDefaultDeviceMessenger(messenger);
|
||||||
|
messengerAdded = true;
|
||||||
|
}
|
||||||
|
|
||||||
this.LogVerbose("Trying to cast to generic device for device: {key}", device.Key);
|
this.LogVerbose("Trying to cast to generic device for device: {key}", device.Key);
|
||||||
|
|
||||||
if (device is EssentialsDevice)
|
if (device is EssentialsDevice)
|
||||||
|
|||||||
Reference in New Issue
Block a user