5DT Data Glove plugin 1.0

D:/SVN/Scol/trunk/plugins/glove5DT/src/Glove.cpp

00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OpenSpace3D
00004 For the latest info, see http://www.openspace3d.com
00005 
00006 Copyright (c) 2010 I-maginer
00007 
00008 This program is free software; you can redistribute it and/or modify it under
00009 the terms of the GNU Lesser General Public License as published by the Free Software
00010 Foundation; either version 2 of the License, or (at your option) any later
00011 version.
00012 
00013 This program is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00016 
00017 You should have received a copy of the GNU Lesser General Public License along with
00018 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00019 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00020 http://www.gnu.org/copyleft/lesser.txt
00021 
00022 You may alternatively use this source under the terms of a specific version of
00023 the OpenSpace3D Unrestricted License provided you have obtained such a license from
00024 I-maginer.
00025 -----------------------------------------------------------------------------
00026 */
00027 
00028 /*
00029  5DT Data Glove library based on fglove library
00030  First version : april 2011
00031  Author : Aymeric Suteau
00032 */
00033 
00041 // Include Header File
00042 #include "Glove.h"
00043 
00045 cbmachine ww;
00046 HWND HScol = NULL;
00047 
00049 int OBJGLOVESCOL;
00050 
00052 //===== CB New data (without thumb) ===
00053 int SCOL_GLOVE_NEWDATA_CB                 = 0;
00054 int GLOVE_NEWDATA_CB;
00055 
00056 //===== CB New data (with thumb) ===
00057 int SCOL_GLOVE_NEWDATA_WITHOUT_THUMB_CB   = 1;
00058 int GLOVE_NEWDATA_WITHOUT_THUMB_CB;
00059 
00060 //===== CB New hand gesture ===
00061 int SCOL_GLOVE_HAND_CB                    = 2;
00062 int GLOVE_HAND_CB;
00063 
00064 //===== CB Start of calibration process ===
00065 int SCOL_GLOVE_CALIBRATION_START_CB       = 3;
00066 int GLOVE_CALIBRATION_START_CB;
00067 
00068 //===== CB End of calibration process ===
00069 int SCOL_GLOVE_CALIBRATION_END_CB         = 4;
00070 int GLOVE_CALIBRATION_END_CB;
00071 
00072 
00083 
00084 int destroyGloveObj(mmachine m, int handsys, int gloveTab) 
00085 {
00086         // Read the first element of a TAB element (table of objects)
00087         GloveObject* GloveObj = (GloveObject*) MMfetch(m, MTOP(gloveTab), 0);
00088         if (GloveObj == NULL) 
00089   {
00090                 // Write the first element in the stack, without pulling it
00091                 MMset(m, 0, NIL); 
00092                 return 0; 
00093         }
00094 
00095         // Safely dispose of "GloveObj" pointer
00096         SAFE_DELETE(GloveObj);
00097         // Write the first element of a TAB element
00098         MMstore(m, MTOP(gloveTab), 0, NULL);
00099 
00100         // Display debug message
00101         MMechostr(MSKDEBUG, "GloveObj destroyed.\n");
00102         return 0;
00103 }
00104 
00105 
00115 int _OpenGloveDevice(mmachine m) 
00116 {
00117         #ifdef  _SCOL_DEBUG_
00118                 MMechostr(MSKDEBUG,"_OpenGloveDevice\n");
00119         #endif
00120 
00121         // Declare local variables
00122         int k = 0;
00123   int gestureMode;
00124 
00125   // Test channel
00126   if (MMget(m, 1) == NIL)   // NOTE: Channel is the first parameter, so on the top of the stack... 
00127   {   
00128     MMechostr(MSKDEBUG,"_OpenFusionDevice : channel NIL\n");
00129     m->pp += 1;
00130     return 0;
00131   }
00132 
00133   // Retrieve data type (raw or orientation)
00134         if ((gestureMode = MTOI(MMpull(m))) == NIL)
00135                 gestureMode = GESTURE_WITH_THUMB;  // Default gesture mode : thumb included
00136 
00137         // Create glove instance
00138         GloveObject * glove = new GloveObject();
00139   MMechostr(MSKDEBUG, "_OpenGloveDevice ...new glove instance created !\n");
00140 
00141         // Open glove on USB port
00142   if (!glove->Init(gestureMode)) 
00143   {
00144                 MMechostr(MSKDEBUG, "_OpenGloveDevice ...initialization failed\n");
00145                 SAFE_DELETE(glove) ;
00146                 MMpull(m);                                                              // Pull the channel
00147                 MMpush(m, NIL);                                         // Push NIL on the stack
00148                 return 0;
00149         }
00150   // Start data glove initialization procedure (for the sensors values)
00151   glove->SetInitValuesDone(false);
00152         MMechostr(MSKDEBUG, "_OpenGloveDevice ...initialization successful\n");
00153 
00154   // TEST : Display data glove serial number and USB index port
00155   MMechostr(MSKDEBUG, "_OpenGloveDevice ...serial number : %s\tUSB index : %d\n", glove->GetSerialNumber(), glove->GetUSBIndex());
00156 
00157   // Start callback
00158   glove->SetCallback();
00159 
00160         // Allocate a block in the stack for a table of glove objects
00161         int gloveTab = MMmalloc(m, 1, TYPETAB);
00162         if (gloveTab == NIL) 
00163   {
00164                 MMechostr(MSKDEBUG, "_OpenGloveDevice ...MMmalloc failed\n");
00165                 SAFE_DELETE(glove); 
00166                 MMpull(m);                                                              // Pull the channel
00167                 return MMpush(m, NIL);          // Push NIL on the stack
00168         }
00169         MMechostr(MSKDEBUG, "_OpenGloveDevice ...MMmalloc successful\n");
00170 
00171         // Push the TAB glove object into the stack
00172         MMstore(m, gloveTab, 0, (int)glove);
00173         MMpush(m, PTOM(gloveTab));
00174 
00175         // Create a new glove object
00176         k = OBJcreate(m, OBJGLOVESCOL, (int)glove, NULL, NULL);
00177         MMechostr(MSKDEBUG, "_OpenGloveDevice ...object creation successful\n");
00178 
00179         #ifdef  _SCOL_DEBUG_
00180                 MMechostr(MSKDEBUG,"ok\n");
00181         #endif
00182 
00183         // Return glove object
00184         return k;
00185 }
00186 
00187 
00196 int _CloseGloveDevice(mmachine m) 
00197 {
00198         #ifdef  _SCOL_DEBUG_
00199                 MMechostr(MSKDEBUG,"_CloseGloveDevice\n");
00200         #endif
00201 
00202         // Get the table of glove objects into the stack (without pulling it)
00203         int gloveTab = MMget(m, 0);
00204   MMechostr(MSKDEBUG, "\n_CloseGloveDevice\n");
00205         if (gloveTab == NIL) 
00206   {
00207                 MMechostr(MSKDEBUG, "_CloseGloveDevice ...ObjGlove NIL\n");
00208                 MMset(m, 0, -1);
00209                 return 0;
00210         }
00211 
00212         // Destroy glove object according to its type and magma object
00213   OBJdelTM(m, OBJGLOVESCOL, gloveTab);
00214 
00215         // Reinitialize the stack
00216         MMset(m, 0, 0);
00217 
00218         #ifdef  _SCOL_DEBUG_
00219                 MMechostr(MSKDEBUG,"ok\n");
00220         #endif
00221 
00222         return 0;
00223 }
00224 
00225 
00234 int _GetSerialNumber(mmachine m)
00235 {
00236         #ifdef _SCOL_DEBUG_
00237                 MMechostr(MSKDEBUG,"_GetSerialNumber\n");
00238         #endif
00239 
00240   // Get the table of glove objects into the stack (without pulling it)
00241         int gloveTab = MMget(m, 0);
00242   MMechostr(MSKDEBUG, "_GetSerialNumber\n");
00243         if (gloveTab == NIL)
00244   {
00245                 MMechostr(MSKDEBUG, "_GetSerialNumber ...ObjGlove NIL\n");
00246                 MMset(m, 0, -1);
00247                 return 0;
00248         }
00249 
00250   // Read the first element of a TAB element (table of objects)
00251         GloveObject* GloveObj = (GloveObject*) MMfetch(m, MTOP(gloveTab), 0);
00252         if (GloveObj == NULL) 
00253   {
00254                 // Write the first element in the stack, without pulling it
00255                 MMset(m, 0, NIL); 
00256                 return 0; 
00257         }
00258 
00259   // Remove param from stack
00260         MMpull(m);
00261 
00262         // Put in the stack the return of the function call  
00263   Mpushstrbloc(m, (char*)(GloveObj->GetSerialNumber().c_str()));
00264 
00265   #ifdef _SCOL_DEBUG_
00266                 MMechostr(0,"ok\n");
00267         #endif
00268 
00269   return 0;
00270 }
00271 
00272 
00281 int _GetType(mmachine m) 
00282 {
00283         #ifdef _SCOL_DEBUG_
00284                 MMechostr(MSKDEBUG,"_GetType\n");
00285         #endif
00286 
00287   // Get the table of glove objects into the stack (without pulling it)
00288         int gloveTab = MMget(m, 0);
00289   MMechostr(MSKDEBUG, "_GetType\n");
00290         if (gloveTab == NIL) 
00291   {
00292                 MMechostr(MSKDEBUG, "_GetType ...ObjGlove NIL\n");
00293                 MMset(m, 0, -1);
00294                 return 0;
00295         }
00296 
00297   // Read the first element of a TAB element (table of objects)
00298         GloveObject* GloveObj = (GloveObject*) MMfetch(m, MTOP(gloveTab), 0);
00299         if (GloveObj == NULL) 
00300   {
00301                 // Write the first element in the stack, without pulling it
00302                 MMset(m, 0, NIL); 
00303                 return 0; 
00304         }
00305 
00306   // Remove param from stack
00307         MMpull(m);
00308 
00309         // Put in the stack the return of the function call  
00310   Mpushstrbloc(m, GloveObj->GetType());
00311 
00312   #ifdef _SCOL_DEBUG_
00313                 MMechostr(0,"ok\n");
00314         #endif
00315 
00316   return 0;
00317 }
00318 
00319 
00328 int _GetUSBIndex(mmachine m) 
00329 {
00330         #ifdef _SCOL_DEBUG_
00331                 MMechostr(MSKDEBUG,"_GetUSBIndex\n");
00332         #endif
00333 
00334   // Get the table of glove objects into the stack (without pulling it)
00335         int gloveTab = MMget(m, 0);
00336   MMechostr(MSKDEBUG, "_GetUSBIndex\n");
00337         if (gloveTab == NIL) 
00338   {
00339                 MMechostr(MSKDEBUG, "_GetUSBIndex ...ObjGlove NIL\n");
00340                 MMset(m, 0, -1);
00341                 return 0;
00342         }
00343 
00344   // Read the first element of a TAB element (table of objects)
00345         GloveObject* GloveObj = (GloveObject*) MMfetch(m, MTOP(gloveTab), 0);
00346         if (GloveObj == NULL) 
00347   {
00348                 // Write the first element in the stack, without pulling it
00349                 MMset(m, 0, NIL); 
00350                 return 0; 
00351         }
00352 
00353   // Put USB index into the stack
00354   MMset(m, 0, ITOM(GloveObj->GetUSBIndex()));
00355  
00356   #ifdef _SCOL_DEBUG_
00357                 MMechostr(0,"ok\n");
00358         #endif
00359 
00360   return 0;
00361 }
00362 
00363 
00372 int _Calibrate(mmachine m)
00373 {
00374         #ifdef _SCOL_DEBUG_
00375                 MMechostr(MSKDEBUG,"_Calibrate\n");
00376         #endif
00377 
00378   // Get the table of glove objects into the stack (without pulling it)
00379         int gloveTab = MMget(m, 0);
00380   MMechostr(MSKDEBUG, "_Calibrate\n");
00381         if (gloveTab == NIL) 
00382   {
00383                 MMechostr(MSKDEBUG, "_Calibrate ...ObjGlove NIL\n");
00384                 MMset(m, 0, -1);
00385                 return 0;
00386         }
00387 
00388   // Read the first element of a TAB element (table of objects)
00389         GloveObject* GloveObj = (GloveObject*) MMfetch(m, MTOP(gloveTab), 0);
00390         if (GloveObj == NULL) 
00391   {
00392                 // Write the first element in the stack, without pulling it
00393                 MMset(m, 0, NIL); 
00394                 return 0; 
00395         }
00396 
00397   // Calibrate the data glove
00398   GloveObj->SetCalibrationDone(false);
00399   MMset(m, 0, ITOM(0));
00400   
00401   #ifdef _SCOL_DEBUG_
00402                 MMechostr(0,"ok\n");
00403         #endif
00404 
00405   return 0;
00406 }
00407 
00408 
00420 int _CBGloveNewDataWithThumb(mmachine m) 
00421 {
00422         // Add a reflex
00423         MMechostr(MSKDEBUG, "_CBGloveNewDataWithThumb ...adding reflex\n");
00424         return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_NEWDATA_CB);
00425 }
00426 
00427 
00428 int getGloveNewDataCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00429 {
00430         int k = 0;
00431         int thumbNear = 0, thumbFar = 0;                // Initialize sensors values
00432         int indexNear = 0, indexFar = 0;
00433         int middleNear = 0, middleFar = 0;
00434         int ringNear = 0, ringFar = 0;
00435         int littleNear = 0, littleFar = 0;
00436         int gestureIndex = 0;                                         // Initialize gesture index
00437 
00438         // Cast id parameter to GloveObj type
00439         GloveObject * GloveObj = (GloveObject*) id;
00440   
00441         // Use : OBJbeginreflex(mmachine, type of object, ptr object, callback type)
00442         if (OBJbeginreflex(m, OBJGLOVESCOL, (int)GloveObj, SCOL_GLOVE_NEWDATA_CB)) 
00443   {
00444                 //MMechostr(MSKDEBUG, "getGloveNewDataCb ...ObjGlove not found\n");
00445                 return 0;
00446         }
00447         
00448         // Retrieve sensors values
00449         thumbNear = GloveObj->pValues[FD_THUMBNEAR];
00450         thumbFar = GloveObj->pValues[FD_THUMBFAR];
00451 
00452         indexNear = GloveObj->pValues[FD_INDEXNEAR];
00453         indexFar = GloveObj->pValues[FD_INDEXFAR];
00454 
00455         middleNear = GloveObj->pValues[FD_MIDDLENEAR];
00456         middleFar = GloveObj->pValues[FD_MIDDLEFAR];
00457 
00458         ringNear = GloveObj->pValues[FD_RINGNEAR];
00459         ringFar = GloveObj->pValues[FD_RINGFAR];
00460 
00461         littleNear = GloveObj->pValues[FD_LITTLENEAR];
00462         littleFar = GloveObj->pValues[FD_LITTLEFAR];
00463 
00464         // 1. Create tuple for Thumb sensors
00465         int tupleThumb = MMmalloc(m, 2, TYPETAB);
00466         if (tupleThumb == NIL) 
00467   {
00468                 MMpush(m, NIL);         // Reinitialize the stack       
00469                 return MERRMEM;         // Return an error code (-1)
00470         }
00471         // Write TAB object field by field
00472         MMstore(m, tupleThumb, 0, ITOM(thumbNear));
00473         MMstore(m, tupleThumb, 1, ITOM(thumbFar));
00474 
00475         // Push tuple on the stack
00476   MMpush(m, PTOM(tupleThumb));
00477 
00478         // 2. Create tuple for Index sensors
00479         int tupleIndex = MMmalloc(m, 2, TYPETAB);
00480         if (tupleIndex == NIL) 
00481   {
00482                 MMpush(m, NIL);
00483                 return MERRMEM;
00484         }
00485         MMstore(m, tupleIndex, 0, ITOM(indexNear));
00486         MMstore(m, tupleIndex, 1, ITOM(indexFar));
00487   MMpush(m, PTOM(tupleIndex));
00488 
00489         // 3. Create tuple for Middle sensors
00490         int tupleMiddle = MMmalloc(m, 2, TYPETAB);
00491         if (tupleMiddle == NIL) 
00492   {
00493                 MMpush(m, NIL);
00494                 return MERRMEM;
00495         }
00496         MMstore(m, tupleMiddle, 0, ITOM(middleNear));
00497         MMstore(m, tupleMiddle, 1, ITOM(middleFar));
00498   MMpush(m, PTOM(tupleMiddle)); 
00499 
00500         // 4. Create tuple for Ring sensors
00501         int tupleRing = MMmalloc(m, 2, TYPETAB);
00502         if (tupleRing == NIL) 
00503   {
00504                 MMpush(m, NIL);
00505                 return MERRMEM;
00506         }
00507         MMstore(m, tupleRing, 0, ITOM(ringNear));
00508         MMstore(m, tupleRing, 1, ITOM(ringFar));
00509   MMpush(m, PTOM(tupleRing));   
00510 
00511         // 5. Create tuple for Little sensors
00512         int tupleLittle = MMmalloc(m, 2, TYPETAB);
00513         if (tupleLittle == NIL) 
00514   {
00515                 MMpush(m, NIL);
00516                 return MERRMEM;
00517         }
00518         MMstore(m, tupleLittle, 0, ITOM(littleNear));
00519         MMstore(m, tupleLittle, 1, ITOM(littleFar));
00520   MMpush(m, PTOM(tupleLittle));
00521 
00522         // 6. Current full gesture index (including thumb)
00523   gestureIndex = GloveObj->GetGestureWithThumbIndex();
00524         MMpush(m, ITOM(gestureIndex));
00525 
00526         // Call reflex previously defined (second parameter = number of user parameters)
00527         k = OBJcallreflex(m, 6);
00528         return k;
00529 }
00530 
00531 
00543 int _CBGloveNewDataWithoutThumb(mmachine m) 
00544 {
00545         // Add a reflex
00546         MMechostr(MSKDEBUG, "_CBGloveNewDataWithoutThumb ...adding reflex\n");
00547         return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_NEWDATA_WITHOUT_THUMB_CB);
00548 }
00549 
00550 
00551 int getGloveNewDataWithoutThumbCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret) {
00552         int k = 0;      
00553         int indexNear = 0, indexFar = 0;    // Initialize sensors values
00554         int middleNear = 0, middleFar = 0;
00555         int ringNear = 0, ringFar = 0;
00556         int littleNear = 0, littleFar = 0;
00557         int gestureIndex = 0;                                         // Initialize gesture index
00558 
00559         // Cast id parameter to GloveObj type
00560         GloveObject * GloveObj = (GloveObject*) id;
00561   
00562         // Use : OBJbeginreflex(mmachine, type of object, ptr object, callback type)
00563         if (OBJbeginreflex(m, OBJGLOVESCOL, (int)GloveObj, SCOL_GLOVE_NEWDATA_WITHOUT_THUMB_CB)) 
00564   {
00565                 MMechostr(MSKDEBUG, "getGloveNewDataWithoutThumbCb ...ObjGlove not found\n");
00566                 return 0;
00567         }
00568         
00569         // Retrieve sensors values
00570         indexNear = GloveObj->pValues[FD_INDEXNEAR];
00571         indexFar = GloveObj->pValues[FD_INDEXFAR];
00572 
00573         middleNear = GloveObj->pValues[FD_MIDDLENEAR];
00574         middleFar = GloveObj->pValues[FD_MIDDLEFAR];
00575 
00576         ringNear = GloveObj->pValues[FD_RINGNEAR];
00577         ringFar = GloveObj->pValues[FD_RINGFAR];
00578 
00579         littleNear = GloveObj->pValues[FD_LITTLENEAR];
00580         littleFar = GloveObj->pValues[FD_LITTLEFAR];
00581 
00582         // 1. Create tuple for Index sensors
00583         int tupleIndex = MMmalloc(m, 2, TYPETAB);
00584         if (tupleIndex == NIL) 
00585   {
00586                 MMpush(m, NIL);
00587                 return MERRMEM;
00588         }
00589         MMstore(m, tupleIndex, 0, ITOM(indexNear));
00590         MMstore(m, tupleIndex, 1, ITOM(indexFar));
00591   MMpush(m, PTOM(tupleIndex));
00592 
00593         // 2. Create tuple for Middle sensors
00594         int tupleMiddle = MMmalloc(m, 2, TYPETAB);
00595         if (tupleMiddle == NIL) 
00596   {
00597                 MMpush(m, NIL);
00598                 return MERRMEM;
00599         }
00600         MMstore(m, tupleMiddle, 0, ITOM(middleNear));
00601         MMstore(m, tupleMiddle, 1, ITOM(middleFar));
00602   MMpush(m, PTOM(tupleMiddle)); 
00603 
00604         // 3. Create tuple for Ring sensors
00605         int tupleRing = MMmalloc(m, 2, TYPETAB);
00606         if (tupleRing == NIL) 
00607   {
00608                 MMpush(m, NIL);
00609                 return MERRMEM;
00610         }
00611         MMstore(m, tupleRing, 0, ITOM(ringNear));
00612         MMstore(m, tupleRing, 1, ITOM(ringFar));
00613   MMpush(m, PTOM(tupleRing));   
00614 
00615         // 4. Create tuple for Little sensors
00616         int tupleLittle = MMmalloc(m, 2, TYPETAB);
00617         if (tupleLittle == NIL) 
00618   {
00619                 MMpush(m, NIL);
00620                 return MERRMEM;
00621         }
00622         MMstore(m, tupleLittle, 0, ITOM(littleNear));
00623         MMstore(m, tupleLittle, 1, ITOM(littleFar));
00624   MMpush(m, PTOM(tupleLittle));
00625 
00626         // 5. Current gesture index (excluding thumb)
00627         gestureIndex = GloveObj->GetGestureIndex();
00628         MMpush(m, ITOM(gestureIndex));
00629 
00630         // Call reflex previously defined (second parameter = number of user parameters)
00631         k = OBJcallreflex(m, 5);
00632         return k;
00633 }
00634 
00635 
00647 int _CBGloveHand(mmachine m) 
00648 {
00649         // Add a reflex
00650         MMechostr(MSKDEBUG, "_CBGloveHand ...adding reflex\n");
00651         return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_HAND_CB);
00652 }
00653 
00654 
00655 int getGloveHandCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret) 
00656 {
00657         int k = 0;
00658         int gestureIndex = 0;   // Initialize gesture index
00659 
00660         // Cast id parameter to GloveObj type
00661         GloveObject * GloveObj = (GloveObject*) id;
00662 
00663         // Use : OBJbeginreflex(mmachine, type of object, ptr object, callback type)
00664         if (OBJbeginreflex(m, OBJGLOVESCOL, (int)GloveObj, SCOL_GLOVE_HAND_CB)) 
00665   {
00666     //MMechostr(MSKDEBUG, "getGloveHandCb ...ObjGlove not found\n");
00667                 return 0;
00668         }
00669 
00670         // Retrieve current gesture index (recognized gestures : 0 for closed hand, 15 for flat hand)
00671         //gestureIndex = GloveObj->GetGestureIndex();           // Get gesture index
00672   gestureIndex = GloveObj->GetGestureWithThumbIndex();    // Get new gesture index (including thumb)
00673         //MMechostr(MSKDEBUG, "...gestureIndex (with thumb) = %d\n", gestureIndex);
00674         MMpush(m, ITOM(gestureIndex));
00675 
00676         // Call reflex previously defined
00677         k = OBJcallreflex(m, 1);
00678         return k;
00679 }
00680 
00681 
00693 int _CBCalibrationStart(mmachine m) 
00694 {
00695         // Add a reflex
00696         MMechostr(MSKDEBUG, "_CBCalibrationStart ...adding reflex\n");
00697         return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_CALIBRATION_START_CB);
00698 }
00699 
00700 
00701 int getCalibrationStartCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret) 
00702 {
00703   int k = 0;    
00704   
00705   // Cast id parameter to GloveObj type
00706         GloveObject * GloveObj = (GloveObject*) id;
00707 
00708         // Use : OBJbeginreflex(mmachine, type of object, ptr object, callback type)
00709         if (OBJbeginreflex(m, OBJGLOVESCOL, (int)GloveObj, SCOL_GLOVE_CALIBRATION_START_CB)) 
00710   {
00711     MMechostr(MSKDEBUG, "getCalibrationStartCb ...ObjGlove not found\n");
00712                 return 0;
00713         }
00714 
00715         // Call reflex previously defined
00716         k = OBJcallreflex(m, 0);
00717         return k;
00718 }
00719 
00720 
00732 int _CBCalibrationEnd(mmachine m) 
00733 {
00734         // Add a reflex
00735         MMechostr(MSKDEBUG, "_CBCalibrationEnd ...adding reflex\n");
00736         return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_CALIBRATION_END_CB);
00737 }
00738 
00739 
00740 int getCalibrationEndCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00741 {
00742   int k = 0;
00743 
00744         // Cast id parameter to GloveObj type
00745         GloveObject * GloveObj = (GloveObject*) id;
00746 
00747         // Use : OBJbeginreflex(mmachine, type of object, ptr object, callback type)
00748         if (OBJbeginreflex(m, OBJGLOVESCOL, (int)GloveObj, SCOL_GLOVE_CALIBRATION_END_CB)) 
00749   {
00750     MMechostr(MSKDEBUG, "getCalibrationEndCb ...ObjGlove not found\n");
00751                 return 0;
00752         }
00753 
00754         // Call reflex previously defined
00755         k = OBJcallreflex(m, 0);
00756         return k;
00757 }
00758 
00759 
00760 
00768 
00769 
00771 #define NbTplPKG        12
00772 
00773 
00777 char    *TplName[NbTplPKG] =
00778 {
00779         "ObjGlove",
00780         "_OpenGloveDevice",
00781         "_CloseGloveDevice",
00782         "_CBGloveNewDataWithThumb",
00783   "_CBGloveNewDataWithoutThumb",
00784         "_CBGloveHand",
00785   "_CBCalibrationStart",
00786   "_CBCalibrationEnd",
00787   "_GetSerialNumber",
00788   "_GetType",
00789   "_GetUSBIndex",
00790   "_Calibrate"
00791 };
00792 
00793 
00797 int (*TplFunc[NbTplPKG])(mmachine m)=
00798 {
00799         NULL,                                                                                                                                                           // ObjGlove
00800         _OpenGloveDevice,                                                                                                               // _OpenGloveDevice
00801         _CloseGloveDevice,                                                                                                      // _CloseGloveDevice
00802         _CBGloveNewDataWithThumb,                                                                               // _CBGloveNewDataWithThumb
00803   _CBGloveNewDataWithoutThumb,                                                          // _CBGloveNewDataWithoutThumb
00804         _CBGloveHand,                                                                                                                           // _CBGloveHand
00805   _CBCalibrationStart,                        // _CBCalibrationStart
00806   _CBCalibrationEnd,                          // _CBCalibrationEnd
00807   _GetSerialNumber,                           // _GetSerialNumber
00808   _GetType,                                   // _GetType
00809   _GetUSBIndex,                               // _GetUSBIndex
00810   _Calibrate                                  // _Calibrate
00811 };
00812 
00813 
00817 int TplNArg[NbTplPKG]=
00818 {
00819         TYPTYPE,                                                                                                                                                // ObjGlove
00820         2,                                                                                                                                                                      // _OpenGloveDevice
00821         1,                                                                                                                                                                      // _CloseGloveDevice
00822         3,                                                                                                                                                                      // _CBGloveNewDataWithThumb
00823   3,                                                                                                                                                                    // _CBGloveNewDataWithoutThumb
00824         3,                                                                                                                                                                      // _CBGloveHand
00825   3,                                          // _CBCalibrationStart
00826   3,                                          // _CBCalibrationEnd
00827   1,                                          // _GetSerialNumber
00828   1,                                          // _GetType
00829   1,                                          // _GetUSBIndex
00830   1                                           // _Calibrate
00831 };
00832 
00833 
00837 char* TplType[NbTplPKG]=
00838 {
00839         NULL,                                                                                                                                                                                                   // ObjGlove
00840         "fun [Chn I] ObjGlove",                                                                                                                                                       // _OpenGloveDevice
00841         "fun [ObjGlove] I",                                                                                                                                                                     // _CloseGloveDevice
00842         "fun [ObjGlove fun [ObjGlove u0 [I I] [I I] [I I] [I I] [I I] I] u1 u0] ObjGlove",      // _CBGloveNewDataWithThumb
00843   "fun [ObjGlove fun [ObjGlove u0 [I I] [I I] [I I] [I I] I] u1 u0] ObjGlove",        // _CBGloveNewDataWithoutThumb
00844         "fun [ObjGlove fun [ObjGlove u0 I] u1 u0] ObjGlove",                                                                                  // _CBGloveHand
00845   "fun [ObjGlove fun [ObjGlove u0] u1 u0] ObjGlove",                                    // _CBCalibrationStart
00846   "fun [ObjGlove fun [ObjGlove u0] u1 u0] ObjGlove",                                    // _CBCalibrationEnd
00847   "fun [ObjGlove] S",                                                                 // _GetSerialNumber
00848   "fun [ObjGlove] S",                                                                 // _GetType
00849   "fun [ObjGlove] I",                                                                 // _GetUSBIndex
00850   "fun [ObjGlove] I"                                                                  // _Calibrate
00851 };
00852 
00853 
00861 // Everything inside _cond and _endcond is ignored by doxygen
00863 
00868 int LoadGlove(mmachine m) 
00869 {
00870   // Return variable for PKhardpak function
00871         int k;
00872 
00873         // Declare a new type of object ("OBJGLOVESCOL")
00874         OBJGLOVESCOL = OBJregister(5, 1, destroyGloveObj, "OBJGLOVESCOL");
00875 
00876         // Get new user events and associate these events with a callback
00877         GLOVE_NEWDATA_CB = OBJgetUserEvent();
00878         OBJdefEvent(GLOVE_NEWDATA_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getGloveNewDataCb);
00879   
00880   GLOVE_NEWDATA_WITHOUT_THUMB_CB = OBJgetUserEvent();
00881         OBJdefEvent(GLOVE_NEWDATA_WITHOUT_THUMB_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getGloveNewDataWithoutThumbCb);
00882 
00883         GLOVE_HAND_CB = OBJgetUserEvent();
00884         OBJdefEvent(GLOVE_HAND_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getGloveHandCb);
00885 
00886   GLOVE_CALIBRATION_START_CB = OBJgetUserEvent();
00887         OBJdefEvent(GLOVE_CALIBRATION_START_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getCalibrationStartCb);
00888 
00889   GLOVE_CALIBRATION_END_CB = OBJgetUserEvent();
00890         OBJdefEvent(GLOVE_CALIBRATION_END_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getCalibrationEndCb);
00891 
00892         // Load package
00893         k = PKhardpak(m, "GloveEngine", NbTplPKG, TplName, TplFunc, TplNArg, TplType);
00894         return k;
00895 }
00897 
00898 
00903 extern "C" __declspec (dllexport) int SCOLloadGLOVE(mmachine m, cbmachine w) 
00904 {
00905         SCOLinitplugin(w);
00906 
00907         // Get Scol window handle (for message callback)
00908         HScol = (HWND)SCgetExtra("hscol");
00909 
00910         // Display debug message
00911         MMechostr(MSKDEBUG, "SCOLloadGLOVE loading Glove DLL ...\n");
00912         
00913         LoadGlove(m);
00914         return 0;
00915 }
00916 
00917 
00922 extern "C" __declspec (dllexport) int SCOLfreeGLOVE() 
00923 {
00924         // Display debug messages
00925         MMechostr(MSKDEBUG, "Release Glove DLL\n");
00926         MMechostr(MSKDEBUG, "Glove DLL CLOSED...\n\n" );
00927 
00928         return 0;
00929 }