/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ /*-------------------- Global variables --------------------*/ struct Smi = [ SMI_inst : PInstance, SMI_object : ObjSmi, SMI_senderIp : S, SMI_senderPort : I, SMI_receiverIp : S, SMI_receiverPort : I, SMI_nbPoints : I, SMI_validation : I, SMI_display : I, SMI_speed : I, SMI_foregroundBrightness : I, SMI_backgroundBrightness : I, SMI_targetShape : I, SMI_targetSize : I, SMI_showEyes : I ] mkSmi;; /*------------------ Delete SMI RED eye tracking instance -------------------*/ fun deleteOb(inst, smiStr)= // Close connection to eye tracking system if smiStr.SMI_object == nil then nil else _CloseSmiDevice smiStr.SMI_object; 0;; /*----------------------- Events ------------------------*/ /* SMI RED connected */ fun cbConnected(smi, smiStr)= // Send connection event SendPluginEvent smiStr.SMI_inst "Connected" nil nil; // Check if eye tracking window must be displayed if (smiStr.SMI_showEyes == 1) then _ShowEyes smiStr.SMI_object smiStr.SMI_showEyes else nil; 0;; /* SMI RED disconnected */ fun cbDisconnected(smi, smiStr)= SendPluginEvent smiStr.SMI_inst "Disconnected" nil nil; 0;; /* Calibration done for SMI RED */ fun cbCalibrationDone(smi, smiStr)= SendPluginEvent smiStr.SMI_inst "Calibration done" nil nil; 0;; /* New fixation data for SMI RED */ fun cbNewFixation(smi, smiStr, duration, posX, posY)= SendPluginEvent smiStr.SMI_inst "Fixation duration" ftoa duration nil; SendPluginEvent smiStr.SMI_inst "Fixation pos X" itoa posX nil; SendPluginEvent smiStr.SMI_inst "Fixation pos Y" itoa posY nil; 0;; /* New sample data for SMI RED */ /*fun cbNewSample(smi, smiStr, leftEye, rightEye)= let leftEye -> [lDiam lGazeX lGazeY] in let rightEye -> [rDiam rGazeX rGazeY] in ( SendPluginEvent smiStr.SMI_inst "Left eye gaze pos" strbuild ((itoa lGazeX)::(itoa lGazeY)::nil)::nil nil; SendPluginEvent smiStr.SMI_inst "Left eye diameter" ftoa lDiam nil; SendPluginEvent smiStr.SMI_inst "Right eye gaze pos" strbuild ((itoa rGazeX)::(itoa rGazeY)::nil)::nil nil; SendPluginEvent smiStr.SMI_inst "Right eye diameter" ftoa rDiam nil; ); 0;;*/ /*----------------------- Actions ------------------------*/ fun cbCalibrate(inst, from, action, param, reply, smiStr)= _StartCalibration smiStr.SMI_object smiStr.SMI_nbPoints smiStr.SMI_validation smiStr.SMI_display smiStr.SMI_speed smiStr.SMI_foregroundBrightness smiStr.SMI_backgroundBrightness smiStr.SMI_targetShape smiStr.SMI_targetSize; 0;; /*--------------- Create new SMI RED eye tracking instance ----------------*/ fun newOb(inst)= let getPluginInstanceParam inst "senderIp" -> senderIp in let atoi (getPluginInstanceParam inst "senderPort") -> senderPort in let getPluginInstanceParam inst "receiverIp" -> receiverIp in let atoi (getPluginInstanceParam inst "receiverPort") -> receiverPort in let atoi (getPluginInstanceParam inst "nbPoints") -> nbPoints in let atoi (getPluginInstanceParam inst "validation") -> validation in let atoi (getPluginInstanceParam inst "display") -> display in let atoi (getPluginInstanceParam inst "speed") -> speed in let atoi (getPluginInstanceParam inst "foregroundBrightness") -> foregroundBrightness in let atoi (getPluginInstanceParam inst "backgroundBrightness") -> backgroundBrightness in let atoi (getPluginInstanceParam inst "targetShape") -> targetShape in let atoi (getPluginInstanceParam inst "targetSize") -> targetSize in let atoi (getPluginInstanceParam inst "showEyes") -> showEyes in // Try to connect to eye tracking system let _OpenSmiDevice _channel senderIp senderPort receiverIp receiverPort -> smi in if (smi == nil) then nil else ( // Set the SMI RED global structure let mkSmi [inst smi senderIp senderPort receiverIp receiverPort nbPoints validation display speed foregroundBrightness backgroundBrightness targetShape targetSize showEyes] -> smiStr in ( // Associate callbacks to actions PluginRegisterAction inst "Calibrate" mkfun6 @cbCalibrate smiStr; // Define the callback to call when the plugin instance is deleted setPluginInstanceCbDel inst mkfun2 @deleteOb smiStr; // Associate callbacks to events _CBSmiConnected smi @cbConnected smiStr; _CBSmiDisconnected smi @cbDisconnected smiStr; _CBSmiCalibrationDone smi @cbCalibrationDone smiStr; _CBSmiNewFixation smi @cbNewFixation smiStr; //_CBSmiNewSample smi @cbNewSample smiStr; ); ); 0;; /*------------------- Initialize plugIT --------------------*/ fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;