MNE-CPP  beta 1.0
dummytoolbox.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "dummytoolbox.h"
43 
44 
45 //*************************************************************************************************************
46 //=============================================================================================================
47 // QT INCLUDES
48 //=============================================================================================================
49 
50 #include <QtCore/QtPlugin>
51 #include <QDebug>
52 
53 
54 //*************************************************************************************************************
55 //=============================================================================================================
56 // USED NAMESPACES
57 //=============================================================================================================
58 
59 using namespace DummyToolboxPlugin;
60 using namespace MNEX;
61 using namespace XMEASLIB;
62 
63 
64 //*************************************************************************************************************
65 //=============================================================================================================
66 // DEFINE MEMBER METHODS
67 //=============================================================================================================
68 
69 DummyToolbox::DummyToolbox()
70 : m_bIsRunning(false)
71 , m_pDummyInput(NULL)
72 , m_pDummyOutput(NULL)
73 , m_pDummyBuffer(new dBuffer(1024))
74 {
75 }
76 
77 
78 //*************************************************************************************************************
79 
80 DummyToolbox::~DummyToolbox()
81 {
82  if(this->isRunning())
83  stop();
84 }
85 
86 
87 //*************************************************************************************************************
88 
89 QSharedPointer<IPlugin> DummyToolbox::clone() const
90 {
91  QSharedPointer<DummyToolbox> pDummyToolboxClone(new DummyToolbox);
92  return pDummyToolboxClone;
93 }
94 
95 
96 //*************************************************************************************************************
97 //=============================================================================================================
98 // Creating required display instances and set configurations
99 //=============================================================================================================
100 
101 void DummyToolbox::init()
102 {
103  // Input
104  m_pDummyInput = PluginInputData<NewRealTimeSampleArray>::create(this, "DummyIn", "Dummy input data");
105  connect(m_pDummyInput.data(), &PluginInputConnector::notify, this, &DummyToolbox::update, Qt::DirectConnection);
106  m_inputConnectors.append(m_pDummyInput);
107 
108  // Output
109  m_pDummyOutput = PluginOutputData<NewRealTimeSampleArray>::create(this, "DummyOut", "Dummy output data");
110  m_outputConnectors.append(m_pDummyOutput);
111 
112  m_pDummyOutput->data()->setName("Dummy Output");
113  m_pDummyOutput->data()->setUnit("mV");
114  m_pDummyOutput->data()->setMinValue(-200);
115  m_pDummyOutput->data()->setMaxValue(360);
116  m_pDummyOutput->data()->setSamplingRate(256.0/1.0);
117 }
118 
119 
120 //*************************************************************************************************************
121 
122 void DummyToolbox::unload()
123 {
124 
125 }
126 
127 
128 //*************************************************************************************************************
129 
130 bool DummyToolbox::start()
131 {
132  //Check if the thread is already or still running. This can happen if the start button is pressed immediately after the stop button was pressed. In this case the stopping process is not finished yet but the start process is initiated.
133  if(this->isRunning())
134  QThread::wait();
135 
136  m_bIsRunning = true;
137  QThread::start();
138  return true;
139 }
140 
141 
142 //*************************************************************************************************************
143 
144 bool DummyToolbox::stop()
145 {
146  m_bIsRunning = false;
147 
148  m_pDummyBuffer->releaseFromPop();
149  m_pDummyBuffer->releaseFromPush();
150 
151  m_pDummyBuffer->clear();
152 
153  return true;
154 }
155 
156 
157 //*************************************************************************************************************
158 
159 IPlugin::PluginType DummyToolbox::getType() const
160 {
161  return _IAlgorithm;
162 }
163 
164 
165 //*************************************************************************************************************
166 
167 QString DummyToolbox::getName() const
168 {
169  return "Dummy Toolbox";
170 }
171 
172 
173 //*************************************************************************************************************
174 
175 QWidget* DummyToolbox::setupWidget()
176 {
177  DummySetupWidget* setupWidget = new DummySetupWidget(this);//widget is later distroyed by CentralWidget - so it has to be created everytime new
178  return setupWidget;
179 }
180 
181 
182 //*************************************************************************************************************
183 
184 void DummyToolbox::update(XMEASLIB::NewMeasurement::SPtr pMeasurement)
185 {
186  QSharedPointer<NewRealTimeSampleArray> pRTSA = pMeasurement.dynamicCast<NewRealTimeSampleArray>();
187 
188  if(pRTSA)
189  {
190  for(unsigned char i = 0; i < pRTSA->getArraySize(); ++i)
191  {
192  double value = pRTSA->getSampleArray()[i];
193  m_pDummyBuffer->push(value);
194  }
195  }
196 }
197 
198 
199 
200 //*************************************************************************************************************
201 
202 void DummyToolbox::run()
203 {
204  while(m_bIsRunning)
205  {
206  /* Dispatch the inputs */
207  double v = m_pDummyBuffer->pop();
208 
209  //ToDo: Implement your algorithm here
210 
211  m_pDummyOutput->data()->setValue(v);
212  }
213 }
214 
The DummyToolbox class provides a dummy algorithm structure.
Definition: dummytoolbox.h:91
Contains the declaration of the DummySetupWidget class.
The DummySetupWidget class provides the DummyToolbox configuration window.
Definition: arrow.h:75
Contains the declaration of the DummyToolbox class.
PluginOutputConnector with specified Measurement.
QSharedPointer< NewMeasurement > SPtr
const QVector< double > & getSampleArray()
The NewRealTimeSampleArray class is the base class of every NewRealTimeSampleArray Measurement...