/*
-----------------------------------------------------------------------------
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
*/
/*! \brief Callback on instance destruction
*
* Prototype: fun [PInstance] I
*
* \param PInstance : destroyed plugIT instance
*
* \return I : 0
**/
fun deleteOb(inst, p)=
let p -> [mNeurosky] in
_DSNeurosky mNeurosky;
0;;
/*! \brief Callback on "attention" dms action
*
* Get the attention value from neurosky datas
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNeurosky : NeuroSky Instance
* \param PInstance : plugIT instance
* \param I : Attention value
*
* \return I : 0
**/
fun cbReadAttentionData(mNeurosky, inst, attention)=
SendPluginEvent inst "attention" ftoa attention nil;
0;;
/*! \brief Callback on "Meditation" dms action
*
* Get the meditation value from neurosky datas
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNeurosky : NeuroSky Instance
* \param PInstance : plugIT instance
* \param I : Meditation value
*
* \return I : 0
**/
fun cbReadMeditationData(mNeurosky, inst, meditation)=
SendPluginEvent inst "meditation" ftoa meditation nil;
0;;
/*! \brief Callback on "blink" dms action
*
* Get the blink value from neurosky datas
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNeurosky : NeuroSky Instance
* \param PInstance : plugIT instance
* \param I : battery value
*
* \return I : 0
**/
fun cbReadBlinkData(mNeurosky, inst, blink)=
SendPluginEvent inst "blink" ftoa blink nil;
0;;
/*! \brief Callback on "poor_quality" dms action
*
* Get the signal quality value from neurosky datas
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNeurosky : NeuroSky Instance
* \param PInstance : plugIT instance
* \param I : poor_quality value
*
* \return I : 0
**/
fun cbReadPoorQualityData(mNeurosky, inst, poorQuality)=
SendPluginEvent inst "poor_quality" ftoa poorQuality nil;
0;;
/*! \brief Callback on "raw_signal" dms action
*
* Get the attention value from neurosky datas
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNeurosky : NeuroSky Instance
* \param PInstance : plugIT instance
* \param I : raw_signal value
*
* \return I : 0
**/
fun cbReadRawSignalData(mNeurosky, inst, rawSignal)=
SendPluginEvent inst "raw_signal" ftoa rawSignal nil;
0;;
/*! \brief Callback on "EEG Datas" dms action
*
* Get the attention value from neurosky datas
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNeurosky : NeuroSky Instance
* \param PInstance : plugIT instance
* \param I : eegDelta value
* \param I : eegTheta value
* \param I : eegLowAlpha value
* \param I : eegHighAlpha value
* \param I : eegLowBeta value
* \param I : eegHighBeta value
* \param I : eegLowGamma value
* \param I : eegHighGamma value
*
* \return I : 0
**/
fun cbReadEEGData(mNeurosky, inst, delta, theta, low_alpha, high_alpha, low_beta, high_beta, low_gamma, high_gamma)=
SendPluginEvent inst "eegDelta" itoa delta nil;
SendPluginEvent inst "eegTheta" itoa theta nil;
SendPluginEvent inst "eegLowAlpha" itoa low_alpha nil;
SendPluginEvent inst "eegHighAlpha" itoa high_alpha nil;
SendPluginEvent inst "eegLowBeta" itoa low_beta nil;
SendPluginEvent inst "eegHighBeta" itoa high_beta nil;
SendPluginEvent inst "eegLowGamma" itoa low_gamma nil;
SendPluginEvent inst "eegHighGamma" itoa high_gamma nil;
0;;
/*! \brief Callback on "connected" dms action
*
* Get event when neurosky is connected
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNeurosky : NeuroSky Instance
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun cbConnected(mNeurosky, inst)=
SendPluginEvent inst "connected" nil nil;
0;;
/*! \brief Callback on "disconnected" dms action
*
* Get event when neurosky is disconnected
*
* Prototype: fun [PInstance DMI S S I [F F F I]] I
*
* \param OBJNeurosky : NeuroSky Instance
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun cbDisconnected(mNeurosky, inst)=
SendPluginEvent inst "disconnected" nil nil;
0;;
fun cbEnableNeurosky(inst, from, action, param, rep, p)=
let _CRNeurosky _channel -> mNeurosky in
(
_CBNeuroskyAttentionData mNeurosky @cbReadAttentionData inst;
_CBNeuroskyMeditationData mNeurosky @cbReadMeditationData inst;
_CBNeuroskyBlinkData mNeurosky @cbReadBlinkData inst;
_CBNeuroskyPoorQualityData mNeurosky @cbReadPoorQualityData inst;
_CBNeuroskyRawSignalData mNeurosky @cbReadRawSignalData inst;
_CBNeuroskyEEGData mNeurosky @cbReadEEGData inst;
_CBNeuroskyConnected mNeurosky @cbConnected inst;
_CBNeuroskyDisconnected mNeurosky @cbDisconnected inst;
mutate p <- [mNeurosky];
);
0;;
fun cbDisableNeurosky(inst, from, action, param, rep, p)=
let p -> [mNeurosky] in
_DSNeurosky mNeurosky;
mutate p <- [nil];
0;;
/*! \brief Callback on new plugIT instance
*
* Read the datas from Neurosky BCI
*
* Prototype: fun [PInstance] I
*
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun newOb(inst)=
let atoi (getPluginInstanceParam inst "init") -> init in
let if (init == nil) then 1 else init -> init in
let [nil] -> p in
(
if (!init) then nil else
cbEnableNeurosky inst nil nil nil nil p;
PluginRegisterAction inst "Enable" mkfun6 @cbEnableNeurosky p;
PluginRegisterAction inst "Disable" mkfun6 @cbDisableNeurosky p;
setPluginInstanceCbDel inst mkfun2 @deleteOb p;
);
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;;