Commit 540fcfa9 authored by RIOU Cedric's avatar RIOU Cedric

[plugins] LUA Stimulator: add 'delay(s)' as modifiable setting handled by name

  - example to test settings handling
  - identify 'delay(s)' setting by CIdentifier

[CORE-1249](https://jira.mensiatech.com/browse/CORE-1249)
parent b4a37d00
......@@ -242,7 +242,7 @@ SET(SKIP_DOCUMENTATION "1")
#SET(SKIP_CONTRIB_PLUGINS_PROCESSING_PYTHON "1")
# Skipping demos can speed up compilation a lot, if you don't need them
#SET(SKIP_APPLICATIONS_DEMOS "1")
SET(SKIP_APPLICATIONS_DEMOS "1")
#SET(SKIP_CONTRIB_APPLICATIONS "1")
IF(UNIX)
......
......@@ -48,7 +48,7 @@ function process(box)
box:remove_stimulation(input, 1)
-- triggers a new OVTK_StimulationId_Label_00 stimulation five seconds after
box:send_stimulation(1, OVTK_StimulationId_Label_00, t+5, 0)
box:send_stimulation(1, OVTK_StimulationId_Label_00, t+box:get_setting_by_name("delay(s)"), 0)
end
end
......
......@@ -163,6 +163,19 @@ static int lua_get_setting_cb(lua_State* pState)
return 1;
}
static int lua_get_setting_by_name_cb(lua_State* pState)
{
CString l_sSetting;
CBoxAlgorithmLuaStimulator* l_pThis=static_cast < CBoxAlgorithmLuaStimulator* >(lua_touserdata(pState, lua_upvalueindex(1)));
__CB_Assert__(l_pThis != NULL);
if(!lua_check_argument_count(pState, "get_setting_by_name", 1)) return 0;
__CB_Assert__(l_pThis->getSettingCB(lua_tostring(pState, 2), l_sSetting));
lua_pushstring(pState, l_sSetting.toASCIIString());
return 1;
}
static int lua_get_config_cb(lua_State* pState)
{
CString l_sConfiguration;
......@@ -401,6 +414,7 @@ boolean CBoxAlgorithmLuaStimulator::initialize(void)
lua_setcallback(m_pLuaState, "get_output_count", ::lua_get_output_count_cb, this);
lua_setcallback(m_pLuaState, "get_setting_count", ::lua_get_setting_count_cb, this);
lua_setcallback(m_pLuaState, "get_setting", ::lua_get_setting_cb, this);
lua_setcallback(m_pLuaState, "get_setting_by_name", ::lua_get_setting_by_name_cb, this);
lua_setcallback(m_pLuaState, "get_config", ::lua_get_config_cb, this);
lua_setcallback(m_pLuaState, "get_current_time", ::lua_get_current_time_cb, this);
lua_setcallback(m_pLuaState, "sleep", ::lua_sleep_cb, this);
......@@ -753,6 +767,26 @@ boolean CBoxAlgorithmLuaStimulator::getSettingCountCB(uint32& rui32Count)
return true;
}
boolean CBoxAlgorithmLuaStimulator::getSettingCB(const CString& rsName, CString& rsSetting)
{
char *pEnd;
if(!this->getStaticBoxContext().getSettingValue(rsName, rsSetting))
{
this->getLogManager() << LogLevel_Warning << "Setting " << rsName << " does not exist\n";
rsSetting=CString("");
return true;
}
rsSetting = CString(std::to_string(std::strtol(rsSetting.toASCIIString(),&pEnd,10)).c_str());
// catch non numeric value
if(*pEnd)
{
// conversion has failed
this->getStaticBoxContext().getSettingDefaultValue(rsName,rsSetting);
this->getLogManager() << LogLevel_Warning << "Bad value for setting '" << rsName << "'. Use default value: " << rsSetting << "\n";
}
return true;
}
boolean CBoxAlgorithmLuaStimulator::getSettingCB(uint32 ui32SettingIndex, CString& rsSetting)
{
if(ui32SettingIndex >= this->getStaticBoxContext().getSettingCount())
......
......@@ -16,6 +16,10 @@
#include <cstdio>
#include <cstring>
#include <openvibe/ov_all.h>
#include <toolkit/ovtk_all.h>
#include <visualization-toolkit/ovviz_all.h>
extern "C"
{
#include "lua.h"
......@@ -27,8 +31,10 @@ extern "C"
// - please move the identifier definitions in ovp_defines.h
// - please include your desciptor in ovp_main.cpp
#define OVP_ClassId_BoxAlgorithm_LuaStimulator OpenViBE::CIdentifier(0x0B5A2787, 0x02750621)
#define OVP_ClassId_BoxAlgorithm_LuaStimulatorDesc OpenViBE::CIdentifier(0x67AF36F3, 0x2B424F46)
#define OVP_ClassId_BoxAlgorithm_LuaStimulator OpenViBE::CIdentifier(0x0B5A2787, 0x02750621)
#define OVP_ClassId_BoxAlgorithm_LuaStimulatorDesc OpenViBE::CIdentifier(0x67AF36F3, 0x2B424F46)
#define OVP_ClassId_BoxAlgorithm_Setting_Delay_Seconds OpenViBE::CIdentifier(0x646836F3, 0x2A5624F46)
namespace OpenViBEPlugins
{
......@@ -58,6 +64,7 @@ namespace OpenViBEPlugins
virtual OpenViBE::boolean getOutputCountCB(OpenViBE::uint32& rui64Count);
virtual OpenViBE::boolean getSettingCountCB(OpenViBE::uint32& rui64Count);
virtual OpenViBE::boolean getSettingCB(OpenViBE::uint32 ui32SettingIndex, OpenViBE::CString& rsSetting);
virtual OpenViBE::boolean getSettingCB(const OpenViBE::CString& rsName, OpenViBE::CString& rsSetting);
virtual OpenViBE::boolean getConfigCB(const OpenViBE::CString& rsString, OpenViBE::CString& rsConfig);
virtual OpenViBE::boolean getCurrentTimeCB(OpenViBE::uint64& rui64Time);
......@@ -162,12 +169,18 @@ namespace OpenViBEPlugins
virtual OpenViBE::Plugins::IBoxListener* createBoxListener(void) const { return new CBoxAlgorithmLuaStimulatorListener; }
virtual void releaseBoxListener(OpenViBE::Plugins::IBoxListener* pBoxListener) const { delete pBoxListener; }
virtual bool hasFunctionality(OpenViBE::CIdentifier functionalityIdentifier) const
{
return functionalityIdentifier == OVD_Functionality_Visualization;
}
virtual OpenViBE::boolean getBoxPrototype(
OpenViBE::Kernel::IBoxProto& rBoxAlgorithmPrototype) const
{
rBoxAlgorithmPrototype.addOutput ("Stimulations", OV_TypeId_Stimulations);
rBoxAlgorithmPrototype.addSetting("Lua Script", OV_TypeId_Script, "");
rBoxAlgorithmPrototype.addSetting("delay(s)", OV_TypeId_String, "0", false, OVP_ClassId_BoxAlgorithm_Setting_Delay_Seconds);
rBoxAlgorithmPrototype.addFlag (OpenViBE::Kernel::BoxFlag_CanAddOutput);
rBoxAlgorithmPrototype.addFlag (OpenViBE::Kernel::BoxFlag_CanAddInput);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment