/*
-----------------------------------------------------------------------------
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
]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)=
_dsGPIOpin obstr.GPIOIN_iPin;
0;;
/*! \brief Callback on "Write" dms action
*
* Write 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 cbWrite(inst, from, action, param, reply, obstr)=
if (obstr.GPIOIN_iMode == 0) then
_GPIOdigitalWrite obstr.GPIOIN_iPin atoi param
else if (obstr.GPIOIN_iMode == 1) then
_GPIOanalogWrite obstr.GPIOIN_iPin atoi param
else
_GPIOpwmWrite obstr.GPIOIN_iPin atoi param;
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 "initvalue") -> initvalue in
let if initvalue == nil then 0 else initvalue -> initvalue in
let if mode == 2 then
GPIO_PWM_OUTPUT
else
GPIO_OUTPUT
-> outmode in
let mkPlugGPIOinput [nil mode] -> obstr in
(
set obstr.GPIOIN_iPin = _crGPIOpin _channel pin outmode;
if (mode == 0) then
_GPIOdigitalWrite obstr.GPIOIN_iPin initvalue
else if (obstr.GPIOIN_iMode == 1) then
_GPIOanalogWrite obstr.GPIOIN_iPin initvalue
else
_GPIOpwmWrite obstr.GPIOIN_iPin initvalue;
PluginRegisterAction inst "Write" mkfun6 @cbWrite 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;;