/* ----------------------------------------------------------------------------- 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 DataGlove = [ GLOVE_inst : PInstance, GLOVE_object : ObjGlove, GLOVE_flashInterface : SO3_WIDGET, GLOVE_sFlashPath : S, GLOVE_iLastGesture : I ] mkDataGlove;; var lGestureEvents = [0 "Closed hand"]:: [1 "Thumb point"]:: [2 "Index point"]:: [3 "Thumb and index point"]:: [4 "Middle point"]:: [6 "Index and middle point"]:: [7 "Three first fingers"]:: [8 "Ring point"]:: [14 "Three middle fingers"]:: [15 "Four first fingers"]:: [16 "Little point"]:: [19 "Spiderman hand"]:: [30 "Four last fingers"]:: [31 "Flat hand"]:: nil;; /*------------------ Delete Glove object -------------------*/ fun deleteOb(inst, gloveStr)= // Destroy glove instance _DTGloveCloseDevice gloveStr.GLOVE_object; // Destroy Flash object V3DremoveWidgetControl (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) gloveStr.GLOVE_flashInterface; SO3WidgetDestroy gloveStr.GLOVE_flashInterface; 0;; /*----------------------- Callbacks ------------------------*/ /* New gesture index */ fun cbHand(glove, gloveStr, gestureIndex)= if (gestureIndex != gloveStr.GLOVE_iLastGesture) then ( SendPluginEvent gloveStr.GLOVE_inst "Raw Gesture Value" itoa gestureIndex nil; let switch lGestureEvents gestureIndex -> event in SendPluginEvent gloveStr.GLOVE_inst event nil nil; // Update last gesture made set gloveStr.GLOVE_iLastGesture = gestureIndex; ) else nil; 0;; /* New sensors values and gesture index (INCLUDING thumb) */ fun cbHandRawData(glove, gloveStr, p1, p2, p3, p4, p5, abduction, tw, pr)= let ["thumb" p1]:: ["index" p2]:: ["middle" p3]:: ["ring" p4]:: ["little" p5]::nil -> fingerList in { let 0 -> i in while (i <= 4) do { let nth_list fingerList i -> [fingerName [nearValue farValue]] in let strcat fingerName " near" -> fingerNear in let strcat fingerName " far" -> fingerFar in { //TODO : renvoyer un vecteur de 5 vecteurs/flottants de rotation entre -180 a 180 avec reglage d'un offset SendPluginEvent gloveStr.GLOVE_inst fingerNear ftoa nearValue nil; SendPluginEvent gloveStr.GLOVE_inst fingerFar ftoa farValue nil; }; set i = i + 1; }; }; 0;; /* Start of calibration process */ fun cbCalibrationStart(glove, flashCtrl)= SO3WidgetCallFunction flashCtrl "setStatus" "Calibration started..."::nil; 0;; /* End of calibration process */ fun cbCalibrationEnd(glove, p)= let p -> [inst flashCtrl] in ( SO3WidgetCallFunction flashCtrl "setStatus" "Calibration finished !"::nil; SendPluginEvent inst "Calibration ended" nil nil; ); 0;; /* Event into Flash interface*/ fun cbFlashCalibrate(flashCtrl, p, functionName, listOfParams)= let p -> [glove functionName listOfParams] in ( _DTGloveCalibrate glove; // Add a call to a plugIT action instead of calling directly Calibration function ); 0;; /* Start calibration */ fun cbStartCalibration(inst, from, action, param, reply, gloveStr)= _DTGloveCalibrate gloveStr.GLOVE_object; 0;; /*--------------- Create new Glove instance ----------------*/ fun newOb(inst)= // Retrieve plugIT parameters let atoi (getPluginInstanceParam inst "showInterface") -> showInterface in // Open data glove let _DTGloveOpenDevice _channel -> glove in // Retrieve Flash interface path let (getPluginInstanceParam inst "path") -> path in // Create Flash object only if a data glove could be opened if (glove == nil) then nil else ( //let strcatn (getPluginDirectory (getInstancePlugin inst))::"/"::path::nil -> calibrationPath in // Create path to look for Flash file let path -> calibrationPath in let (V3DgetDefaultViewport (V3DgetSessionView c3dXsession)) -> viewportstr in let SO3FlashControlCreate (V3DgetSession c3dXsession) viewportstr.V3D_viewport (strcat (getPluginInstanceName inst) "_calibration") 0 0 1440 900 0 -> flashCtrl in // Set the data glove global structure let mkDataGlove [inst glove flashCtrl calibrationPath 0] -> gloveStr in ( // Define Flash object initial state if (flashCtrl == nil) then nil else ( // Set initial parameters of flash interface SO3WidgetLoadFile flashCtrl (_checkpack path); // Set interface visibility SO3WidgetSetVisibility flashCtrl showInterface; SO3WidgetSetTransparency flashCtrl 1; SO3WidgetSetOpacity flashCtrl 0.9; // Update Flash interface components (calibration status, data glove type and calibration instructions SO3WidgetCallFunction flashCtrl "setStatus" "Calibration not done."::nil; SO3WidgetCallFunction flashCtrl "setGloveType" (strcat "Data Glove : " (_DTGloveGetSerialNumber glove))::nil; SO3WidgetCallFunction flashCtrl "setCalibrationInfo" "NOTE: Open/close your hand several times to calibrate the data glove."::nil; // Associate a callback function to the event related to a click on "Calibrate" function SO3WidgetOnScriptEventCb flashCtrl @cbFlashCalibrate [glove "startCalibration" nil::nil]; ); // Associate callbacks to actions PluginRegisterAction inst "Start calibration" mkfun6 @cbStartCalibration gloveStr; // Define the callback to call when the plugin instance is deleted setPluginInstanceCbDel inst mkfun2 @deleteOb gloveStr; // Associate callbacks to the current data glove _CBDTGloveRawData glove @cbHandRawData gloveStr; _CBDTGloveGesture glove @cbHand gloveStr; _CBDTGloveCalibrationStart glove @cbCalibrationStart flashCtrl; _CBDTGloveCalibrationEnd glove @cbCalibrationEnd [inst flashCtrl]; ); ); 0;; /*------------------- Initialize plugIT --------------------*/ fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;