1: using System;
2: using System.Threading;
3: using ManagedNite;
4:
5: namespace DetectingWave
6: {
7: class Program
8: {
9: private static XnMOpenNIContext _context;
10: private static XnMSessionManager _sessionManager;
11: private static XnMWaveDetector _waveDetector;
12: private static Thread _readerThread;
13: private static bool _shouldRun;
14:
15: static void Main()
16: {
17: Console.WriteLine("Iniciando acceso a Kinect ...");
18: _shouldRun = true;
19:
20: InitSensorInteraction();
21: InitThreadReader();
22:
23: Console.WriteLine("Kinect online. Saluda para comenzar");
24: Console.ReadLine();
25: _shouldRun = false:
26: }
27:
28: #region Sensor Interaction
29: private static void InitSensorInteraction()
30: {
31: _context = new XnMOpenNIContext();
32: _context.Init();
33:
34: _sessionManager = new XnMSessionManager(_context, "Wave", "RaiseHand");
35: _waveDetector = new XnMWaveDetector();
36: _waveDetector.Wave += WaveDetectorWave;
37: _sessionManager.AddListener(_waveDetector);
38: }
39:
40: private static void WaveDetectorWave(object sender, EventArgs e)
41: {
42: Console.WriteLine("WAVE detected");
43: }
44: #endregion
45:
46: #region Update Thread
47: private static void InitThreadReader()
48: {
49: _readerThread = new Thread(ReaderThread);
50: _readerThread.Start();
51: }
52: private static void ReaderThread()
53: {
54: while (_shouldRun)
55: {
56: var rc = _context.Update();
57: if (rc == 0)
58: _sessionManager.Update(_context);
59: }
60: }
61: #endregion
62: }
63: }