39 #include "GlovePlugin.h"
50 int SCOL_GLOVE_NEWDATA_CB = 0;
54 int SCOL_GLOVE_GESTURE_CB = 1;
58 int SCOL_GLOVE_CALIBRATION_START_CB = 2;
59 int GLOVE_CALIBRATION_START_CB;
62 int SCOL_GLOVE_CALIBRATION_END_CB = 3;
63 int GLOVE_CALIBRATION_END_CB;
77 int destroyGloveObj(mmachine m,
int handsys,
int gloveTab)
89 SAFE_DELETE(GloveObj);
91 MMstore(m, MTOP(gloveTab), 0, NULL);
94 MMechostr(MSKDEBUG,
"GloveObj destroyed.\n");
110 MMechostr(MSKDEBUG,
"_DTGloveOpenDevice\n");
117 if (MMget(m, 0) == NIL)
119 MMechostr(MSKDEBUG,
"_OpenFusionDevice : channel NIL\n");
125 MMechostr(MSKDEBUG,
"_DTGloveOpenDevice ...new glove instance created !\n");
130 MMechostr(MSKDEBUG,
"_DTGloveOpenDevice ...initialization failed\n");
136 MMechostr(MSKDEBUG,
"_DTGloveOpenDevice ...initialization successful\n");
139 MMechostr(MSKDEBUG,
"_DTGloveOpenDevice ...serial number : %s\tUSB index : %d\n", glove->GetSerialNumber(), glove->GetUSBPortIndex());
142 int gloveTab = MMmalloc(m, 1, TYPETAB);
145 MMechostr(MSKDEBUG,
"_DTGloveOpenDevice ...MMmalloc failed\n");
150 MMechostr(MSKDEBUG,
"_DTGloveOpenDevice ...MMmalloc successful\n");
153 MMstore(m, gloveTab, 0, (
int)glove);
154 MMpush(m, PTOM(gloveTab));
157 k = OBJcreate(m, OBJGLOVESCOL, (
int)glove, NIL, 0);
158 MMechostr(MSKDEBUG,
"_DTGloveOpenDevice ...object creation successful\n");
161 MMechostr(MSKDEBUG,
"ok\n");
180 MMechostr(MSKDEBUG,
"_DTGloveCloseDevice\n");
184 int gloveTab = MMget(m, 0);
185 MMechostr(MSKDEBUG,
"\n_DTGloveCloseDevice\n");
188 MMechostr(MSKDEBUG,
"_DTGloveCloseDevice ...ObjGlove NIL\n");
194 OBJdelTM(m, OBJGLOVESCOL, gloveTab);
200 MMechostr(MSKDEBUG,
"ok\n");
218 MMechostr(MSKDEBUG,
"_DTGloveGetSerialNumber\n");
222 int gloveTab = MMget(m, 0);
223 MMechostr(MSKDEBUG,
"_DTGloveGetSerialNumber\n");
226 MMechostr(MSKDEBUG,
"_DTGloveGetSerialNumber ...ObjGlove NIL\n");
233 if (GloveObj == NULL)
244 Mpushstrbloc(m, (
char*)(GloveObj->GetSerialNumber().c_str()));
265 MMechostr(MSKDEBUG,
"_DTGloveGetType\n");
269 int gloveTab = MMget(m, 0);
270 MMechostr(MSKDEBUG,
"_DTGloveGetType\n");
273 MMechostr(MSKDEBUG,
"_DTGloveGetType ...ObjGlove NIL\n");
280 if (GloveObj == NULL)
291 Mpushstrbloc(m, const_cast<char*>(GloveObj->GetTypeName().c_str()));
312 MMechostr(MSKDEBUG,
"_DTGloveGetUSBIndex\n");
316 int gloveTab = MMget(m, 0);
317 MMechostr(MSKDEBUG,
"_DTGloveGetUSBIndex\n");
320 MMechostr(MSKDEBUG,
"_DTGloveGetUSBIndex ...ObjGlove NIL\n");
327 if (GloveObj == NULL)
335 MMset(m, 0, ITOM(GloveObj->GetUSBPortIndex()));
356 MMechostr(MSKDEBUG,
"_DTGloveCalibrate\n");
360 int gloveTab = MMget(m, 0);
361 MMechostr(MSKDEBUG,
"_DTGloveCalibrate\n");
364 MMechostr(MSKDEBUG,
"_DTGloveCalibrate ...ObjGlove NIL\n");
371 if (GloveObj == NULL)
379 GloveObj->StartCalibration();
380 MMset(m, 0, ITOM(0));
404 return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_NEWDATA_CB);
407 int getGloveRawDataCb(mmachine m, UINT
id, LONG msg_ptr)
411 float* data = (
float*) msg_ptr;
414 if (OBJbeginreflex(m, OBJGLOVESCOL, (
int)GloveObj, SCOL_GLOVE_NEWDATA_CB))
420 for (
int i = 0; i < 5; i++)
422 int tupleFinger = MMmalloc(m, 2, TYPETAB);
423 if (tupleFinger == NIL)
427 MMstore(m, tupleFinger, 0, FTOM(data[3*i]));
428 MMstore(m, tupleFinger, 1, FTOM(data[3*i+2]));
429 MMpush(m, PTOM(tupleFinger));
433 int tupleAbduction = MMmalloc(m, 4, TYPETAB);
434 for (
int i = 0; i < 4; i++)
436 if (tupleAbduction == NIL)
440 MMstore(m, tupleAbduction, i, FTOM(data[3*i+2]));
442 MMpush(m, PTOM(tupleAbduction));
445 int tuplePW = MMmalloc(m, 2, TYPETAB);
449 MMstore(m, tuplePW, 0, FTOM(data[14]));
450 MMstore(m, tuplePW, 1, FTOM(data[15]));
451 MMpush(m, PTOM(tuplePW));
454 int tuplePR = MMmalloc(m, 2, TYPETAB);
459 MMstore(m, tuplePR, 0, FTOM(data[16]));
460 MMstore(m, tuplePR, 1, FTOM(data[17]));
461 MMpush(m, PTOM(tuplePR));
467 return OBJcallreflex(m, 8);
483 MMechostr(MSKDEBUG,
"_CBDTGloveGesture ...adding reflex\n");
484 return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_GESTURE_CB);
488 int getGloveGestureCb(mmachine m, UINT
id, LONG gesture)
494 if (OBJbeginreflex(m, OBJGLOVESCOL, (
int)GloveObj, SCOL_GLOVE_GESTURE_CB))
500 MMpush(m, ITOM(gesture));
503 return OBJcallreflex(m, 1);
520 MMechostr(MSKDEBUG,
"_CBDTGloveCalibrationStart ...adding reflex\n");
521 return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_CALIBRATION_START_CB);
525 int getCalibrationStartCb(mmachine m, UINT
id, LONG param)
533 if (OBJbeginreflex(m, OBJGLOVESCOL, (
int)GloveObj, SCOL_GLOVE_CALIBRATION_START_CB))
535 MMechostr(MSKDEBUG,
"getCalibrationStartCb ...ObjGlove not found\n");
540 k = OBJcallreflex(m, 0);
558 MMechostr(MSKDEBUG,
"_CBDTGloveCalibrationEnd ...adding reflex\n");
559 return OBJaddreflex(m, OBJGLOVESCOL, SCOL_GLOVE_CALIBRATION_END_CB);
562 int getCalibrationEndCb(mmachine m, UINT
id, LONG param)
570 if (OBJbeginreflex(m, OBJGLOVESCOL, (
int)GloveObj, SCOL_GLOVE_CALIBRATION_END_CB))
572 MMechostr(MSKDEBUG,
"getCalibrationEndCb ...ObjGlove not found\n");
577 k = OBJcallreflex(m, 0);
599 char *TplName[NbTplPKG] =
602 "_DTGloveOpenDevice",
603 "_DTGloveCloseDevice",
606 "_CBDTGloveCalibrationStart",
607 "_CBDTGloveCalibrationEnd",
608 "_DTGloveGetSerialNumber",
610 "_DTGloveGetUSBIndex",
618 int (*TplFunc[NbTplPKG])(mmachine m)=
637 int TplNArg[NbTplPKG]=
656 char* TplType[NbTplPKG]=
659 "fun [Chn] ObjGlove",
661 "fun [ObjGlove fun [ObjGlove u0 [F F] [F F] [F F] [F F] [F F] [F F F F] [F F] [F F]] u1 u0] ObjGlove",
662 "fun [ObjGlove fun [ObjGlove u0 I] u1 u0] ObjGlove",
663 "fun [ObjGlove fun [ObjGlove u0] u1 u0] ObjGlove",
664 "fun [ObjGlove fun [ObjGlove u0] u1 u0] ObjGlove",
686 int LoadGlove(mmachine m)
692 OBJGLOVESCOL = OBJregister(4, 1, destroyGloveObj,
"OBJGLOVESCOL");
695 GLOVE_NEWDATA_CB = OBJgetUserEvent();
696 OBJdefEvent(GLOVE_NEWDATA_CB, (
int (__cdecl *)(
struct Mmachine *, UINT, LONG))getGloveRawDataCb);
698 GLOVE_HAND_CB = OBJgetUserEvent();
699 OBJdefEvent(GLOVE_HAND_CB, (
int (__cdecl *)(
struct Mmachine *, UINT, LONG))getGloveGestureCb);
701 GLOVE_CALIBRATION_START_CB = OBJgetUserEvent();
702 OBJdefEvent(GLOVE_CALIBRATION_START_CB, (
int (__cdecl *)(
struct Mmachine *, UINT, LONG))getCalibrationStartCb);
704 GLOVE_CALIBRATION_END_CB = OBJgetUserEvent();
705 OBJdefEvent(GLOVE_CALIBRATION_END_CB, (
int (__cdecl *)(
struct Mmachine *, UINT, LONG))getCalibrationEndCb);
708 k = PKhardpak(m,
"GloveEngine", NbTplPKG, TplName, TplFunc, TplNArg, TplType);
719 #if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
720 __declspec (dllexport)
722 int ScolLoadPlugin(mmachine m, cbmachine w)
727 HScol = (HWND)SCgetExtra(
"hscol");
738 #if SCOL_PLATFORM == SCOL_PLATFORM_WINDOWS
739 __declspec (dllexport)
741 int ScolUnloadPlugin()