@@ -88,6 +88,7 @@ BabyMEG::BabyMEG()
8888, m_sFiffProjections(QCoreApplication::applicationDirPath() + "/../resources/mne_scan/plugins/babymeg/header.fif")
8989, m_sFiffCompensators(QCoreApplication::applicationDirPath() + "/../resources/mne_scan/plugins/babymeg/compensator.fif")
9090, m_sBadChannels(QCoreApplication::applicationDirPath() + "/../resources/mne_scan/plugins/babymeg/both.bad")
91+ , m_bProcessOutput(false )
9192{
9293 m_pActionSqdCtrl = new QAction (QIcon (" :/images/sqdctrl.png" ), tr (" Squid Control" ),this );
9394// m_pActionSetupProject->setShortcut(tr("F12"));
@@ -107,7 +108,7 @@ BabyMEG::BabyMEG()
107108
108109BabyMEG::~BabyMEG ()
109110{
110- if (this -> isRunning () ) {
111+ if (m_bProcessOutput ) {
111112 stop ();
112113 }
113114
@@ -208,7 +209,8 @@ bool BabyMEG::start()
208209 initConnector ();
209210
210211 // Start thread
211- QThread::start ();
212+ m_bProcessOutput = true ;
213+ m_OutputProcessingThread = std::thread (&BabyMEG::run, this );
212214
213215 return true ;
214216}
@@ -217,8 +219,11 @@ bool BabyMEG::start()
217219
218220bool BabyMEG::stop ()
219221{
220- requestInterruption ();
221- wait (2000 );
222+ m_bProcessOutput = false ;
223+
224+ if (m_OutputProcessingThread.joinable ()){
225+ m_OutputProcessingThread.join ();
226+ }
222227
223228 // Clear all data in the buffer connected to displays and other plugins
224229 m_pRTMSABabyMEG->measurementData ()->clear ();
@@ -260,13 +265,13 @@ void BabyMEG::run()
260265{
261266 MatrixXf matValue;
262267
263- while (! isInterruptionRequested () ) {
268+ while (m_bProcessOutput ) {
264269 // pop matrix
265270 if (m_pCircularBuffer->pop (matValue)) {
266271 // Create digital trigger information
267272 createDigTrig (matValue);
268273
269- if (! isInterruptionRequested () ) {
274+ if (m_bProcessOutput ) {
270275 m_pRTMSABabyMEG->measurementData ()->setValue (this ->calibrate (matValue));
271276 }
272277 }
@@ -352,7 +357,7 @@ void BabyMEG::setFiffData(QByteArray data)
352357 IOUtils::swap_floatp (rawData.data ()+i);
353358 }
354359
355- if (this -> isRunning () ) {
360+ if (m_bProcessOutput ) {
356361 while (!m_pCircularBuffer->push (rawData)) {
357362 // Do nothing until the circular buffer is ready to accept new data again
358363 }
0 commit comments