await GetKinect in FluentKinect

  • Thread starter Thread starter Greg Duncan
  • Start date Start date
G

Greg Duncan

Guest
Todays project by Marcus Kohnert brings us back to the FluentKinect and Marcus recent update to make it awaitable...

await GetKinect()


In the first blog post about FluentKinect I’ve mentioned that I’m not very happy with the actual process of getting a KinectSensor instance from the KinectSensors collection.

FluentKinect has now been updated and the KinectConnector’s static method GetKinect is now awaitable.

var kinect = await KinectConnector.GetKinect();

kinect.Start();

It’s not thread safe at the moment but there are a few improvements now in my opinion.

    • You can start and debug your actual program without a Kinect controller connected because no more exception is thrown. This helps with Kinect programming on a plane for example.
      db7d4842508cecd296d6dc0607272f2d.gif
    • Your program starts faster because GetKinect returns immediately
    • Since GetKinect returns a Task you get the ability to await the result

Project Information URL: http://passiondev.wordpress.com/2013/07/30/await-getkinect/

Project Download URL: http://www.nuget.org/packages/FluentKinect

Project Source URL: https://github.com/MarcusKohnert/FluentKinect


public static Task<KinectSensor> GetKinect()
{
return Task.Factory.StartNew<KinectSensor>(() =>
{
if (kinectSensor != null) return kinectSensor;

var kinect = KinectSensor.KinectSensors
.FirstOrDefault(_ => _.Status == KinectStatus.Connected);
if (kinect != null)
{
kinectSensor = kinect;
return kinectSensor;
}

using (var signal = new ManualResetEventSlim())
{
KinectSensor.KinectSensors.StatusChanged += (s, e) =>
{
if (e.Status == KinectStatus.Connected)
{
kinectSensor = e.Sensor;
coordinateMapper = new CoordinateMapper(kinectSensor);
signal.Set();
}
};

signal.Wait();
}

return kinectSensor;
});
}

Contact Information:

[Broken External Image]:http://m.webtrends.com/dcs1wotjh100...ntry:RSSView:4177c2a791804cc68f4da21000103fd7

Continue reading...
 
Back
Top