/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com
Copyright (c) 2012 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/08/2010
Author : Hamza Hamdi
*/
/*-------------------- Global structure --------------------*/
struct Nonin = [
NONIN_inst : PInstance,
NONIN_object : ObjNonin,
NONIN_iOptions : I
] mkNonin;;
/*! \brief Callback on instance destruction
*
* Prototype: fun [PInstance] I
*
* \param PInstance : destroyed plugIT instance
*
* \return I : 0
**/
fun deleteOb(inst, noninstr)=
_DSNonin noninstr.NONIN_object;
set noninstr.NONIN_object = nil;
0;;
fun cbDisable(inst, from, action, param, rep, noninstr)=
SendPluginEvent inst "disconnected" nil nil;
deleteOb inst noninstr;
0;;
/*! \brief Callback on "connected" dms action
*
* Get event when Nonin is connected
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNonin : Nonin Instance
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun cbConnected(mNonin, noninstr)=
SendPluginEvent noninstr.NONIN_inst "connected" nil nil;
0;;
/*! \brief Callback on "disconnected" dms action
*
* Get event when Nonin is disconnected
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNonin : Nonin Instance
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun cbDisconnected(mNonin, noninstr)=
SendPluginEvent noninstr.NONIN_inst "disconnected" nil nil;
0;;
/*! \brief Callback on "heart_rate" dms action
*
* Get event when Nonin send an 4 beat Heart rate
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNonin : Nonin Instance
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun cbHR(mNonin, noninstr, hr)=
SendPluginEvent noninstr.NONIN_inst "heart_rate" itoa hr nil;
0;;
/*! \brief Callback on "spO2" dms action
*
* Get event when Nonin send an 4 beat SPO2 value
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNonin : Nonin Instance
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun cbSPO2(mNonin, noninstr, spo2)=
SendPluginEvent noninstr.NONIN_inst "spo2" itoa spo2 nil;
0;;
/*! \brief Callback on "sensor_alarm" dms action
*
* Get event when Nonin send an sensor alarm event
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNonin : Nonin Instance
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun cbSNSA(mNonin, noninstr)=
SendPluginEvent noninstr.NONIN_inst "sensor_alarm" nil nil;
0;;
/*! \brief Callback on "low_battery" dms action
*
* Get event when Nonin send a low battery event
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNonin : Nonin Instance
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun cbLowBattery(nonin, noninstr)=
SendPluginEvent noninstr.NONIN_inst "low_battery" nil nil;
0;;
fun cbEnable(inst, from, action, param, rep, noninstr)=
if (noninstr.NONIN_object != nil) then nil else
(
set noninstr.NONIN_object = _CRNonin _channel noninstr.NONIN_iOptions;
_CBNoninConnected noninstr.NONIN_object @cbConnected noninstr;
_CBNoninDisconnected noninstr.NONIN_object @cbDisconnected noninstr;
_CBNoninHR noninstr.NONIN_object @cbHR noninstr;
_CBNoninSPO2 noninstr.NONIN_object @cbSPO2 noninstr;
_CBNoninSNSA noninstr.NONIN_object @cbSNSA noninstr;
_CBNoninLowBattery noninstr.NONIN_object @cbLowBattery noninstr;
);
0;;
/*! \brief Callback on new plugIT instance
*
* Read the datas from Nonin BCI
*
* Prototype: fun [PInstance] I
*
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun newOb(inst)=
let atoi (getPluginInstanceParam inst "oninit") -> oninit in
let atoi getPluginInstanceParam inst "hr" -> hr in
let atoi getPluginInstanceParam inst "spo2" -> spo2 in
let getPluginInstanceParam inst "format" -> formatName in
let 0 -> options in
let mkNonin [inst nil 0] -> noninstr in
(
if (!hr) then nil else
set noninstr.NONIN_iOptions = NONIN_HR_ENABLE;
if (!spo2) then nil else
set noninstr.NONIN_iOptions = noninstr.NONIN_iOptions|NONIN_SPO2_ENABLE;
if (!strcmp formatName "Average using 1 value") then
set noninstr.NONIN_iOptions = noninstr.NONIN_iOptions|NONIN_1_VALUE_AVERAGE
else if (!strcmp formatName "Average using 4 value") then
set noninstr.NONIN_iOptions = noninstr.NONIN_iOptions|NONIN_4_VALUE_AVERAGE
else if (!strcmp formatName "Average using 8 value") then
set noninstr.NONIN_iOptions = noninstr.NONIN_iOptions|NONIN_8_VALUE_AVERAGE
else nil;
if !oninit then nil else
cbEnable inst nil nil nil nil noninstr;
PluginRegisterAction inst "enable" mkfun6 @cbEnable noninstr;
PluginRegisterAction inst "disable" mkfun6 @cbDisable noninstr;
setPluginInstanceCbDel inst mkfun2 @deleteOb noninstr;
);
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;;