diff -r 11234537653b -r 92f19af39024 middleware/src/Communication/Server.cs --- a/middleware/src/Communication/Server.cs Fri Mar 09 18:15:12 2012 +0100 +++ b/middleware/src/Communication/Server.cs Thu Mar 15 13:33:21 2012 +0100 @@ -1,5 +1,5 @@ /* - * Projet : KINECT PROJECTS + * Projet : TraKERS * Module : MIDDLEWARE * Sous-Module : Communication * Classe : Server @@ -26,6 +26,7 @@ using Trakers.Tracking; using System.Windows.Media.Media3D; using Trakers.Tracking.Events; +using System.Timers; namespace Trakers.Communication { @@ -37,18 +38,37 @@ //Permet de savoir si un curseur pour la main gauche/droite a été créé. private bool leftHandCursorCreated; private bool rightHandCursorCreated; + private bool messageCreated; + private bool gestureLocked; + + private int timerElapsing; + + System.Timers.Timer _timer; /* * Constructeur : On initialise le serveur avec une adresse et un port, au début les curseurs * ne sont pas créés et on indique au ThreadPool une fonction de callback de manière à vérifier * s'il reçoit des notifications. */ - public Server(String host, int port) + public Server(String host, int port, int _timerElapsing) { + //On démarre le serveur TUIO. server = new TuioServer(host, port); + //On initialise le threadPool (appelé toutes les N ms). + ThreadPool.QueueUserWorkItem(ThreadPoolCallback); + + //Au départ, aucune main n'est dans le champ de recherche et aucune gesture n'est détectée. leftHandCursorCreated = false; rightHandCursorCreated = false; - ThreadPool.QueueUserWorkItem(ThreadPoolCallback); + messageCreated = false; + gestureLocked = false; + + timerElapsing = _timerElapsing; + + //On instancie le timer à N ms. + _timer = new System.Timers.Timer(timerElapsing); + //Dès que le timer est expiré, on appelle _timer_Elapsed. + _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed); } /* @@ -60,10 +80,22 @@ } /* + * Méthode appelée à l'expiration du timer. + */ + public void _timer_Elapsed(object sender, ElapsedEventArgs e) + { + //On débloque la détection de gesture. + gestureLocked = false; + //On arrête le timer. + _timer.Stop(); + } + + /* * Méthode appelée lors d'une notification de type : main gauche entrée dans le champ. */ public void LeftHandTracked(object sender, LeftHandTrackedEventArgs e) { + return; //Si le curseur de la main gauche n'est pas créé, alors on le crée. if (!leftHandCursorCreated) { @@ -82,16 +114,19 @@ */ public void RightHandTracked(object sender, RightHandTrackedEventArgs e) { + return; //Si le curseur de la main droite n'est pas créé, alors on le crée. if (!rightHandCursorCreated) { server.AddTuioCursor(1, SkeletonPointToPoint3D(e.handJoint.Position)); + //server.AddTuioString(1, "BOO"); rightHandCursorCreated = true; } //S'il existe, on le met simplement à jour. else { server.UpdateTuioCursor(1, SkeletonPointToPoint3D(e.handJoint.Position)); + //server.UpdateTuioString(1, "BOO"); } } @@ -100,6 +135,7 @@ */ public void LeftHandQuit(object sender, LeftHandQuitEventArgs e) { + return; //Si le curseur de la main gauche existe, alors on le supprime. if (leftHandCursorCreated) { @@ -113,15 +149,75 @@ */ public void RightHandQuit(object sender, RightHandQuitEventArgs e) { + return; //Si le curseur de la main droite existe, alors on le supprime. if (rightHandCursorCreated) { server.DeleteTuioCursor(1); + //server.DeleteTuioString(1); rightHandCursorCreated = false; } } /* + * Méthode appelée lors d'une notification de type : l'utilisateur fait un swipe. + */ + public void Swipe(object sender, SwipeEventArgs e) + { + if (e.direction == Tracking.Gestures.SwipeDetector.Direction.LEFT) + GesturePerformed("SWIPE LEFT"); + else if (e.direction == Tracking.Gestures.SwipeDetector.Direction.RIGHT) + GesturePerformed("SWIPE RIGHT"); + } + + /* + * Méthode appelée lors d'une notification de type : l'utilisateur fait un push/pull. + */ + public void Pull(object sender, PushEventArgs e) + { + if(e.hand == Tracking.Gestures.PushDetector.Hand.NONE) + return; + + String pushPull = "", hand = ""; + if (e.direction == Tracking.Gestures.PushDetector.Direction.PUSH) + pushPull = "PUSH"; + else + pushPull = "PULL"; + + if (e.hand == Tracking.Gestures.PushDetector.Hand.LEFT) + hand = "LEFT"; + else if (e.hand == Tracking.Gestures.PushDetector.Hand.RIGHT) + hand = "RIGHT"; + else + hand = "BOTH"; + + Console.Out.WriteLine(pushPull + "-" + hand); + + GesturePerformed(pushPull + "-" + hand); + } + + /* + * Méthode appelée lorsqu'une gesture a été détectée et que l'événement approprié a été lancé. + */ + public void GesturePerformed(String code) + { + //Si une gesture a été effectuée, on bloque un certain temps. + if (!gestureLocked) + { + gestureLocked = true; + + //On crée un message contenant le code à envoyer. + if (!messageCreated) + { + messageCreated = true; + server.AddTuioString(1, code); + //On démarre le timer. + _timer.Start(); + } + } + } + + /* * Permet de convertir un point de position de noeud en Point3D. */ private Point3D SkeletonPointToPoint3D(SkeletonPoint p) @@ -144,6 +240,14 @@ server.CommitFrame(); //On attend 25 ms. Thread.Sleep(25); + + //Si une gesture a été effectuée et que le délai d'attente est expiré. + if (messageCreated && !gestureLocked) + { + //On débloque la détection de gesture et on supprime l'objet envoyant les messages OSC de gesture. + messageCreated = false; + server.DeleteTuioString(1); + } } } }