from ctypes import *
from brainaccess.sdk import ba_sdk
from brainaccess.utilities import *
sdk = ba_sdk.get_sdk()
# API
sdk.baSDK_initializeSSVEPDetector.restype = c_int
[docs]def initialize(channel_indices, ssvep_frequencies):
"""
Initializes SSVEP Detector's internal structures, intializes BrainAccess Core library and attempts to connect to BrainAccess EEG hardware.
Args:
``channel_indices`` (**list[int]**): indices of channels that should be used by the algorithm. Electrodes should be placed in oxipital region (we suggest O1, O2, Oz).
``ssvep_frequencies`` (**list[float]**): flicker frequencies that are provided as visual stimuli for the user.
For best results, frequencies should be roughly in 8 - 15Hz range and distance between them should be at least 1Hz.
Each frequency is associated with a class that the algorithm later predicts.
Returns:
``bool``: True if successful, False on error.
"""
ch_ptr = python_array_to_ctype(channel_indices, c_int)
ssvep_ptr = python_array_to_ctype(ssvep_frequencies, c_double)
if sdk.baSDK_initializeSSVEPDetector(ch_ptr, len(channel_indices), ssvep_ptr, len(ssvep_frequencies)) != 0:
print("SSVEP Detector could not be initialized")
return False
return True
sdk.baSDK_startSSVEPDetector.restype = c_int
[docs]def start():
"""
Starts EEG data collection
Should be called before :meth:`brainaccess.sdk.ssvep_detector.predict`
Returns:
``bool``: True if successful, False on error.
"""
return sdk.baSDK_startSSVEPDetector() == 0
sdk.baSDK_stopSSVEPDetector.restype = c_int
[docs]def stop():
"""
Stop EEG data collection
Should be called when SSVEP Detector is no longer needed.
Returns:
``bool``: True if successful, False on error.
"""
return sdk.baSDK_stopSSVEPDetector() == 0
sdk.baSDK_predictSSVEP.restype = c_int
[docs]def predict():
"""
Predicts class (frequency) on which user is concentrated.
Note that EEG data does not instantly reflect the flicker frequencies once the user switches focus to it.
Rather, it takes a few seconds for it to happen.
Returns:
``int``: Predicted class index or -1 if an error occured.
Class indices correspond to frequencies provided in :meth:`brainaccess.sdk.ssvep_detector.initialize` (using the same ordering as was provided).
"""
return sdk.baSDK_predictSSVEP()