Data Subscription
List of methods related to data stream subscription available in the base Cortex class
A data stream is a continuous flow of information specific to a session that you have opened with a headset. In this implementation, the data stream is split into two main chunks:
Mental Commands
Mental commands are blocks of Information about what category of imagined activity the current headset data has been categorized to, and at which strength (0.0 - 1.0). This stream is updated several times a second and can be used as an input by treating each action other than neutral as a button press. Action names are constrained to the set of Mental Command Names, and only four can be active for detection at once.
public class MentalCommand
{
    public double timestamp;
    public string action;
    public double power;
}Device Info
Device info contains information about battery level, signal and contact quality for a device. It is important to display this when fitting a headset, ideally showing the nodes visually so that they can be adjusted live. Contact quality is provided according to the 10-10 System.
public class DeviceInfo
{
    public List<string> cqHeaders;
    public DiCtionary<Channel_t, float> contactQuality;
    public float battery;
    public float cqOverall;
    public float signalStrength;
}Data Stream Exists
Returns true if a data stream currently exists for the headset, used to check if a headset is already in use.
bool DataStreamExists(string headsetId);headsetId
id code of the target headset
Subscribe Mental Commands
Subscribe to mental commands received through the data stream for a specified headset. Returns true if subscription was successful.
bool SubscribeMentalCommands(string headsetId, Action<MentalCommand> action);headsetId
id code of the target headset
action
action to call when new data is received, can be a method or delegate
Example:
using UnityEngine;
using CortexPlugin;
public class MentalCommandStreamPrinter: MonoBehavior
{
    void Start()
    {
        Cortex.DataStreamStarted += OnDataStreamStarted;
    }
    
    void OnDataStreamStarted(string headsetId)
    {
        Cortex.SubscribeMentalCommands(headsetId, OnMentalCommandReceived);
    }
    
    void OnMentalCommandReceived(MentalCommand mentalCommand)
    {
        Debug.Log("Mental command received: " + mentalCommand);
    }
}Unsubscribe Mental Commands
Unsubscribe from data stream mental commands. Returns true if successful.
bool UnsubscribeMentalCommands(string headsetId, Action<MentalCommand> action);Subscribe Device Info
Subscribe to device info received through the data stream of a specified headset. Device info includes battery level and contact quality for the headset. Returns true if subscription was successful.
bool SubscribeDeviceInfo(string headsetId, Action<DeviceInfo> action);headsetId
id code of the target headset
action
action to call when new data is received, can be a method or delegate
Unsubscribe Device Info
Unsubscribe from data stream device info. Returns true if successful.
bool UnsubscribeDeviceinfo(string headsetId, Action<DeviceInfo> action);Subscribe System Events
It is recommended that developers use the explicit event equivalents provided in the training handler
Subscribe to system events through the data stream of a specifies headset. These events are related to the training of mental commands and also provided as events in the training handler. They are included here due to the structure of the base API. Returns true if subscription was successful.
bool SubscribeSystemEvents(string headsetId, Action<SysEventArgs> action);headsetId
id code of the target headset
action
action to call when new data is received, can be a method or delegate
Possible system events: https://emotiv.gitbook.io/cortex-api/bci/getdetectioninfo#mental-command
- Started - training has started successfully 
- Succeeded - training has been successfully completed, must accept or reject 
- Failed - training has failed, often due to lack of signal or contact quality 
- Completed - training was started, succeeded, and then accepted 
- Data Erased 
- Rejected - training sample was successfully rejected 
- Reset - training samples for an action were successfully reset 
- Auto Sampling Neutral Completed 
- Signature Updated 
Unsubscribe System Events
Unsubscribe from data stream system events. Return true if successful.
bool UnsubscribeSystemEvents(string headsetId, Action<SysEventArgs> action);Last updated
