/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2016 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 ----------------------------------------------------------------------------- */ /* Version : 1.0 First version : 05/29/2016 Author : Bourineau Bastien */ struct PlugGPIOinput = [ GPIOIN_iPin : ObjGpioPin, GPIOIN_iMode : I, GPIOIN_iPullMode : I, GPIOIN_iLastValue : I ]mkPlugGPIOinput;; /*! \brief Callback on instance destruction * * Prototype: fun [PInstance PlugGPIOinput] I * * \param PInstance : destroyed plugIT instance * \param PlugGPIOinput : gpio structure * * \return I : 0 **/ fun deleteOb(inst, obstr)= setPluginInstanceCbScenePreRender inst nil; _setGPIOpinPullMode obstr.GPIOIN_iPin GPIO_PUD_OFF; _dsGPIOpin obstr.GPIOIN_iPin; 0;; /*! \brief Callback on "Read" dms action * * Read param link data to GPIO pin * * Prototype: fun [PInstance DMI S S I PlugGPIOinput] I * * \param PInstance : plugIT instance * \param DMI : DMS module who call the action (not used) * \param S : name of the launched action * \param S : data posted in DMS action link * \param I : reply flag (not used) * \param PlugGPIOinput : gpio structure * * \return I : 0 **/ fun cbRead(inst, from, action, param, reply, obstr)= let if (!obstr.GPIOIN_iMode) then _GPIOdigitalRead obstr.GPIOIN_iPin else _GPIOanalogRead obstr.GPIOIN_iPin -> value in SendPluginEvent inst "Value" itoa value inst.INST_sName; 0;; fun cbPreRender(inst, sessionstr, etime, obstr)= let if (!obstr.GPIOIN_iMode) then _GPIOdigitalRead obstr.GPIOIN_iPin else _GPIOanalogRead obstr.GPIOIN_iPin -> value in ( if (value == obstr.GPIOIN_iLastValue) then nil else ( SendPluginEvent inst "Value" itoa value inst.INST_sName; if ((!obstr.GPIOIN_iMode) && value) then SendPluginEvent inst "On" nil inst.INST_sName else if (obstr.GPIOIN_iMode) then SendPluginEvent inst "Off" nil inst.INST_sName; ); set obstr.GPIOIN_iLastValue = value; ); 0;; /*! \brief Callback on new plugIT instance * * Read the parameters from editor values and init GPIO pin * * Prototype: fun [PInstance] I * * \param PInstance : plugIT instance * * \return I : 0 **/ fun newOb(inst)= let atoi (getPluginInstanceParam inst "pin") -> pin in let if pin == nil then 2 else pin -> pin in let atoi (getPluginInstanceParam inst "mode") -> mode in let if mode == nil then 0 else mode -> mode in let atoi (getPluginInstanceParam inst "pullmode") -> pullmode in let if pullmode == nil then 0 else pullmode -> pullmode in let mkPlugGPIOinput [nil mode pullmode 0] -> obstr in ( set obstr.GPIOIN_iPin = _crGPIOpin _channel pin if (!mode) then GPIO_INPUT else GPIO_DIGITAL_INPUT; _setGPIOpinPullMode obstr.GPIOIN_iPin pullmode; //PluginRegisterAction inst "Read" mkfun6 @cbRead obstr; setPluginInstanceCbScenePreRender inst mkfun4 @cbPreRender obstr; setPluginInstanceCbDel inst mkfun2 @deleteOb obstr; ); 0;; /*! \brief Global plugIT function to initialize the plugIT callbacks * * Prototype: fun [S] I * * \param S : plugIT file path * * \return I : 0 **/ fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;