You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.9 KiB
104 lines
2.9 KiB
using Microsoft.Kinect;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
|
|
namespace Lib
|
|
{
|
|
public class KinectManager : INotifyPropertyChanged
|
|
{
|
|
private KinectSensor sensor;
|
|
public KinectSensor Sensor {
|
|
get {
|
|
return sensor;
|
|
}
|
|
set
|
|
{
|
|
sensor = value;
|
|
OnPropertyChanged(nameof(Sensor));
|
|
}
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
protected virtual void OnPropertyChanged(string propertyName)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
public KinectManager()
|
|
{
|
|
sensor = KinectSensor.GetDefault();
|
|
if (Sensor == null)
|
|
{
|
|
StatusText = "Kinect n'est pas connecté";
|
|
}
|
|
else if (!Sensor.IsOpen)
|
|
{
|
|
StatusText = "Kinect n'est pas ouvert";
|
|
}
|
|
else if (Sensor.IsAvailable)
|
|
{
|
|
StatusText = "Kinect est disponible";
|
|
}
|
|
else
|
|
{
|
|
StatusText = "Kinect n'est pas disponible";
|
|
}
|
|
}
|
|
public void StartSensor()
|
|
{
|
|
if (sensor != null) {
|
|
sensor.Open();
|
|
}
|
|
else {
|
|
sensor = KinectSensor.GetDefault();
|
|
sensor.Open();
|
|
}
|
|
}
|
|
public void StopSensor()
|
|
{
|
|
if (sensor != null)
|
|
{
|
|
sensor.Close();
|
|
sensor = null;
|
|
}
|
|
}
|
|
public bool Status
|
|
{
|
|
get { return Sensor != null && Sensor.IsAvailable; }
|
|
}
|
|
private string _statusText;
|
|
public string StatusText
|
|
{
|
|
get { return _statusText; }
|
|
set {
|
|
_statusText = value;
|
|
if(this.PropertyChanged != null)
|
|
{
|
|
this.PropertyChanged(this, new PropertyChangedEventArgs("StatusText"));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs args)
|
|
{
|
|
if (Sensor == null)
|
|
{
|
|
StatusText = "Kinect n'est pas connecté";
|
|
}
|
|
else if (!Sensor.IsOpen)
|
|
{
|
|
StatusText = "Kinect n'est pas ouvert";
|
|
}
|
|
else if (Sensor.IsAvailable)
|
|
{
|
|
StatusText = "Kinect est disponible";
|
|
}
|
|
else
|
|
{
|
|
StatusText = "Kinect n'est pas disponible";
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|