5DT Data Glove plugin  1.0
GloveCalibration.cpp
1 //###################################################################################
2 //# Glove Calibration #
3 //# Used To Handle a 5DT Glove #
4 //# Author : #
5 //# NGUYEN Thanh Tu #
6 //###################################################################################
7 
8 // TODO : handle object supression while calibration ?
9 // TODO : properly send a message that the calibration has stopped
10 
11 /* HEADER INCLUDE */
12 #include "GloveCalibration.h"
13 #include "GloveObject.h"
14 #include "GlovePlugin.h"
15 
16 
17 /*-------------------------- CONSTRUCTOR AND DESTRUCTOR ---------------------------*/
19 {
20  //FORBIDDEN : PRIVATE
21 }
22 
24 {
25  glove=gloveObject;
26  isRunning=false;
27 }
28 
30 {
31  // demander arret...
32  // TODO
33 
34  // attendre arret...
35  // TODO
36 
37  // Destroy Thread
38  stop();
39 
40 }
41 
42 bool GloveCalibration::GetIsRunning()
43 {
44  return isRunning;
45 }
46 
47 // Begin the auto calibration of the glove
49 {
50  time_t startTime, currentTime;
51 
52  isRunning=true;
53  // TODO : change that (main loop)
54  // Notify Scol window that the calibration has started
55  OBJpostEvent(GLOVE_CALIBRATION_START_CB, (int)glove, 0);
56 
57  MMechostr(MSKDEBUG, "-> Beginning of calibration... \n");
58  fdResetCalibrationAll(glove->GetGlove());
59 
60  // Enable auto calibration
61  fdSetAutoCalibrate(glove->GetGlove(), TRUE);
62 
63  // Start calibration : the process will last 5 seconds
64  // During this period, the user must open/close his hand several times to complete calibration process
65  time(&startTime);
66  do
67  {
68  time(&currentTime);
69  //TODO : tant qu'il n'y a pas d'arret demandé
70  } while ((currentTime - startTime) < 5);
71 
72  // Disable auto calibration
73  fdSetAutoCalibrate(glove->GetGlove(), FALSE);
74 
75  // TODO : change that... where ?
76  // Seems that the SCOL never receive this...
77  // Notify Scol window that the calibration has ended
78  OBJpostEvent(GLOVE_CALIBRATION_END_CB, (int)glove, 0);
79 
80  MMechostr(MSKDEBUG, "-> Calibration done for %s.\n", glove->GetTypeName().c_str());
81  isRunning=false;
82 }
83 /*
84 void GloveObject::run()
85 {
86  try
87  {
88  while(isRunning)
89  {
90  // TODO : Handle USB disconnection of the data glove
91  // Will be implemented by 5DT Technical support in a few days
92 
93  // Calibration
94 
95  // Initialize data glove sensors values
96  else if (!bInitValuesDone)
97  {
98  InitValues();
99  }
100  }
101  // Release connection to the data glove
102  if (Close() == 0)
103  {
104  pGlove = NULL;
105  }
106  }
107  catch (ThreadException ex)
108  {
109  MMechostr(MSKDEBUG, "error thread : %s\n", ex.getMessage().c_str());
110  }
111 
112 }*/