Emotiv EPOC plugin 1.0

D:/SVN/Scol/trunk/plugins/Epoc/src/Plugin.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  Emotiv EPOC Developer Headset control
00030  First version : July 2010
00031  Author : Aymeric Suteau
00032 */
00033 
00041 #include "Plugin.h"
00042 
00044 cbmachine ww;
00045 HWND HScol = NULL;
00046 
00048 int OBJEPOCSCOL;
00049 
00051 int SCOL_EPOC_CONNECTED_CB                      = 0;    // Headset connected
00052 int EPOC_CONNECTED_CB;
00053 
00054 int SCOL_EPOC_DISCONNECTED_CB                   = 1;    // Headset disconnected
00055 int EPOC_DISCONNECTED_CB;
00056 
00057 int SCOL_EPOC_BAD_SIGNAL_CB                     = 2;    // Bad wireless signal
00058 int EPOC_BAD_SIGNAL_CB;
00059 
00060 int SCOL_EPOC_LOW_BATTERY_CB                    = 3;    // Low battery level
00061 int EPOC_LOW_BATTERY_CB;
00062 
00063 int SCOL_EPOC_HEADSET_DATA_CB                   = 4;    // New data related to Headset Setup
00064 int EPOC_HEADSET_DATA_CB;
00065 
00066 int SCOL_EPOC_AFFECTIV_DATA_CB                  = 5;    // New data from Affectiv Suite
00067 int EPOC_AFFECTIV_DATA_CB;
00068 
00069 int SCOL_EPOC_EXPRESSIV_DATA_CB                 = 6;    // New data from Expressiv Suite
00070 int EPOC_EXPRESSIV_DATA_CB;
00071 
00072 int SCOL_EPOC_COGNITIV_DATA_CB                  = 7;    // New data from Cognitiv Suite
00073 int EPOC_COGNITIV_DATA_CB;
00074 
00075 int SCOL_EPOC_EXPRESSIV_TRAINING_STARTED_CB     = 8;    // Expressive training started
00076 int EPOC_EXPRESSIV_TRAINING_STARTED_CB;
00077 
00078 int SCOL_EPOC_COGNITIV_TRAINING_STARTED_CB      = 9;    // Cognitive training started
00079 int EPOC_COGNITIV_TRAINING_STARTED_CB;
00080 
00081 int SCOL_EPOC_EXPRESSIV_TRAINING_COMPLETED_CB   = 10;   // Expressive training completed
00082 int EPOC_EXPRESSIV_TRAINING_COMPLETED_CB;
00083 
00084 int SCOL_EPOC_COGNITIV_TRAINING_COMPLETED_CB    = 11;   // Cognitive training completed
00085 int EPOC_COGNITIV_TRAINING_COMPLETED_CB;
00086 
00087 int SCOL_EPOC_EXPRESSIV_TRAINING_ERASED_CB      = 12;   // Expressive training completed
00088 int EPOC_EXPRESSIV_TRAINING_ERASED_CB;
00089 
00090 int SCOL_EPOC_COGNITIV_TRAINING_ERASED_CB       = 13;   // Cognitive training completed
00091 int EPOC_COGNITIV_TRAINING_ERASED_CB;
00092 
00093 int SCOL_EPOC_EXPRESSIV_TRAINING_REJECTED_CB    = 14;   // Expressive training rejected
00094 int EPOC_EXPRESSIV_TRAINING_REJECTED_CB;
00095 
00096 int SCOL_EPOC_COGNITIV_TRAINING_REJECTED_CB     = 15;   // Cognitive training rejected
00097 int EPOC_COGNITIV_TRAINING_REJECTED_CB;
00098 
00099 int SCOL_EPOC_EXPRESSIV_TRAINING_SUCCEEDED_CB   = 16;   // Expressive training succeeded
00100 int EPOC_EXPRESSIV_TRAINING_SUCCEEDED_CB;
00101 
00102 int SCOL_EPOC_COGNITIV_TRAINING_SUCCEEDED_CB    = 17;   // Cognitive training succeeded
00103 int EPOC_COGNITIV_TRAINING_SUCCEEDED_CB;
00104 
00105 int SCOL_EPOC_EXPRESSIV_TRAINING_FAILED_CB      = 18;   // Expressive training failed
00106 int EPOC_EXPRESSIV_TRAINING_FAILED_CB;
00107 
00108 int SCOL_EPOC_COGNITIV_TRAINING_FAILED_CB       = 19;   // Cognitive training failed
00109 int EPOC_COGNITIV_TRAINING_FAILED_CB;
00110 
00111 int SCOL_EPOC_RAW_EEG_CB                        = 20;   // New raw EEG data
00112 int EPOC_RAW_EEG_CB;
00113 
00114 
00115 // Extern variables
00116 extern list<Epoc*> lEpocList;
00117 
00118 
00127 
00128 int destroyEpocObj(mmachine m, int handsys, int epocTab) 
00129 {
00130         // Read the first element of a TAB element (table of objects)
00131         Epoc* EpocObj = (Epoc*) MMfetch(m, MTOP(epocTab), 0);
00132         if (EpocObj == NULL)
00133   {
00134                 // Write the first element in the stack, without pulling it
00135                 MMset(m, 0, NIL); 
00136                 return 0; 
00137         }
00138 
00139         // Safely dispose of "EpocObj" pointer
00140         SAFE_DELETE(EpocObj);
00141   MMechostr(MSKDEBUG, "destroyEpocObj ...SAFE_DELETE ok\n");
00142 
00143         // Write the first element of a TAB element
00144         MMstore(m, MTOP(epocTab), 0, NULL);
00145 
00146         // Display debug message
00147         MMechostr(MSKDEBUG, "EpocObj destroyed.\n");
00148         return 0;
00149 }
00150 
00151 
00160 int _CREpoc(mmachine m)
00161 {
00162         #ifdef _SCOL_DEBUG_
00163                 MMechostr(MSKDEBUG,"_CREpoc\n");
00164         #endif
00165         
00166         // Get Channel
00167         int channel = MMget(m, 0);
00168 
00169         // Test Channel
00170         if (channel == NIL) 
00171   { 
00172                 MMechostr(MSKDEBUG, "Channel NIL\n");     // Display Warning in Scol Console
00173                 MMpull(m);
00174                 MMpush(m, NIL);
00175                 return 0;
00176         }
00177 
00178         // Create Emotiv EPOC instance
00179   Epoc* newEpoc = new Epoc();
00180   
00181   // Initialize the connection to Emotiv EPOC headset
00182   if (!newEpoc->Connect()) 
00183   {
00184                 MMechostr(MSKDEBUG, "_CREpoc ...initialization failed\n");
00185                 SAFE_DELETE(newEpoc);
00186                 MMpull(m);                                                              // Pull the channel
00187                 MMpush(m, NIL);                                         // Push NIL on the stack
00188                 return 0;
00189         }
00190 
00191   int epocTab = MMmalloc(m, 1, TYPETAB);
00192   if (epocTab == NIL) 
00193   {
00194                 SAFE_DELETE(newEpoc); 
00195                 MMpull(m);
00196                 return MMpush(m, NIL);
00197         }
00198   MMstore(m, epocTab, 0, (int)newEpoc);
00199         MMpush(m, PTOM(epocTab));
00200 
00201         int k = OBJcreate(m, OBJEPOCSCOL, (int)newEpoc, -1, -1);
00202 
00203         #ifdef  _SCOL_DEBUG_
00204                 MMechostr(MSKDEBUG,"ok\n");
00205         #endif
00206 
00207         return k;
00208 }
00209 
00210 
00219 int _DSEpoc(mmachine m) 
00220 {
00221   #ifdef _SCOL_DEBUG_
00222           MMechostr(MSKDEBUG, "_DSEpoc\n");
00223   #endif
00224 
00225   // Get the table of Emotiv EPOC objects into the stack (without pulling it)
00226         int epocTab = MMget(m, 0);
00227         if (epocTab == NIL) {
00228                 MMechostr(MSKDEBUG, "ObjEpoc NIL\n");
00229                 MMset(m, 0, -1);
00230                 return 0;
00231         }
00232 
00233         OBJdelTM(m, OBJEPOCSCOL, epocTab);
00234         MMset(m, 0, 0);
00235 
00236   #ifdef        _SCOL_DEBUG_
00237           MMechostr(MSKDEBUG, "ok\n");
00238   #endif
00239         return 0;
00240 }
00241 
00242 
00254 int _CBEpocConnected(mmachine m)
00255 {
00256         return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_CONNECTED_CB);
00257 }
00258 
00259 int getEpocConnectedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00260 {
00261         int k = 0;
00262         Epoc * EpocObj = (Epoc*) id;
00263         
00264         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00265         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_CONNECTED_CB))
00266                 return 0;
00267 
00268         if ((k=OBJcallreflex(m, 0))) 
00269     return k;
00270         return k;
00271 }
00272 
00273 
00285 int _CBEpocDisconnected(mmachine m)
00286 {
00287   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_DISCONNECTED_CB);
00288 }
00289 
00290 int getEpocDisconnectedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00291 {
00292         int k = 0;
00293         Epoc * EpocObj = (Epoc*) id;
00294         
00295         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00296         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_DISCONNECTED_CB))
00297                 return 0;
00298 
00299         if ((k = OBJcallreflex(m, 0))) 
00300     return k;
00301         return k;
00302 }
00303 
00304 
00316 int _CBEpocBadSignal(mmachine m)
00317 {
00318   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_BAD_SIGNAL_CB);
00319 }
00320 
00321 int getEpocBadSignalCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00322 {
00323         int k = 0;
00324         Epoc * EpocObj = (Epoc*) id;
00325         
00326         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00327         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_BAD_SIGNAL_CB))
00328                 return 0;
00329 
00330         if ((k = OBJcallreflex(m, 0))) 
00331     return k;
00332         return k;
00333 }
00334 
00335 
00347 int _CBEpocLowBattery(mmachine m)
00348 {
00349   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_LOW_BATTERY_CB);
00350 }
00351 
00352 int getEpocLowBatteryCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00353 {
00354         int k = 0;
00355         Epoc * EpocObj = (Epoc*) id;
00356         
00357         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00358         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_LOW_BATTERY_CB))
00359                 return 0;
00360 
00361         if ((k = OBJcallreflex(m, 0))) 
00362     return k;
00363         return k;
00364 }
00365 
00366 
00378 int _CBEpocHeadsetData(mmachine m)
00379 {
00380   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_HEADSET_DATA_CB);
00381 }
00382 
00383 int getEpocHeadsetDataCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00384 {
00385         int k = 0;
00386   int cms = 0, drl = 0;
00387   int af3 = 0, f7 = 0, f3 = 0, fc5 = 0, t7 = 0, p7 = 0, o1 = 0;
00388   int af4 = 0, f8 = 0, f4 = 0, fc6 = 0, t8 = 0, p8 = 0, o2 = 0;
00389   float xGyro = 0.f, yGyro = 0.f;
00390   float systemUpTime = 0.f;
00391 
00392   // Retrieve Emotiv EPOC instance
00393         Epoc * EpocObj = (Epoc*) id;
00394         
00395         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00396         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_HEADSET_DATA_CB))
00397                 return 0;
00398 
00399   // Retrieve sensors pads quality
00400   cms = EpocObj->iContactQuality[0];   // Reference pads
00401   drl = EpocObj->iContactQuality[1];
00402 
00403   af3 = EpocObj->iContactQuality[3];   // Left hemisphere
00404   f7 = EpocObj->iContactQuality[4];
00405   f3 = EpocObj->iContactQuality[5];
00406   fc5 = EpocObj->iContactQuality[6];
00407   t7 = EpocObj->iContactQuality[7];
00408   p7 = EpocObj->iContactQuality[8];
00409   o1 = EpocObj->iContactQuality[9];
00410 
00411   af4 = EpocObj->iContactQuality[16];  // Right hemisphere
00412   f8 = EpocObj->iContactQuality[15];
00413   f4 = EpocObj->iContactQuality[14];
00414   fc6 = EpocObj->iContactQuality[13];
00415   t8 = EpocObj->iContactQuality[12];
00416   p8 = EpocObj->iContactQuality[11];
00417   o2 = EpocObj->iContactQuality[10];
00418 
00419   // Update gyroscope values
00420   xGyro = EpocObj->GetGyroX();
00421   yGyro = EpocObj->GetGyroY();
00422 
00423   // Update system up time
00424   systemUpTime = EpocObj->GetSystemUpTime();
00425 
00426   // Create tuples
00427   int tupleRef = MMmalloc(m, 2, TYPETAB);     // Reference pads
00428         if (tupleRef == NIL) 
00429   {     
00430     MMset(m, 0, NIL);           
00431     return MERRMEM;     
00432   }
00433   MMstore(m, tupleRef, 0, ITOM(cms));
00434         MMstore(m, tupleRef, 1, ITOM(drl));
00435   MMpush(m, PTOM(tupleRef));
00436 
00437   int tupleLeft = MMmalloc(m, 7, TYPETAB);    // Left hemisphere
00438         if (tupleLeft == NIL) 
00439   {     
00440     MMset(m, 0, NIL);           
00441     return MERRMEM;     
00442   }
00443   MMstore(m, tupleLeft, 0, ITOM(af3));
00444         MMstore(m, tupleLeft, 1, ITOM(f7));
00445   MMstore(m, tupleLeft, 2, ITOM(f3));
00446         MMstore(m, tupleLeft, 3, ITOM(fc5));
00447   MMstore(m, tupleLeft, 4, ITOM(t7));
00448         MMstore(m, tupleLeft, 5, ITOM(p7));
00449   MMstore(m, tupleLeft, 6, ITOM(o1));
00450   MMpush(m, PTOM(tupleLeft));
00451 
00452   int tupleRight = MMmalloc(m, 7, TYPETAB);   // Right hemisphere
00453         if (tupleRight == NIL) 
00454   {     
00455     MMset(m, 0, NIL);
00456     return MERRMEM;
00457   }
00458   MMstore(m, tupleRight, 0, ITOM(af4));
00459         MMstore(m, tupleRight, 1, ITOM(f8));
00460   MMstore(m, tupleRight, 2, ITOM(f4));
00461         MMstore(m, tupleRight, 3, ITOM(fc6));
00462   MMstore(m, tupleRight, 4, ITOM(t8));
00463         MMstore(m, tupleRight, 5, ITOM(p8));
00464   MMstore(m, tupleRight, 6, ITOM(o2));
00465   MMpush(m, PTOM(tupleRight));
00466 
00467   // Gyro
00468   int tupleGyro = MMmalloc(m, 2, TYPETAB);
00469         if (tupleGyro == NIL) 
00470   {
00471     MMset(m, 0, NIL);
00472     return MERRMEM;
00473   }
00474   MMstore(m, tupleGyro, 0, FTOM(xGyro));
00475         MMstore(m, tupleGyro, 1, FTOM(yGyro));
00476   MMpush(m, PTOM(tupleGyro));
00477 
00478   // System up time
00479   MMpush(m, FTOM(systemUpTime));
00480 
00481         k = OBJcallreflex(m, 5);
00482         return k;
00483 }
00484 
00485 
00497 int _CBEpocAffectivData(mmachine m)
00498 {
00499   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_AFFECTIV_DATA_CB);
00500 }
00501 
00502 int getEpocAffectivDataCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00503 {
00504         int k = 0;
00505   float engagement = 0.f, frustration = 0.f, meditation = 0.f, shortExcitement = 0.f, longExcitement = 0.f;
00506         Epoc * EpocObj = (Epoc*) id;
00507         
00508         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00509         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_AFFECTIV_DATA_CB))
00510                 return 0;
00511 
00512   // Retrieve data related to Affectiv Suite
00513   engagement = EpocObj->GetEngagementBoredom();
00514   frustration = EpocObj->GetFrustration();
00515   meditation = EpocObj->GetMeditation();
00516   shortExcitement = EpocObj->GetInstantaneousExcitement();
00517   longExcitement = EpocObj->GetLongTermExcitement();
00518 
00519   // Push Affective data into the stack
00520         MMpush(m, FTOM(engagement));
00521   MMpush(m, FTOM(frustration));
00522   MMpush(m, FTOM(meditation));
00523   MMpush(m, FTOM(shortExcitement));
00524   MMpush(m, FTOM(longExcitement));
00525 
00526         k = OBJcallreflex(m, 5);
00527         return k;
00528 }
00529 
00530 
00542 int _CBEpocExpressivData(mmachine m)
00543 {
00544   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_EXPRESSIV_DATA_CB);
00545 }
00546 
00547 int getEpocExpressivDataCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00548 {
00549         int k = 0;
00550   unsigned int eyeType = 0, upperFaceType = 0, lowerFaceType = 0;
00551   float upperFacePower = 0.f, lowerFacePower = 0.f;
00552 
00553         Epoc * EpocObj = (Epoc*) id;
00554         
00555         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00556         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_EXPRESSIV_DATA_CB))
00557                 return 0;
00558 
00559   // Retrieve data from Expressiv Suite
00560   eyeType = EpocObj->GetEyeExpressionType();
00561   upperFaceType = EpocObj->GetUpperFaceExpressionType();
00562   upperFacePower = EpocObj->GetUpperFaceExpressionPower();
00563   lowerFaceType = EpocObj->GetLowerFaceExpressionType();
00564   lowerFacePower = EpocObj->GetLowerFaceExpressionPower();
00565 
00566   // Push Expressiv data into the stack
00567         MMpush(m, ITOM(eyeType));
00568   MMpush(m, ITOM(upperFaceType));
00569   MMpush(m, FTOM(upperFacePower));
00570   MMpush(m, ITOM(lowerFaceType));
00571   MMpush(m, FTOM(lowerFacePower));
00572         k = OBJcallreflex(m, 5);
00573         return k;
00574 }
00575 
00576 
00588 int _CBEpocCognitivData(mmachine m)
00589 {
00590   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_COGNITIV_DATA_CB);
00591 }
00592 
00593 int getEpocCognitivDataCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00594 {
00595         int k = 0;
00596   unsigned int actionType = 0;
00597   float actionPower = 0.f;
00598 
00599         Epoc * EpocObj = (Epoc*) id;
00600         
00601         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00602         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_COGNITIV_DATA_CB))
00603                 return 0;
00604 
00605   // Retrieve data from Cognitiv Suite
00606   actionType = EpocObj->GetActionType();
00607   actionPower = EpocObj->GetActionPower();
00608 
00609   // Push Affective data into the stack
00610         MMpush(m, ITOM(actionType));
00611   MMpush(m, FTOM(actionPower));
00612 
00613         k = OBJcallreflex(m, 2);
00614         return k;
00615 }
00616 
00617 
00629 int _CBEpocExpressivTrainingStarted(mmachine m)
00630 {
00631   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_EXPRESSIV_TRAINING_STARTED_CB);
00632 }
00633 
00634 int getEpocExpressivTrainingStartedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00635 {
00636         int k = 0;
00637         Epoc * EpocObj = (Epoc*) id;
00638         
00639         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00640         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_EXPRESSIV_TRAINING_STARTED_CB))
00641                 return 0;
00642 
00643         if ((k=OBJcallreflex(m, 0))) 
00644     return k;
00645 
00646   // DEBUG
00647   MMechostr(MSKDEBUG, "<<< getEpocExpressivTrainingStartedCb OK\n");
00648 
00649         return k;
00650 }
00651 
00652 
00664 int _CBEpocCognitivTrainingStarted(mmachine m)
00665 {
00666   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_COGNITIV_TRAINING_STARTED_CB);
00667 }
00668 
00669 int getEpocCognitivTrainingStartedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00670 {
00671         int k = 0;
00672         Epoc * EpocObj = (Epoc*) id;
00673         
00674         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00675         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_COGNITIV_TRAINING_STARTED_CB))
00676                 return 0;
00677 
00678         if ((k=OBJcallreflex(m, 0))) 
00679     return k;
00680 
00681   // DEBUG
00682   MMechostr(MSKDEBUG, "<<< getEpocCognitivTrainingStartedCb OK\n");
00683 
00684         return k;
00685 }
00686 
00687 
00699 int _CBEpocExpressivTrainingCompleted(mmachine m)
00700 {
00701   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_EXPRESSIV_TRAINING_COMPLETED_CB);
00702 }
00703 
00704 int getEpocExpressivTrainingCompletedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00705 {
00706   // DEBUG
00707   MMechostr(MSKDEBUG, "<<< starting getEpocExpressivTrainingCompletedCb...\n");
00708         
00709   int k = 0;
00710         Epoc * EpocObj = (Epoc*) id;
00711         
00712         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00713         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_EXPRESSIV_TRAINING_COMPLETED_CB))
00714                 return 0;
00715 
00716         if ((k=OBJcallreflex(m, 0))) 
00717     return k;
00718 
00719   // DEBUG
00720   MMechostr(MSKDEBUG, "<<< getEpocExpressivTrainingCompletedCb OK\n");
00721         return k;
00722 }
00723 
00724 
00736 int _CBEpocCognitivTrainingCompleted(mmachine m)
00737 {
00738   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_COGNITIV_TRAINING_COMPLETED_CB);
00739 }
00740 
00741 int getEpocCognitivTrainingCompletedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
00742 {
00743   // DEBUG
00744   MMechostr(MSKDEBUG, "<<< starting getEpocCognitivTrainingCompletedCb...\n");
00745   
00746         int k = 0;
00747         Epoc * EpocObj = (Epoc*) id;
00748         
00749         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
00750         if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_COGNITIV_TRAINING_COMPLETED_CB))
00751                 return 0;
00752 
00753         if ((k=OBJcallreflex(m, 0))) 
00754     return k;
00755 
00756   // DEBUG
00757   MMechostr(MSKDEBUG, "<<< getEpocCognitivTrainingCompletedCb OK\n");
00758         return k;
00759 }
00760 
00761 
00771 int _StartExpressivTraining(mmachine m)
00772 {
00773         unsigned int expressionIndex = 0;
00774         expressionIndex = MTOI(MMpull(m));
00775 
00776         int epocTab = MTOP(MMget(m, 0));
00777         if (epocTab == NIL) 
00778   { 
00779     MMset(m, 0, NIL); 
00780     return 0; 
00781   }
00782 
00783   // Retrieve Emotiv EPOC instance
00784   Epoc * EpocObj = (Epoc*) MMfetch(m, epocTab, 0);
00785   if (!EpocObj) 
00786   { 
00787     MMset(m, 0, NIL); 
00788     return 0; 
00789   }
00790 
00791   // Start Expressiv training procedure for selected expression
00792   EpocObj->StartExpressivSuiteTraining((EE_ExpressivAlgo_t) expressionIndex);
00793         MMset(m, 0, 0);
00794         
00795   return 0;
00796 }
00797 
00798 
00808 int _EraseExpressivTraining(mmachine m)
00809 {
00810         unsigned int expressionIndex = 0;
00811         expressionIndex = MTOI(MMpull(m));
00812 
00813         int epocTab = MTOP(MMget(m, 0));
00814         if (epocTab == NIL)
00815   { 
00816     MMset(m, 0, NIL);
00817     return 0;
00818   }
00819 
00820   // Retrieve Emotiv EPOC instance
00821   Epoc * EpocObj = (Epoc*) MMfetch(m, epocTab, 0);
00822   if (!EpocObj)
00823   { 
00824     MMset(m, 0, NIL);
00825     return 0;
00826   }
00827 
00828   // Erase Expressiv training for selected expression
00829   EpocObj->EraseExpressivSuiteTraining((EE_ExpressivAlgo_t) expressionIndex);
00830         MMset(m, 0, 0);
00831         
00832   return 0;
00833 }
00834 
00835 
00845 int _StartCognitivTraining(mmachine m)
00846 {
00847         unsigned int cognitivAction = 0;
00848         cognitivAction = MTOI(MMpull(m));
00849 
00850         int epocTab = MTOP(MMget(m, 0));
00851         if (epocTab == NIL) 
00852   { 
00853     MMset(m, 0, NIL); 
00854     return 0; 
00855   }
00856 
00857   // Retrieve Emotiv EPOC instance
00858   Epoc * EpocObj = (Epoc*) MMfetch(m, epocTab, 0);
00859   if (!EpocObj) 
00860   { 
00861     MMset(m, 0, NIL); 
00862     return 0; 
00863   }
00864 
00865   // Start Cognitiv training procedure for selected action
00866   EpocObj->StartCognitivSuiteTraining((EE_CognitivAction_t) cognitivAction);
00867         MMset(m, 0, 0);
00868         
00869   return 0;
00870 }
00871 
00872 
00882 int _EraseCognitivTraining(mmachine m)
00883 {
00884         unsigned int cognitivAction = 0;
00885         cognitivAction = MTOI(MMpull(m));
00886 
00887         int epocTab = MTOP(MMget(m, 0));
00888         if (epocTab == NIL) 
00889   {
00890     MMset(m, 0, NIL); 
00891     return 0; 
00892   }
00893 
00894   // Retrieve Emotiv EPOC instance
00895   Epoc * EpocObj = (Epoc*) MMfetch(m, epocTab, 0);
00896   if (!EpocObj)
00897   { 
00898     MMset(m, 0, NIL);
00899     return 0;
00900   }
00901 
00902   // Erases Cognitiv training for selected action
00903   EpocObj->EraseCognitivSuiteTraining((EE_CognitivAction_t) cognitivAction);
00904         MMset(m, 0, 0);
00905         
00906   return 0;
00907 }
00908 
00909 
00919 int _LoadProfile(mmachine m)
00920 {
00921   int fileName = MMpull(m);
00922         int epocTab = MTOP(MMget(m, 0));
00923         if (epocTab == NIL) 
00924   { 
00925     MMset(m, 0, NIL);
00926     return 0;
00927   }
00928 
00929   // Retrieve Emotiv EPOC instance
00930   Epoc * EpocObj = (Epoc*) MMfetch(m, epocTab, 0);
00931   if (!EpocObj) 
00932   { 
00933     MMset(m, 0, NIL);
00934     return 0;
00935   }
00936 
00937   // Convert parameter to char*
00938   char* strFileName = (char*) MMstartstr(m, MTOP(fileName));
00939 
00940   // DEBUG
00941   MMechostr(MSKDEBUG, "LOAD: strFileName = %s\n", strFileName);
00942 
00943   // Set path name and load user profile
00944   EpocObj->SetUserProfileFileName(strFileName);
00945   EpocObj->SetProfileLoadingDone(false);
00946 
00947         MMset(m, 0, 0);
00948   return 0;
00949 }
00950 
00951 
00961 int _SaveProfile(mmachine m)
00962 {
00963   int fileName = MMpull(m);
00964         int epocTab = MTOP(MMget(m, 0));
00965         if (epocTab == NIL) 
00966   { 
00967     MMset(m, 0, NIL); 
00968     return 0; 
00969   }
00970 
00971   // Retrieve Emotiv EPOC instance
00972   Epoc * EpocObj = (Epoc*) MMfetch(m, epocTab, 0);
00973   if (!EpocObj) 
00974   { 
00975     MMset(m, 0, NIL);
00976     return 0;
00977   }
00978 
00979   // Convert parameter to char*
00980   char* strFileName = (char*) MMstartstr(m, MTOP(fileName));
00981 
00982   // Eventually update path name and save user profile
00983   MMechostr(MSKDEBUG, "SAVE: strFileName = %s\n", strFileName);
00984   if (strcmp(strFileName, "") != 0)
00985     EpocObj->SetUserProfileFileName(strFileName);
00986   EpocObj->SetProfileSavingDone(false);
00987 
00988         MMset(m, 0, 0);
00989   return 0;
00990 }
00991 
00992 
01004 int _CBEpocExpressivTrainingErased(mmachine m)
01005 {
01006   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_EXPRESSIV_TRAINING_ERASED_CB);
01007 }
01008 
01009 int getEpocExpressivTrainingErasedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01010 {
01011         int k = 0;
01012         Epoc * EpocObj = (Epoc*) id;
01013         
01014         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01015   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_EXPRESSIV_TRAINING_ERASED_CB))
01016                 return 0;
01017 
01018         if ((k = OBJcallreflex(m, 0)))
01019     return k;
01020         return k;
01021 }
01022 
01023 
01035 int _CBEpocCognitivTrainingErased(mmachine m)
01036 {
01037   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_COGNITIV_TRAINING_ERASED_CB);
01038 }
01039 
01040 int getEpocCognitivTrainingErasedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01041 {
01042         int k = 0;
01043         Epoc * EpocObj = (Epoc*) id;
01044         
01045         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01046   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_COGNITIV_TRAINING_ERASED_CB))
01047                 return 0;
01048 
01049         if ((k = OBJcallreflex(m, 0)))
01050     return k;
01051         return k;
01052 }
01053 
01054 
01066 int _CBEpocExpressivTrainingRejected(mmachine m)
01067 {
01068   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_EXPRESSIV_TRAINING_REJECTED_CB);
01069 }
01070 
01071 int getEpocExpressivTrainingRejectedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01072 {
01073         int k = 0;
01074         Epoc * EpocObj = (Epoc*) id;
01075         
01076         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01077   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_EXPRESSIV_TRAINING_REJECTED_CB))
01078                 return 0;
01079 
01080         if ((k = OBJcallreflex(m, 0)))
01081     return k;
01082         return k;
01083 }
01084 
01085 
01097 int _CBEpocCognitivTrainingRejected(mmachine m)
01098 {
01099   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_COGNITIV_TRAINING_REJECTED_CB);
01100 }
01101 
01102 int getEpocCognitivTrainingRejectedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01103 {
01104         int k = 0;
01105         Epoc * EpocObj = (Epoc*) id;
01106         
01107         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01108   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_COGNITIV_TRAINING_REJECTED_CB))
01109                 return 0;
01110 
01111         if ((k = OBJcallreflex(m, 0)))
01112     return k;
01113         return k;
01114 }
01115 
01116 
01128 int _CBEpocExpressivTrainingSucceeded(mmachine m)
01129 {
01130   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_EXPRESSIV_TRAINING_SUCCEEDED_CB);
01131 }
01132 
01133 int getEpocExpressivTrainingSucceededCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01134 {
01135         int k = 0;
01136         Epoc * EpocObj = (Epoc*) id;
01137         
01138         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01139   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_EXPRESSIV_TRAINING_SUCCEEDED_CB))
01140                 return 0;
01141 
01142   if ((k = OBJcallreflex(m, 0)))
01143     return k;
01144         return k;
01145 }
01146 
01147 
01159 int _CBEpocCognitivTrainingSucceeded(mmachine m)
01160 {
01161   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_EXPRESSIV_TRAINING_SUCCEEDED_CB);
01162 }
01163 
01164 int getEpocCognitivTrainingSucceededCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01165 {
01166         int k = 0;
01167         Epoc * EpocObj = (Epoc*) id;
01168         
01169         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01170   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_COGNITIV_TRAINING_SUCCEEDED_CB))
01171                 return 0;
01172 
01173         if (k = OBJcallreflex(m, 0))
01174     return k;
01175         return k;
01176 }
01177 
01178 
01190 int _CBEpocExpressivTrainingFailed(mmachine m)
01191 {
01192   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_EXPRESSIV_TRAINING_FAILED_CB);
01193 }
01194 
01195 int getEpocExpressivTrainingFailedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01196 {
01197         int k = 0;
01198         Epoc * EpocObj = (Epoc*) id;
01199         
01200         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01201   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_EXPRESSIV_TRAINING_FAILED_CB))
01202                 return 0;
01203 
01204         if (k = OBJcallreflex(m, 0))
01205     return k;
01206         return k;
01207 }
01208 
01209 
01221 int _CBEpocCognitivTrainingFailed(mmachine m)
01222 {
01223   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_COGNITIV_TRAINING_FAILED_CB);
01224 }
01225 
01226 int getEpocCognitivTrainingFailedCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01227 {
01228         int k = 0;
01229         Epoc * EpocObj = (Epoc*) id;
01230         
01231         // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01232   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_COGNITIV_TRAINING_FAILED_CB))
01233                 return 0;
01234 
01235         if (k = OBJcallreflex(m, 0))
01236     return k;
01237         return k;
01238 }
01239 
01240 
01252 int _CBEpocRawEEGData(mmachine m)
01253 {
01254   return OBJaddreflex(m, OBJEPOCSCOL, SCOL_EPOC_RAW_EEG_CB);
01255 }
01256 
01257 int getEpocRawEEGDataCb(mmachine m, HWND h, unsigned msg, UINT id, LONG param, int *ret)
01258 {
01259         int k = 0, i = 0;
01260         Epoc* EpocObj = (Epoc*) id;
01261   
01262   // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
01263   if (OBJbeginreflex(m, OBJEPOCSCOL, (int)EpocObj, SCOL_EPOC_RAW_EEG_CB))
01264                 return 0;
01265 
01266   // Browse raw EEG data
01267   //MMechostr(MSKDEBUG, ">>> EEG data size = %d\n", sizeof(EpocObj->fEEGData));
01268   for (i = 0; i < 14; i++)
01269   {
01270     if (MMpush(m, FTOM(EpocObj->fEEGData[i])))
01271       return MERRMEM;
01272   }
01273 
01274         if (MMpush(m, NIL))
01275     return MERRMEM;
01276 
01277         for (i = 0; i < 14; i++)
01278         {
01279     if (MMpush(m, 2*2))         
01280       return MERRMEM;
01281                 if (k = MBdeftab(m))            
01282       return k;
01283         }
01284   
01285         // Call reflex previously defined
01286         k = OBJcallreflex(m, 1);
01287         return k;
01288 }
01289 
01290 
01298 
01299 
01301 #define NbTplPKG 30
01302 
01303 
01307 char    *TplName[NbTplPKG] =
01308 {
01309         "ObjEpoc",
01310   "_CREpoc",
01311         "_DSEpoc",
01312   "_CBEpocConnected",
01313   "_CBEpocDisconnected",
01314   "_CBEpocBadSignal",
01315   "_CBEpocLowBattery",
01316   "_CBEpocHeadsetData",
01317   "_CBEpocAffectivData",
01318   "_CBEpocExpressivData",
01319   "_CBEpocCognitivData",
01320   "_CBEpocExpressivTrainingStarted",
01321   "_CBEpocCognitivTrainingStarted",
01322   "_CBEpocExpressivTrainingCompleted",
01323   "_CBEpocCognitivTrainingCompleted",
01324   "_CBEpocExpressivTrainingErased",
01325   "_CBEpocCognitivTrainingErased",
01326   "_CBEpocExpressivTrainingRejected",
01327   "_CBEpocCognitivTrainingRejected",
01328   "_CBEpocExpressivTrainingSucceeded",
01329   "_CBEpocCognitivTrainingSucceeded",
01330   "_CBEpocExpressivTrainingFailed",
01331   "_CBEpocCognitivTrainingFailed",
01332   "_CBEpocRawEEGData",
01333   "_StartExpressivTraining",
01334   "_EraseExpressivTraining",
01335   "_StartCognitivTraining",
01336   "_EraseCognitivTraining",
01337   "_LoadProfile",
01338   "_SaveProfile"
01339 };
01340 
01341 
01345 int (*TplFunc[NbTplPKG])(mmachine m)=
01346 {
01347         NULL,                                                                                                                                                           // ObjEpoc
01348   _CREpoc,                                                                                                                // _CREpoc
01349         _DSEpoc,                                                                                                                  // _DSEpoc
01350   _CBEpocConnected,                           // _CBEpocConnected
01351   _CBEpocDisconnected,                        // _CBEpocDisconnected
01352   _CBEpocBadSignal,                           // _CBEpocBadSignal    
01353   _CBEpocLowBattery,                          // _CBEpocLowBattery  
01354   _CBEpocHeadsetData,                         // _CBEpocHeadsetData
01355   _CBEpocAffectivData,                        // _CBEpocAffectivData
01356   _CBEpocExpressivData,                       // _CBEpocExpressivData
01357   _CBEpocCognitivData,                        // _CBEpocCognitivData
01358   _CBEpocExpressivTrainingStarted,            // _CBEpocExpressivTrainingStarted
01359   _CBEpocCognitivTrainingStarted,             // _CBEpocCognitivTrainingStarted
01360   _CBEpocExpressivTrainingCompleted,          // _CBEpocExpressivTrainingCompleted
01361   _CBEpocCognitivTrainingCompleted,           // _CBEpocCognitivTrainingCompleted
01362   _CBEpocExpressivTrainingErased,             // _CBEpocExpressivTrainingErased
01363   _CBEpocCognitivTrainingErased,              // _CBEpocCognitivTrainingErased
01364   _CBEpocExpressivTrainingRejected,           // _CBEpocExpressivTrainingRejected
01365   _CBEpocCognitivTrainingRejected,            // _CBEpocCognitivTrainingRejected
01366   _CBEpocExpressivTrainingSucceeded,          // _CBEpocExpressivTrainingSucceeded
01367   _CBEpocCognitivTrainingSucceeded,           // _CBEpocCognitivTrainingSucceeded
01368   _CBEpocExpressivTrainingFailed,             // _CBEpocExpressivTrainingFailed
01369   _CBEpocCognitivTrainingFailed,              // _CBEpocCognitivTrainingFailed
01370   _CBEpocRawEEGData,                          // _CBEpocRawEEGData
01371   _StartExpressivTraining,                                                                        // _StartExpressivTraining
01372   _EraseExpressivTraining,                                                                        // _EraseExpressivTraining
01373   _StartCognitivTraining,                     // _StartCognitivTraining
01374   _EraseCognitivTraining,                                                                           // _EraseCognitivTraining
01375   _LoadProfile,                               // _LoadProfile
01376   _SaveProfile                                // _SaveProfile
01377 };
01378 
01379 
01383 int TplNArg[NbTplPKG]=
01384 {
01385         TYPTYPE,                                                                                                                                                // ObjEpoc
01386   1,                                                                                                                                                                    // _CREpoc
01387         1,                                                                                                                                                                      // _DSEpoc
01388   3,                                          // _CBEpocConnected
01389   3,                                          // _CBEpocDisconnected
01390   3,                                          // _CBEpocBadSignal
01391   3,                                          // _CBEpocLowBattery
01392   3,                                          // _CBEpocHeadsetData
01393   3,                                          // _CBEpocAffectivData
01394   3,                                          // _CBEpocExpressivData
01395   3,                                          // _CBEpocCognitivData
01396   3,                                          // _CBEpocExpressivTrainingStarted
01397   3,                                          // _CBEpocCognitivTrainingStarted
01398   3,                                          // _CBEpocExpressivTrainingCompleted
01399   3,                                          // _CBEpocCognitivTrainingCompleted
01400   3,                                          // _CBEpocExpressivTrainingErased
01401   3,                                          // _CBEpocCognitivTrainingErased
01402   3,                                          // _CBEpocExpressivTrainingRejected
01403   3,                                          // _CBEpocCognitivTrainingRejected
01404   3,                                          // _CBEpocExpressivTrainingSucceeded
01405   3,                                          // _CBEpocCognitivTrainingSucceeded
01406   3,                                          // _CBEpocExpressivTrainingFailed
01407   3,                                          // _CBEpocCognitivTrainingFailed
01408   3,                                          // _CBEpocRawEEGData
01409   2,                                          // _StartExpressivTraining
01410   2,                                          // _EraseExpressivTraining
01411   2,                                          // _StartCognitivTraining
01412   2,                                          // _EraseCognitivTraining
01413   2,                                          // _LoadProfile
01414   2                                           // _SaveProfile
01415 };
01416 
01417 
01421 char* TplType[NbTplPKG]=
01422 {
01423         NULL,                                                                                                                                                                       // ObjEpoc
01424   "fun [Chn] ObjEpoc",                                                                                                // _CREpoc
01425         "fun [ObjEpoc] I",                                                                                                            // _DSEpoc
01426   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",                     // _CBEpocConnected
01427   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",                     // _CBEpocDisconnected
01428   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocBadSignal
01429   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocLowBattery
01430   "fun [ObjEpoc fun [ObjEpoc u0 [I I] [I I I I I I I] [I I I I I I I] [F F] F] u1 u0] ObjEpoc",       // _CBEpocHeadsetData
01431   "fun [ObjEpoc fun [ObjEpoc u0 F F F F F] u1 u0] ObjEpoc",     // _CBEpocAffectivData
01432   "fun [ObjEpoc fun [ObjEpoc u0 I I F I F] u1 u0] ObjEpoc",     // _CBEpocExpressivData
01433   "fun [ObjEpoc fun [ObjEpoc u0 I F] u1 u0] ObjEpoc",           // _CBEpocCognitivData
01434   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocExpressivTrainingStarted
01435   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocCognitivTrainingStarted
01436   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocExpressivTrainingCompleted
01437   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocCognitivTrainingCompleted
01438   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocExpressivTrainingErased
01439   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocCognitivTrainingErased
01440   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocExpressivTrainingRejected
01441   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocCognitivTrainingRejected
01442   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocExpressivTrainingSucceeded
01443   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocCognitivTrainingSucceeded
01444   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocExpressivTrainingFailed
01445   "fun [ObjEpoc fun [ObjEpoc u0] u1 u0] ObjEpoc",               // _CBEpocCognitivTrainingFailed
01446   "fun [ObjEpoc fun [ObjEpoc u0 [F r1]] u1 u0] ObjEpoc",        // _CBEpocRawEEGData
01447   "fun [ObjEpoc I] I",                                                                                                                  // _StartExpressivTraining
01448   "fun [ObjEpoc I] I",                                                                                                                  // _EraseExpressivTraining
01449   "fun [ObjEpoc I] I",                                          // _StartCognitivTraining
01450   "fun [ObjEpoc I] I",                                          // _EraseCognitivTraining
01451   "fun [ObjEpoc S] I",                                          // _LoadProfile
01452   "fun [ObjEpoc S] I"                                           // _SaveProfile
01453 };
01454 
01455 
01456 
01464 
01465 
01466 // Everything inside _cond and _endcond is ignored by doxygen
01468 
01473 int LoadEpoc(mmachine m) 
01474 {
01475   // Return variable for PKhardpak function
01476         int k;
01477 
01478         // Declare a new type of object ("OBJEPOCSCOL")
01479         OBJEPOCSCOL = OBJregister(21, 1, destroyEpocObj, "OBJEPOCSCOL");
01480 
01481   EPOC_CONNECTED_CB = OBJgetUserEvent();
01482         OBJdefEvent(EPOC_CONNECTED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocConnectedCb);
01483 
01484   EPOC_DISCONNECTED_CB = OBJgetUserEvent();
01485         OBJdefEvent(EPOC_DISCONNECTED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocDisconnectedCb);
01486 
01487   EPOC_BAD_SIGNAL_CB = OBJgetUserEvent();
01488         OBJdefEvent(EPOC_BAD_SIGNAL_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocBadSignalCb);
01489 
01490   EPOC_LOW_BATTERY_CB = OBJgetUserEvent();
01491         OBJdefEvent(EPOC_LOW_BATTERY_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocLowBatteryCb);
01492 
01493   EPOC_HEADSET_DATA_CB = OBJgetUserEvent();
01494   OBJdefEvent(EPOC_HEADSET_DATA_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocHeadsetDataCb);
01495 
01496   EPOC_AFFECTIV_DATA_CB = OBJgetUserEvent();
01497         OBJdefEvent(EPOC_AFFECTIV_DATA_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocAffectivDataCb);
01498 
01499   EPOC_EXPRESSIV_DATA_CB = OBJgetUserEvent();
01500         OBJdefEvent(EPOC_EXPRESSIV_DATA_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocExpressivDataCb);
01501 
01502   EPOC_COGNITIV_DATA_CB = OBJgetUserEvent();
01503   OBJdefEvent(EPOC_COGNITIV_DATA_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocCognitivDataCb);
01504 
01505   EPOC_EXPRESSIV_TRAINING_STARTED_CB = OBJgetUserEvent();
01506         OBJdefEvent(EPOC_EXPRESSIV_TRAINING_STARTED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocExpressivTrainingStartedCb);
01507 
01508   EPOC_COGNITIV_TRAINING_STARTED_CB = OBJgetUserEvent();
01509         OBJdefEvent(EPOC_COGNITIV_TRAINING_STARTED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocCognitivTrainingStartedCb);
01510 
01511   EPOC_EXPRESSIV_TRAINING_COMPLETED_CB = OBJgetUserEvent();
01512         OBJdefEvent(EPOC_EXPRESSIV_TRAINING_COMPLETED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocExpressivTrainingCompletedCb);
01513 
01514   EPOC_COGNITIV_TRAINING_COMPLETED_CB = OBJgetUserEvent();
01515         OBJdefEvent(EPOC_COGNITIV_TRAINING_COMPLETED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocCognitivTrainingCompletedCb);
01516 
01517   EPOC_EXPRESSIV_TRAINING_ERASED_CB = OBJgetUserEvent();
01518   OBJdefEvent(EPOC_EXPRESSIV_TRAINING_ERASED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocExpressivTrainingErasedCb);
01519 
01520   EPOC_COGNITIV_TRAINING_ERASED_CB = OBJgetUserEvent();
01521   OBJdefEvent(EPOC_COGNITIV_TRAINING_ERASED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocCognitivTrainingErasedCb);
01522 
01523   EPOC_EXPRESSIV_TRAINING_REJECTED_CB = OBJgetUserEvent();
01524   OBJdefEvent(EPOC_EXPRESSIV_TRAINING_REJECTED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocExpressivTrainingRejectedCb);
01525 
01526   EPOC_COGNITIV_TRAINING_REJECTED_CB = OBJgetUserEvent();
01527   OBJdefEvent(EPOC_COGNITIV_TRAINING_REJECTED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocCognitivTrainingRejectedCb);
01528 
01529   EPOC_EXPRESSIV_TRAINING_SUCCEEDED_CB = OBJgetUserEvent();
01530   OBJdefEvent(EPOC_EXPRESSIV_TRAINING_SUCCEEDED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocExpressivTrainingSucceededCb);
01531 
01532   EPOC_COGNITIV_TRAINING_SUCCEEDED_CB = OBJgetUserEvent();
01533   OBJdefEvent(EPOC_COGNITIV_TRAINING_SUCCEEDED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocCognitivTrainingSucceededCb);
01534 
01535   EPOC_EXPRESSIV_TRAINING_FAILED_CB = OBJgetUserEvent();
01536   OBJdefEvent(EPOC_EXPRESSIV_TRAINING_FAILED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocExpressivTrainingFailedCb);
01537 
01538   EPOC_COGNITIV_TRAINING_FAILED_CB = OBJgetUserEvent();
01539   OBJdefEvent(EPOC_COGNITIV_TRAINING_FAILED_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocCognitivTrainingFailedCb);
01540   
01541   EPOC_RAW_EEG_CB = OBJgetUserEvent();
01542   OBJdefEvent(EPOC_RAW_EEG_CB, (int (__cdecl *)(struct Mmachine *, int, unsigned int, int, int, int *))getEpocRawEEGDataCb);
01543 
01544   // Load package
01545         k = PKhardpak(m, "EpocEngine", NbTplPKG, TplName, TplFunc, TplNArg, TplType);
01546         return k;
01547 }
01548 
01550 
01551 
01552 // Clean all connections to an Emotiv EPOC headset
01553 void CleanDirtyConnections()
01554 {
01555   std::list<Epoc*>::iterator iEpocList = lEpocList.begin();
01556   while (iEpocList != lEpocList.begin())
01557   {
01558     (*iEpocList)->Disconnect();
01559     iEpocList++;
01560   }
01561 }
01562 
01563 
01567 extern "C" __declspec (dllexport) int ScolLoadPlugin(mmachine m, cbmachine w) 
01568 {
01569         SCOLinitplugin(w);
01570 
01571         // Get Scol window handle (for message callback)
01572         HScol = (HWND)SCgetExtra("hscol");
01573         LoadEpoc(m);
01574         return 0;
01575 }
01576 
01577 
01582 extern "C" __declspec (dllexport) int ScolUnloadPlugin() 
01583 {
01584   // Clean all connections to an Emotiv EPOC headset
01585   CleanDirtyConnections();
01586         return 0;
01587 }