/*
-----------------------------------------------------------------------------
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 PlugGPIOpBtn = [
GPIOPBTN_iPin : ObjGpioPin,
GPIOPBTN_iLastValue : I
]mkPlugGPIOpBtn;;
/*! \brief Callback on instance destruction
*
* Prototype: fun [PInstance PlugGPIOpBtn] I
*
* \param PInstance : destroyed plugIT instance
* \param PlugGPIOpBtn : gpio structure
*
* \return I : 0
**/
fun deleteOb(inst, obstr)=
setPluginInstanceCbScenePreRender inst nil;
_setGPIOpinPullMode obstr.GPIOPBTN_iPin GPIO_PUD_OFF;
_dsGPIOpin obstr.GPIOPBTN_iPin;
0;;
fun cbPreRender(inst, sessionstr, etime, obstr)=
let _GPIOdigitalRead obstr.GPIOPBTN_iPin -> value in
(
if (value == obstr.GPIOPBTN_iLastValue) then nil else
(
if (value) then
SendPluginEvent inst "On" nil inst.INST_sName
else
SendPluginEvent inst "Off" nil inst.INST_sName;
);
set obstr.GPIOPBTN_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 mkPlugGPIOpBtn [nil 0] -> obstr in
(
set obstr.GPIOPBTN_iPin = _crGPIOpin _channel pin GPIO_INPUT;
_setGPIOpinPullMode obstr.GPIOPBTN_iPin GPIO_PUD_UP;
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;;