60 : m_pEEGoSportsProducer(pEEGoSportsProducer)
62 , m_bInitDeviceSuccess(false)
63 , m_uiNumberOfChannels(64)
64 , m_uiSamplingFrequency(1024)
65 , m_bUseChExponent(false)
66 , m_bWriteDriverDebugToFile(false)
67 , m_sOutputFilePath(
"/mne_x_plugins/resources/eegosports")
68 , m_bMeasureImpedances(false)
74 #ifdef TAKE_EEGOSPORTSSDK_DLL //32 bit system & 64 bit (with 64 bit compiler)
75 m_oLibHandle = ::LoadLibrary(L
"C:\\Windows\\System32\\eego.dll");
76 #elif TAKE_EEGOSPORTSSDK_32_DLL //64 bit (with 32 bit compiler)
77 m_oLibHandle = ::LoadLibrary(L
"C:\\Windows\\SysWOW64\\eego.dll");
81 if( m_oLibHandle == NULL)
83 cout <<
"Plugin EEGoSports - ERROR - Couldn't load DLL - Check if the driver for the TMSi USB Fiber Connector installed in the system dir" << endl;
89 __load_dll_func__(m_oFpCreateAmplifier, CREATEAMPLIFIER,
"CreateAmplifier");
91 cout <<
"Plugin EEGoSports - INFO - EEGoSportsDriver() - Successfully loaded all DLL functions" << endl;
106 int iSamplingFrequency,
108 bool bWriteDriverDebugToFile,
109 QString sOutpuFilePath,
110 bool bMeasureImpedance)
117 m_uiNumberOfChannels = iNumberOfChannels;
118 m_uiSamplingFrequency = iSamplingFrequency;
119 m_bUseChExponent = bUseChExponent;
120 m_bWriteDriverDebugToFile = bWriteDriverDebugToFile;
121 m_sOutputFilePath = sOutpuFilePath;
122 m_bMeasureImpedances = bMeasureImpedance;
125 if(m_bWriteDriverDebugToFile)
126 m_outputFileStream.open(
"mne_x_plugins/resources/eegosports/EEGoSports_Driver_Debug.txt", ios::trunc);
129 HRESULT hres = (*m_oFpCreateAmplifier)(&m_pAmplifier);
130 if(FAILED(hres) || !m_pAmplifier)
132 cout <<
"Plugin EEGoSports - ERROR - Couldn't create amplifier! HRESULT: " << hres << endl;
138 LPTSTR szDevString = NULL;
142 if(FAILED(m_pAmplifier->EnumDevices(&numDevices)))
144 cout <<
"Plugin EEGoSports - ERROR - Couldn't get device numbers!" << endl;
149 for(UINT i = 0; i < numDevices; i++)
152 if(FAILED(m_pAmplifier->EnumDevices(i, &szName)))
154 cout <<
"Plugin EEGoSports - ERROR - Couldn't get device name!" << endl;
160 temp = temp.fromWCharArray(szName);
161 if(!temp.contains(
"SIM"))
163 szDevString = szName;
172 cout <<
"Plugin EEGoSports - ERROR - No connected device found!" << endl;
179 if( FAILED(m_pAmplifier->Connect(szDevString)))
181 cout <<
"Plugin EEGoSports - ERROR - Connect call failed!" << endl;
189 m_pAmplifier->Reset();
197 conf.BITS.bUnlockOCP = 1;
198 m_pAmplifier->SetConfig(conf);
204 if(FAILED(m_pAmplifier->SetSamplingRate((EEGO_RATE)m_uiSamplingFrequency)))
206 cout <<
"Plugin EEGoSports - ERROR - Can not set sampling frequency: " << m_uiSamplingFrequency << endl;
211 EEGO_GAIN gain = GetGainForSignalRange(1000);
214 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_A);
215 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_B);
216 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_C);
217 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_D);
218 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_E);
219 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_F);
220 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_G);
221 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_H);
222 m_pAmplifier->SetSignalGain(gain, EEGO_ADC_S);
227 hr = m_pAmplifier->SetDriverAmplitude(0);
228 hr |= m_pAmplifier->SetDriverPeriod(0);
237 USHORT firmwareVersion;
238 m_pAmplifier->GetFirmwareVersion(&firmwareVersion);
249 m_pAmplifier->GetSamplingRate(&rate);
250 m_pAmplifier->GetSignalGain(&gain, EEGO_ADC_A);
252 cout <<
"Starting Device with sampling rate: " << rate <<
"hz and a gain of: " << gain <<
"\n";
255 if(FAILED(m_pAmplifier->SetMode(EEGO_MODE_IDLE)))
259 if(FAILED(m_pAmplifier->SetMode(EEGO_MODE_STREAMING)))
264 cout <<
"Plugin EEGoSports - INFO - initDevice() - Successfully initialised the device. Starting Device with sampling rate: " << rate <<
"hz and a gain of: " << gain << endl;
267 m_bInitDeviceSuccess =
true;
278 if(!m_bInitDeviceSuccess)
280 cout <<
"Plugin EEGoSports - ERROR - uninitDevice() - Device was not initialised - therefore can not be uninitialised" << endl;
287 cout <<
"Plugin EEGoSports - ERROR - uninitDevice() - Driver DLL was not loaded" << endl;
292 if(m_outputFileStream.is_open() && m_bWriteDriverDebugToFile)
294 m_outputFileStream.close();
295 m_outputFileStream.clear();
303 if(FAILED(m_pAmplifier->SetMode(EEGO_MODE_IDLE)))
307 m_pAmplifier->Disconnect();
308 m_pAmplifier->Release();
313 cout <<
"Plugin EEGoSports - INFO - uninitDevice() - Successfully uninitialised the device" << endl;
323 if(!m_bInitDeviceSuccess)
325 cout <<
"Plugin EEGoSports - ERROR - getSampleMatrixValue() - Cannot start to get samples from device because device was not initialised correctly" << endl;
334 m_pAmplifier->GetData(&pBuffer);
337 m_uiNumberOfAvailableChannels = pBuffer->GetChannelCount();
338 int ulNumSamplesReceived = pBuffer->GetSampleCount();
341 if(ulNumSamplesReceived>0)
344 if(m_uiNumberOfAvailableChannels < m_uiNumberOfChannels)
345 channelMax = m_uiNumberOfAvailableChannels;
347 channelMax = m_uiNumberOfChannels;
349 sampleMatrix = MatrixXf (channelMax, ulNumSamplesReceived);
352 for(
int sample = 0; sample < ulNumSamplesReceived; sample++)
353 for(
int channel = 0; channel < channelMax; channel++)
354 sampleMatrix(channel, sample) = m_bUseChExponent ? pBuffer->GetBuffer(channel, sample) * 1e-6 : pBuffer->GetBuffer(channel, sample);
360 if(m_outputFileStream.is_open() && m_bWriteDriverDebugToFile)
361 m_outputFileStream <<
"ulNumSamplesReceived: " << ulNumSamplesReceived << endl;
366 if(m_outputFileStream.is_open() && m_bWriteDriverDebugToFile)
367 m_outputFileStream <<
"ulNumSamplesReceived: " << ulNumSamplesReceived << endl;
522 EEGoSportsPlugin::EEGO_GAIN EEGoSportsDriver::GetGainForSignalRange(
int range)
526 double idealGain = 1800. / range;
529 if(EEGO_GAIN_1X <= idealGain && realGain <= EEGO_GAIN_1X)
530 realGain = EEGO_GAIN_1X;
532 if(EEGO_GAIN_2X <= idealGain && realGain <= EEGO_GAIN_2X)
533 realGain = EEGO_GAIN_2X;
535 if(EEGO_GAIN_3X <= idealGain && realGain <= EEGO_GAIN_3X)
536 realGain = EEGO_GAIN_3X;
538 if(EEGO_GAIN_4X <= idealGain && realGain <= EEGO_GAIN_4X)
539 realGain = EEGO_GAIN_4X;
541 if(EEGO_GAIN_6X <= idealGain && realGain <= EEGO_GAIN_6X)
542 realGain = EEGO_GAIN_6X;
544 if(EEGO_GAIN_8X <= idealGain && realGain <= EEGO_GAIN_8X)
545 realGain = EEGO_GAIN_8X;
547 if(EEGO_GAIN_12X <= idealGain && realGain <= EEGO_GAIN_12X)
548 realGain = EEGO_GAIN_12X;
550 return (EEGO_GAIN)realGain;
The EEGProducer class provides a EEG data producer for a given sampling rate.
bool getSampleMatrixValue(MatrixXf &sampleMatrix)
bool initDevice(int iNumberOfChannels, int iSamplingFrequency, bool bUseChExponent, bool bWriteDriverDebugToFile, QString sOutpuFilePath, bool bMeasureImpedance)
Contains the declaration of the EEGoSportsDriver class. This class implements the basic communication...
EEGoSportsDriver(EEGoSportsProducer *pEEGoSportsProducer)
Contains the declaration of the EEGoSportsProducer class.