32#include <scolMemoryHelper.hpp>
46int SCOL_VRPN_ANALOG_CB = 0;
49int SCOL_VRPN_BTN_CB = 1;
51int SCOL_VRPN_BTN_STATE_CB = 2;
54int SCOL_VRPN_TRACKER_CB = 3;
55int VRPN_TRACKER_VEL_CB;
56int SCOL_VRPN_TRACKER_VEL_CB = 4;
57int VRPN_TRACKER_ACC_CB;
58int SCOL_VRPN_TRACKER_ACC_CB = 5;
61int SCOL_VRPN_DIAL_CB = 6;
64int SCOL_VRPN_TEXT_CB = 7;
87int destroyVRPNObj(mmachine m, SCOL_PTR_TYPE handsys,
int handscol)
90 SVrpn* vrpnObj = MMgetPointer<SVrpn*>(m, MTOP(handscol));
93 sVrpnThread::GetInstance()->RemoveDevice(vrpnObj);
95 MMsetPointer<SVrpn*>(m, MTOP(handscol), 0);
98 MMechostr(MSKDEBUG,
"ObjVRPN destroyed.\n");
116 MMechostr(0,
"_CRvrpnDevice\n");
121 int sDevice = MMpull(m);
122 int sHost = MMpull(m);
125 int channel = MMget(m, 0);
128 if (channel == NIL || sDevice == NIL)
130 MMechostr(MSKDEBUG,
"Channel NIL\n");
135 std::string hostName =
"localhost";
138 hostName = MMstartstr(m, MTOP(sHost));
140 std::string deviceName = MMstartstr(m, MTOP(sDevice));
141 SVrpn* vrpnObj = sVrpnThread::GetInstance()->AddDevice(hostName, deviceName);
144 MMechostr(MSKDEBUG,
"vrpnObj failed\n");
150 if ((MMpushPointer(m, vrpnObj) != 0))
152 sVrpnThread::GetInstance()->RemoveDevice(vrpnObj);
158 k = OBJcreate(m, OBJ_VRPN_SCOL, SCOL_PTR vrpnObj, NIL, 0);
177 MMechostr(MSKDEBUG,
"_DSvrpnDevice\n");
180 int vrpnTab = MMget(m,0);
187 OBJdelTM(m, OBJ_VRPN_SCOL, vrpnTab);
188 MMset(m, 0, ITOM(0));
191 MMechostr(MSKDEBUG,
"ok\n");
211 int vrpnTab = MMget(m, 2);
212 int cb = MMget(m, 1);
216 SVrpn* vrpnObj = MMgetPointer<SVrpn*>(m, MTOP(vrpnTab));
217 vrpnObj->EnableAnalogData(cb == NIL ?
false :
true);
221 MMechostr(MSKDEBUG,
"_CBvrpnAnalogData ...adding reflex\n");
222 return OBJaddreflex(m, OBJ_VRPN_SCOL, SCOL_VRPN_ANALOG_CB);
228int getVRPNAnalogCb(mmachine m, SCOL_PTR_TYPE wParam, SCOL_PTR_TYPE lParam)
234 if (OBJbeginreflex(m, OBJ_VRPN_SCOL, SCOL_PTR vrpnObj, SCOL_VRPN_ANALOG_CB))
236 MMechostr(MSKDEBUG,
"ObjVRPN callback not found\n");
241 for (
unsigned int i = 0; i < vrpnData->analogData.size(); i++)
243 if (MMpush(m, FTOM(vrpnData->analogData[i])))
250 for(
unsigned int j = 0; j < vrpnData->analogData.size(); j++)
255 if (
int k=MBdeftab(m))
260 int k = OBJcallreflex(m, 1 );
282 int vrpnTab = MMget(m, 2);
283 int cb = MMget(m, 1);
287 SVrpn* vrpnObj = MMgetPointer<SVrpn*>(m, MTOP(vrpnTab));
288 vrpnObj->EnableButtonData(cb == NIL ?
false :
true);
292 MMechostr(MSKDEBUG,
"_CBvrpnButtonData ...adding reflex\n");
293 return OBJaddreflex(m, OBJ_VRPN_SCOL, SCOL_VRPN_BTN_CB);
299int getVRPNBtnCb(mmachine m, SCOL_PTR_TYPE wParam, SCOL_PTR_TYPE lParam)
305 if (OBJbeginreflex(m, OBJ_VRPN_SCOL, SCOL_PTR vrpnObj, SCOL_VRPN_BTN_CB))
307 MMechostr(MSKDEBUG,
"ObjVRPN callback not found\n");
312 for (
unsigned int i = 0; i < vrpnData->btnData.size(); i++)
314 if (MMpush(m, ITOM(vrpnData->btnData[i])))
321 for(
unsigned int j = 0; j < vrpnData->btnData.size(); j++)
326 if (
int k=MBdeftab(m))
331 int k = OBJcallreflex(m, 1 );
354 int vrpnTab = MMget(m, 2);
355 int cb = MMget(m, 1);
359 SVrpn* vrpnObj = MMgetPointer<SVrpn*>(m, MTOP(vrpnTab));
360 vrpnObj->EnableButtonStateData(cb == NIL ?
false :
true);
364 MMechostr(MSKDEBUG,
"_CBvrpnButtonState ...adding reflex\n");
365 return OBJaddreflex(m, OBJ_VRPN_SCOL, SCOL_VRPN_BTN_STATE_CB);
371int getVRPNBtnStateCb(mmachine m, SCOL_PTR_TYPE wParam, SCOL_PTR_TYPE lParam)
377 if (OBJbeginreflex(m, OBJ_VRPN_SCOL, SCOL_PTR vrpnObj, SCOL_VRPN_BTN_STATE_CB))
379 MMechostr(MSKDEBUG,
"ObjVRPN callback not found\n");
384 MMpush(m, ITOM(vrpnData->valueId));
385 MMpush(m, ITOM(vrpnData->btnState));
388 int k = OBJcallreflex(m, 2 );
412 int vrpnTab = MMget(m, 2);
413 int cb = MMget(m, 1);
417 SVrpn* vrpnObj = MMgetPointer<SVrpn*>(m, MTOP(vrpnTab));
418 vrpnObj->EnableTrackerData(cb == NIL ?
false :
true);
422 MMechostr(MSKDEBUG,
"_CBvrpnTrackerData ...adding reflex\n");
423 return OBJaddreflex(m, OBJ_VRPN_SCOL, SCOL_VRPN_TRACKER_CB);
429int getVRPNTrackerCb(mmachine m, SCOL_PTR_TYPE wParam, SCOL_PTR_TYPE lParam)
435 if (OBJbeginreflex(m, OBJ_VRPN_SCOL, SCOL_PTR vrpnObj, SCOL_VRPN_TRACKER_CB))
437 MMechostr(MSKDEBUG,
"ObjVRPN callback not found\n");
442 MMpush(m, ITOM(vrpnData->valueId));
444 int vec = MMmalloc(m, 3, TYPETAB);
448 MMstore(m, vec, 0, FTOM(vrpnData->vectorData[0]));
449 MMstore(m, vec, 1, FTOM(vrpnData->vectorData[1]));
450 MMstore(m, vec, 2, FTOM(vrpnData->vectorData[2]));
451 MMpush(m, PTOM(vec));
453 int quat = MMmalloc(m, 4, TYPETAB);
457 MMstore(m, quat, 0, FTOM(vrpnData->quatData[0]));
458 MMstore(m, quat, 1, FTOM(vrpnData->quatData[1]));
459 MMstore(m, quat, 2, FTOM(vrpnData->quatData[2]));
460 MMstore(m, quat, 3, FTOM(vrpnData->quatData[3]));
461 MMpush(m, PTOM(quat));
464 int k = OBJcallreflex(m, 3 );
487 int vrpnTab = MMget(m, 2);
488 int cb = MMget(m, 1);
492 SVrpn* vrpnObj = MMgetPointer<SVrpn*>(m, MTOP(vrpnTab));
493 vrpnObj->EnableTrackerVelData(cb == NIL ?
false :
true);
497 MMechostr(MSKDEBUG,
"_CBvrpnTrackerVelocityData ...adding reflex\n");
498 return OBJaddreflex(m, OBJ_VRPN_SCOL, SCOL_VRPN_TRACKER_VEL_CB);
504int getVRPNTrackerVelocityCb(mmachine m, SCOL_PTR_TYPE wParam, SCOL_PTR_TYPE lParam)
510 if (OBJbeginreflex(m, OBJ_VRPN_SCOL, SCOL_PTR vrpnObj, SCOL_VRPN_TRACKER_VEL_CB))
512 MMechostr(MSKDEBUG,
"ObjVRPN callback not found\n");
517 MMpush(m, ITOM(vrpnData->valueId));
519 int vec = MMmalloc(m, 3, TYPETAB);
523 MMstore(m, vec, 0, FTOM(vrpnData->vectorData[0]));
524 MMstore(m, vec, 1, FTOM(vrpnData->vectorData[1]));
525 MMstore(m, vec, 2, FTOM(vrpnData->vectorData[2]));
526 MMpush(m, PTOM(vec));
528 int quat = MMmalloc(m, 4, TYPETAB);
532 MMstore(m, quat, 0, FTOM(vrpnData->quatData[0]));
533 MMstore(m, quat, 1, FTOM(vrpnData->quatData[1]));
534 MMstore(m, quat, 2, FTOM(vrpnData->quatData[2]));
535 MMstore(m, quat, 3, FTOM(vrpnData->quatData[3]));
536 MMpush(m, PTOM(quat));
539 int k = OBJcallreflex(m, 3 );
562 int vrpnTab = MMget(m, 2);
563 int cb = MMget(m, 1);
567 SVrpn* vrpnObj = MMgetPointer<SVrpn*>(m, MTOP(vrpnTab));
568 vrpnObj->EnableTrackerAccelData(cb == NIL ?
false :
true);
572 MMechostr(MSKDEBUG,
"_CBvrpnTrackerAccelData ...adding reflex\n");
573 return OBJaddreflex(m, OBJ_VRPN_SCOL, SCOL_VRPN_TRACKER_ACC_CB);
579int getVRPNTrackerAccelCb(mmachine m, SCOL_PTR_TYPE wParam, SCOL_PTR_TYPE lParam)
585 if (OBJbeginreflex(m, OBJ_VRPN_SCOL, SCOL_PTR vrpnObj, SCOL_VRPN_TRACKER_ACC_CB))
587 MMechostr(MSKDEBUG,
"ObjVRPN callback not found\n");
592 MMpush(m, ITOM(vrpnData->valueId));
594 int vec = MMmalloc(m, 3, TYPETAB);
598 MMstore(m, vec, 0, FTOM(vrpnData->vectorData[0]));
599 MMstore(m, vec, 1, FTOM(vrpnData->vectorData[1]));
600 MMstore(m, vec, 2, FTOM(vrpnData->vectorData[2]));
601 MMpush(m, PTOM(vec));
603 int quat = MMmalloc(m, 4, TYPETAB);
607 MMstore(m, quat, 0, FTOM(vrpnData->quatData[0]));
608 MMstore(m, quat, 1, FTOM(vrpnData->quatData[1]));
609 MMstore(m, quat, 2, FTOM(vrpnData->quatData[2]));
610 MMstore(m, quat, 3, FTOM(vrpnData->quatData[3]));
611 MMpush(m, PTOM(quat));
614 int k = OBJcallreflex(m, 3 );
635 int vrpnTab = MMget(m, 2);
636 int cb = MMget(m, 1);
640 SVrpn* vrpnObj = MMgetPointer<SVrpn*>(m, MTOP(vrpnTab));
641 vrpnObj->EnableTextData(cb == NIL ?
false :
true);
645 MMechostr(MSKDEBUG,
"_CBvrpnTextData ...adding reflex\n");
646 return OBJaddreflex(m, OBJ_VRPN_SCOL, SCOL_VRPN_TEXT_CB);
652int getVRPNTextCb(mmachine m, SCOL_PTR_TYPE wParam, SCOL_PTR_TYPE lParam)
658 if (OBJbeginreflex(m, OBJ_VRPN_SCOL, SCOL_PTR vrpnObj, SCOL_VRPN_TEXT_CB))
660 MMechostr(MSKDEBUG,
"ObjVRPN callback not found\n");
665 Mpushstrbloc(m, (
char*)vrpnData->textData.c_str());
668 int k = OBJcallreflex(m, 1 );
676static NativeDefinition svrpnDef[] =
678 {
"ObjVRPN", TYPTYPE, NULL, NULL },
679 {
"_CRvrpnDevice", 3,
"fun [Chn S S] ObjVRPN",
_CRvrpnDevice },
681 {
"_CBvrpnAnalogData", 3,
"fun [ObjVRPN fun [ObjVRPN u0 [F r1]] u1 u0] ObjVRPN",
_CBvrpnAnalogData },
682 {
"_CBvrpnButtonData", 3,
"fun [ObjVRPN fun [ObjVRPN u0 [I r1]] u1 u0] ObjVRPN",
_CBvrpnButtonData },
683 {
"_CBvrpnButtonState", 3,
"fun [ObjVRPN fun [ObjVRPN u0 I I] u1 u0] ObjVRPN",
_CBvrpnButtonState },
684 {
"_CBvrpnTrackerData", 3,
"fun [ObjVRPN fun [ObjVRPN u0 I [F F F] [F F F F]] u1 u0] ObjVRPN",
_CBvrpnTrackerData },
685 {
"_CBvrpnTrackerVelocityData", 3,
"fun [ObjVRPN fun [ObjVRPN u0 I [F F F] [F F F F]] u1 u0] ObjVRPN",
_CBvrpnTrackerVelocityData },
686 {
"_CBvrpnTrackerAccelData", 3,
"fun [ObjVRPN fun [ObjVRPN u0 I [F F F] [F F F F]] u1 u0] ObjVRPN",
_CBvrpnTrackerAccelData },
687 {
"_CBvrpnTextData", 3,
"fun [ObjVRPN fun [ObjVRPN u0 S] u1 u0] ObjVRPN",
_CBvrpnTextData }
697int LoadVRPN(mmachine m)
701 MMechostr(MSKDEBUG,
"\n" );
702 MMechostr(MSKDEBUG,
" > Loading VRPN Support\n");
705 OBJ_VRPN_SCOL = OBJregister(8 , 1, destroyVRPNObj,
"OBJ_VRPN_SCOL");
707 k = PKhardpak2(m,
"mVRPN.pkg-1.0",
sizeof(svrpnDef) /
sizeof(svrpnDef[0]), svrpnDef);
710 VRPN_ANALOG_CB = OBJgetUserEvent();
711 OBJdefEvent(VRPN_ANALOG_CB, getVRPNAnalogCb);
713 VRPN_BTN_CB = OBJgetUserEvent();
714 OBJdefEvent(VRPN_BTN_CB, getVRPNBtnCb);
716 VRPN_BTN_STATE_CB = OBJgetUserEvent();
717 OBJdefEvent(VRPN_BTN_STATE_CB, getVRPNBtnStateCb);
719 VRPN_TEXT_CB = OBJgetUserEvent();
720 OBJdefEvent(VRPN_TEXT_CB, getVRPNTextCb);
722 VRPN_TRACKER_CB = OBJgetUserEvent();
723 OBJdefEvent(VRPN_TRACKER_CB, getVRPNTrackerCb);
725 VRPN_TRACKER_VEL_CB = OBJgetUserEvent();
726 OBJdefEvent(VRPN_TRACKER_VEL_CB, getVRPNTrackerVelocityCb);
728 VRPN_TRACKER_ACC_CB = OBJgetUserEvent();
729 OBJdefEvent(VRPN_TRACKER_ACC_CB, getVRPNTrackerAccelCb);
734 MMechostr(MSKDEBUG,
" > Successfully Loaded\n\n");
740 MMechostr(MSKDEBUG,
"\n" );
741 MMechostr(MSKDEBUG,
" > Unloading VRPN Support\n");
745 MMechostr(MSKDEBUG,
" > Successfully unloaded\n\n");
757extern "C" SCOL_EXPORT
int ScolLoadPlugin(mmachine m, cbmachine w)
759extern "C" SCOL_EXPORT
int ScolSvrpnLoadPlugin(mmachine m, cbmachine w)
771extern "C" SCOL_EXPORT
int ScolUnloadPlugin()
773extern "C" SCOL_EXPORT
int ScolSvrpnUnloadPlugin()
int _CBvrpnButtonState(mmachine m)
_CBvrpnButtonState : This function sets the callback called when a VRPN Button data is received
int _DSvrpnDevice(mmachine m)
_DSvrpnDevice : Destroy VRPN object
int _CBvrpnTrackerData(mmachine m)
_CBvrpnTrackerData : This function sets the callback called when a VRPN traker position data is recei...
int _CBvrpnTrackerAccelData(mmachine m)
_CBvrpnTrackerAccelData : This function sets the callback called when a VRPN traker acceleration data...
int _CBvrpnAnalogData(mmachine m)
_CBvrpnAnalogData : This function sets the callback called when a VRPN Analog data is received
int _CBvrpnTrackerVelocityData(mmachine m)
_CBvrpnTrackerVelocityData : This function sets the callback called when a VRPN traker velocity data ...
int _CBvrpnTextData(mmachine m)
_CBvrpnTextData : This function sets the callback called when a VRPN text data is received
int _CRvrpnDevice(mmachine m)
_CRvrpnDevice : This function create a VRPN object
int _CBvrpnButtonData(mmachine m)
_CBvrpnButtonData : This function sets the callback called when a VRPN Button data is received