32 #include <scolPlugin.h> 33 #include <scolMemoryHelper.hpp> 47 int SCOL_MYO_CONNECTED_CB = 0;
49 int MYO_DISCONNECTED_CB;
50 int SCOL_MYO_DISCONNECTED_CB = 1;
52 int MYO_ORIENTATION_CB;
53 int SCOL_MYO_ORIENTATION_CB = 2;
56 int SCOL_MYO_ACCEL_CB = 3;
59 int SCOL_MYO_POSE_CB = 4;
61 int MYO_ARMRECOGNIZED_CB;
62 int SCOL_MYO_ARMRECOGNIZED_CB = 5;
65 int SCOL_MYO_ARMLOST_CB = 6;
88 int destroyMyoObj(mmachine m, SCOL_PTR_TYPE handsys,
int handscol)
91 SMyo* myoInstance = MMgetPointer<SMyo*>(m, MTOP(handscol));
95 SMyoManager::GetInstance()->RemoveMyoInstance(myoInstance);
97 MMsetPointer(m, MTOP(handscol), NULL);
100 MMechostr(MSKDEBUG,
"ObjMyo destroyed.\n");
120 MMechostr(0,
"_CRmyoDevice\n");
125 int pUserd = MMpull(m);
126 int pCbkd = MMpull(m);
127 int pUserc = MMpull(m);
128 int pCbkc = MMpull(m);
131 int channel = MMget(m, 0);
136 MMechostr(MSKDEBUG,
"_CRmyoDevice : Channel NIL\n");
140 SMyo* myoInstance = SMyoManager::GetInstance()->AddMyoInstance();
141 if (myoInstance == NULL)
143 MMechostr(MSKDEBUG,
"_CRmyoDevice : myoInstance failed\n");
149 if ((MMpushPointer(m, myoInstance) != 0))
151 SMyoManager::GetInstance()->RemoveMyoInstance(myoInstance);
157 k = OBJcreate(m, OBJ_MYO_SCOL, SCOL_PTR myoInstance, NULL, NULL);
159 if ((k = MMpush(m, pCbkc)))
return k;
160 if ((k = MMpush(m, pUserc)))
return k;
161 if ((k = OBJaddreflex(m, OBJ_MYO_SCOL, SCOL_MYO_CONNECTED_CB)))
return k;
163 if ((k = MMpush(m, pCbkd)))
return k;
164 if ((k = MMpush(m, pUserd)))
return k;
165 if ((k = OBJaddreflex(m, OBJ_MYO_SCOL, SCOL_MYO_DISCONNECTED_CB)))
return k;
184 MMechostr(MSKDEBUG,
"_DSmyoDevice\n");
187 int myoTab = MMget(m, 0);
194 OBJdelTM(m, OBJ_MYO_SCOL, myoTab);
195 MMset(m, 0, ITOM(0));
198 MMechostr(MSKDEBUG,
"ok\n");
214 MMechostr(MSKDEBUG,
"_VibrateMyoDevice\n");
217 int period = MTOI(MMpull(m));
218 int myoTab = MMget(m, 0);
225 SMyo* myoInstance = MMgetPointer<SMyo*>(m, MTOP(myoTab));
226 myo::Myo::VibrationType vtype = myo::Myo::vibrationShort;
229 vtype = myo::Myo::vibrationMedium;
230 else if (period == 2)
231 vtype = myo::Myo::vibrationLong;
233 myoInstance->Vibrate(vtype);
235 MMset(m, 0, ITOM(0));
238 MMechostr(MSKDEBUG,
"ok\n");
253 MMechostr(MSKDEBUG,
"_IsMyoDeviceTrained\n");
256 int myoTab = MMget(m, 0);
264 MMset(m, 0, ITOM(1));
267 MMechostr(MSKDEBUG,
"ok\n");
282 MMechostr(MSKDEBUG,
"_GetMyoArmDirection\n");
285 int myoTab = MMget(m, 0);
292 SMyo* myoInstance = MMgetPointer<SMyo*>(m, MTOP(myoTab));
299 int dir = (myoInstance->GetDirection() == xDirectionTowardWrist) ? 1 : -1;
301 MMset(m, 0, ITOM(dir));
304 MMechostr(MSKDEBUG,
"ok\n");
323 return OBJaddreflex(m, OBJ_MYO_SCOL, SCOL_MYO_ORIENTATION_CB);
326 int getMyoOrientationCb(mmachine m, SCOL_PTR_TYPE
id, LONG param)
340 if (OBJbeginreflex(m, OBJ_MYO_SCOL, SCOL_PTR myoInstance, SCOL_MYO_ORIENTATION_CB))
346 int tuple = MMmalloc(m, 4, TYPETAB);
351 MMstore(m, tuple, 0, FTOM(data->quat.x()));
352 MMstore(m, tuple, 1, FTOM(data->quat.y()));
353 MMstore(m, tuple, 2, FTOM(data->quat.z()));
354 MMstore(m, tuple, 3, FTOM(data->quat.w()));
355 MMpush(m, PTOM(tuple));
357 k=OBJcallreflex(m, 1);
375 return OBJaddreflex(m, OBJ_MYO_SCOL, SCOL_MYO_ACCEL_CB);
378 int getMyoAccelCb(mmachine m, SCOL_PTR_TYPE
id, LONG param)
392 if (OBJbeginreflex(m, OBJ_MYO_SCOL, SCOL_PTR myoInstance, SCOL_MYO_ACCEL_CB))
398 int ftuple = MMmalloc(m, 3, TYPETAB);
403 MMstore(m, ftuple, 0, FTOM(data->svec.x()));
404 MMstore(m, ftuple, 1, FTOM(data->svec.y()));
405 MMstore(m, ftuple, 2, FTOM(data->svec.z()));
406 MMpush(m, PTOM(ftuple));
408 k=OBJcallreflex(m, 1);
426 return OBJaddreflex(m, OBJ_MYO_SCOL, SCOL_MYO_POSE_CB);
429 int getMyoPoseCb(mmachine m, SCOL_PTR_TYPE
id, LONG param)
443 if (OBJbeginreflex(m, OBJ_MYO_SCOL, SCOL_PTR myoInstance, SCOL_MYO_POSE_CB))
449 int pose = (int)data->pose.type();
454 MMpush(m, ITOM(pose));
456 k=OBJcallreflex(m, 1);
462 int getMyoConnectedCb(mmachine m, SCOL_PTR_TYPE
id, LONG param)
471 if (OBJbeginreflex(m, OBJ_MYO_SCOL, SCOL_PTR myoInstance, SCOL_MYO_CONNECTED_CB))
474 k=OBJcallreflex(m, 0);
478 int getMyoDisconnectedCb(mmachine m, SCOL_PTR_TYPE
id, LONG param)
487 if (OBJbeginreflex(m, OBJ_MYO_SCOL, SCOL_PTR myoInstance, SCOL_MYO_DISCONNECTED_CB))
490 k=OBJcallreflex(m, 0);
506 return OBJaddreflex(m, OBJ_MYO_SCOL, SCOL_MYO_ARMRECOGNIZED_CB);
509 int getMyoArmRecognizedCb(mmachine m, SCOL_PTR_TYPE
id, LONG param)
518 if (OBJbeginreflex(m, OBJ_MYO_SCOL, SCOL_PTR myoInstance, SCOL_MYO_ARMRECOGNIZED_CB))
521 MMpush(m, ITOM(param));
523 k=OBJcallreflex(m, 1);
538 return OBJaddreflex(m, OBJ_MYO_SCOL, SCOL_MYO_ARMLOST_CB);
541 int getMyoArmLostCb(mmachine m, SCOL_PTR_TYPE
id, LONG param)
550 if (OBJbeginreflex(m, OBJ_MYO_SCOL, SCOL_PTR myoInstance, SCOL_MYO_ARMLOST_CB))
553 k=OBJcallreflex(m, 0);
567 "_GetMyoArmDirection",
568 "_IsMyoDeviceTrained",
572 "_CBMyoArmRecognized",
579 #define NMYOPKG (sizeof(mMYOname)/sizeof(char*)) 584 int (*mMYOfun[NMYOPKG])(mmachine m)=
603 int mMYOnarg[NMYOPKG]=
622 char* mMYOtype[NMYOPKG]=
626 "fun [Chn fun [ObjMyo u0] u1 u0 fun [ObjMyo u0] u1 u0] ObjMyo",
631 "fun [ObjMyo fun [ObjMyo u0 [F F F F]] u1 u0] ObjMyo",
632 "fun [ObjMyo fun [ObjMyo u0 [F F F]] u1 u0] ObjMyo",
633 "fun [ObjMyo fun [ObjMyo u0 I] u1 u0] ObjMyo",
634 "fun [ObjMyo fun [ObjMyo u0 I] u1 u0] ObjMyo",
635 "fun [ObjMyo fun [ObjMyo u0] u1 u0] ObjMyo" 646 int LoadMyo(mmachine m)
650 MMechostr(MSKDEBUG,
"\n" );
651 MMechostr(MSKDEBUG,
" > Loading MYO Support\n");
654 SMyoManager::GetInstance();
657 OBJ_MYO_SCOL = OBJregister(7 , 0, destroyMyoObj,
"OBJ_MYO_SCOL");
658 k = PKhardpak(m,
"mMYO.pkg-1.0", NMYOPKG, mMYOname, mMYOfun, mMYOnarg, mMYOtype);
660 MYO_CONNECTED_CB = OBJgetUserEvent();
661 OBJdefEvent(MYO_CONNECTED_CB, (
int (__cdecl *)(
struct Mmachine*, SCOL_PTR_TYPE, LONG))getMyoConnectedCb);
663 MYO_DISCONNECTED_CB = OBJgetUserEvent();
664 OBJdefEvent(MYO_DISCONNECTED_CB, (
int (__cdecl *)(
struct Mmachine*, SCOL_PTR_TYPE, LONG))getMyoDisconnectedCb);
666 MYO_ORIENTATION_CB = OBJgetUserEvent();
667 OBJdefEvent(MYO_ORIENTATION_CB, (
int (__cdecl *)(
struct Mmachine*, SCOL_PTR_TYPE, LONG))getMyoOrientationCb);
669 MYO_ACCEL_CB = OBJgetUserEvent();
670 OBJdefEvent(MYO_ACCEL_CB, (
int (__cdecl *)(
struct Mmachine*, SCOL_PTR_TYPE, LONG))getMyoAccelCb);
672 MYO_POSE_CB = OBJgetUserEvent();
673 OBJdefEvent(MYO_POSE_CB, (
int (__cdecl *)(
struct Mmachine*, SCOL_PTR_TYPE, LONG))getMyoPoseCb);
675 MYO_ARMRECOGNIZED_CB = OBJgetUserEvent();
676 OBJdefEvent(MYO_ARMRECOGNIZED_CB, (
int (__cdecl *)(
struct Mmachine*, SCOL_PTR_TYPE, LONG))getMyoArmRecognizedCb);
678 MYO_ARMLOST_CB = OBJgetUserEvent();
679 OBJdefEvent(MYO_ARMLOST_CB, (
int (__cdecl *)(
struct Mmachine*, SCOL_PTR_TYPE, LONG))getMyoArmLostCb);
681 MMechostr(MSKDEBUG,
" > Successfully Loaded\n\n");
687 MMechostr(MSKDEBUG,
"\n" );
688 MMechostr(MSKDEBUG,
" > Unloading MYO Support\n");
691 SMyoManager::GetInstance()->Kill();
693 MMechostr(MSKDEBUG,
" > Successfully unloaded\n\n");
704 extern "C" SCOL_EXPORT
int ScolLoadPlugin(mmachine m, cbmachine w)
716 extern "C" SCOL_EXPORT
int ScolUnloadPlugin()
725 extern "C" SCOL_EXPORT
int ScolMyoLoadPlugin(mmachine m, cbmachine w)
737 extern "C" SCOL_EXPORT
int ScolMyoUnloadPlugin()
int _CBMyoPose(mmachine m)
_CBMyoPose : Called on a pose gesture
int _CRmyoDevice(mmachine m)
_CRmyoDevice : This function create a MYO object
int _CBMyoOrientation(mmachine m)
_CBMyoOrientation : Called on a Orientation data
int _VibrateMyoDevice(mmachine m)
_VibrateMyoDevice : Set a vibration period on MYO object
int _CBMyoArmRecognized(mmachine m)
_CBMyoArmRecognized : Called on when the myo is positionned on the arm
int _IsMyoDeviceTrained(mmachine m)
_IsMyoDeviceTrained : Get the trained state of the MYO object (Deprecated) always return 1 ...
int _DSmyoDevice(mmachine m)
_DSmyoDevice : Destroy MYO object
int _CBMyoArmLost(mmachine m)
_CBMyoArmLost : Called on when the myo is removed from the arm
int _GetMyoArmDirection(mmachine m)
_GetMyoArmDirection : Get the myo direction on the arm
int _CBMyoAccel(mmachine m)
_CBMyoAccel : Called on Acceleration data