/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2015 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 ----------------------------------------------------------------------------- */ /*------------------ Delete PlugIT instance -------------------*/ fun deleteOb(inst)= _SetSensorEnable SENSOR_TYPE_ACCELEROMETER 0; setPluginInstanceCbScenePreRender inst nil; 0;; fun cbPreRender(inst, sessionstr, etime)= let _GetVectorData SENSOR_TYPE_ACCELEROMETER -> [x y z] in SendPluginEvent inst "Value" strcatn (ftoa x)::" "::(ftoa y)::" "::(ftoa z)::nil inst.INST_sName; 0;; /*----------------------- Callbacks ------------------------*/ fun cbEnable(inst, from, action, param, rep)= if !(_IsSensorAvailable SENSOR_TYPE_ACCELEROMETER) then nil else ( _SetSensorEnable SENSOR_TYPE_ACCELEROMETER 1; setPluginInstanceCbScenePreRender inst @cbPreRender; ); 0;; fun cbDisable(inst, from, action, param, rep)= if !(_IsSensorAvailable SENSOR_TYPE_ACCELEROMETER) then nil else ( _SetSensorEnable SENSOR_TYPE_ACCELEROMETER 0; setPluginInstanceCbScenePreRender inst nil; ); 0;; /*--------------- Create new PlugIT instance ----------------*/ fun newOb(inst)= if !(_IsSensorAvailable SENSOR_TYPE_ACCELEROMETER) then ( SendPluginEvent inst "Sensor not found" nil nil; 0; ) else ( let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in if (!init) then nil else ( _SetSensorEnable SENSOR_TYPE_ACCELEROMETER 1; setPluginInstanceCbScenePreRender inst @cbPreRender; ); PluginRegisterAction inst "Enable" @cbEnable; PluginRegisterAction inst "Disable" @cbDisable; SendPluginEvent inst "Sensor found" nil nil; ); setPluginInstanceCbDel inst @deleteOb; 0;; /*------------------- Initialize PlugIT --------------------*/ fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;