/*
-----------------------------------------------------------------------------
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 PlugSYSCmd = [
SYSCMD_inst : PInstance,
SYSCMD_oSysCmd : ObjSysCommand,
SYSCMD_sCmd : S
]mkPlugSYSCmd;;
/*! \brief Callback on instance destruction
*
* Prototype: fun [PInstance PlugSYSCmd] I
*
* \param PInstance : destroyed plugIT instance
* \param PlugSYSCmd : gpio structure
*
* \return I : 0
**/
fun deleteOb(inst, obstr)=
if (obstr.SYSCMD_oSysCmd == nil) then nil else
killSysCommand obstr.SYSCMD_oSysCmd;
set obstr.SYSCMD_oSysCmd = nil;
0;;
fun cbOutput(cmdobj, obstr, value)=
SendPluginEvent obstr.SYSCMD_inst "Output" value obstr.SYSCMD_inst.INST_sName;
0;;
fun cbError(cmdobj, obstr, value)=
SendPluginEvent obstr.SYSCMD_inst "Errors" value obstr.SYSCMD_inst.INST_sName;
//addLogMessage strcat "System command error : " value;
0;;
fun cbCommand(inst, from, action, param, reply, obstr)=
if (obstr.SYSCMD_oSysCmd == nil) then nil else
(
killSysCommand obstr.SYSCMD_oSysCmd;
set obstr.SYSCMD_oSysCmd = nil;
);
if (param == nil) then nil else
set obstr.SYSCMD_sCmd = param;
set obstr.SYSCMD_oSysCmd = callSysCommand _channel obstr.SYSCMD_sCmd @cbOutput obstr @cbError obstr;
0;;
fun cbLoaded(inst, obstr)=
cbCommand inst nil nil nil nil obstr;
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 getPluginInstanceParam inst "cmd" -> cmd in
let if cmd == nil then "" else cmd -> cmd in
let atoi (getPluginInstanceParam inst "init") -> init in
let if init == nil then 0 else init -> init in
let mkPlugSYSCmd [inst nil cmd] -> obstr in
(
PluginRegisterAction inst "Command" mkfun6 @cbCommand obstr;
setPluginInstanceCbDel inst mkfun2 @deleteOb obstr;
if (!init) then nil else
(
if inst.INST_groupstr.GRP_project.PRJ_bPluginsLoaded then
(
cbCommand inst nil nil nil nil obstr;
0;
)
else
(
setPluginInstanceCbAllPluginsLoaded inst mkfun2 @cbLoaded obstr;
0;
);
);
);
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;;