Skip to content

Commit

Permalink
COR-5053: update unity plugin because setupProfile changed
Browse files Browse the repository at this point in the history
  • Loading branch information
tungntEmotiv authored and thamha-emotiv committed Oct 12, 2023
1 parent e00fda7 commit 6dddea6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
11 changes: 7 additions & 4 deletions Src/BCITraining.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void QueryProfile()
/// </summary>
public void CreateProfile(string profileName)
{
_trainingHandler.CreateProfile(profileName);
_trainingHandler.CreateProfile(profileName, _workingHeadsetId);
}

/// <summary>
Expand Down Expand Up @@ -250,7 +250,7 @@ private void OnQueryProfileOK(object sender, List<string> profiles)
if (!string.IsNullOrEmpty(_wantedProfileName))
{
// create new profile
_trainingHandler.CreateProfile(_wantedProfileName);
_trainingHandler.CreateProfile(_wantedProfileName, _workingHeadsetId);
}
}
else
Expand All @@ -262,20 +262,23 @@ private void OnQueryProfileOK(object sender, List<string> profiles)
}
bool foundProfile = false;

UnityEngine.Debug.Log("OnQueryProfileOK: number of profiles " +_profileLists.Count.ToString());

foreach (var profileName in _profileLists)
{
UnityEngine.Debug.Log("OnQueryProfileOK " + profileName + ", wantedProfile: " + _wantedProfileName);
if (_wantedProfileName == profileName)
{
UnityEngine.Debug.Log("OnQueryProfileOK: the profile" + _wantedProfileName + " is existed.");
foundProfile = true;
// get current profile
_trainingHandler.GetCurrentProfile(_workingHeadsetId);
return;
}
}
if (!foundProfile)
{
// create new profile
_trainingHandler.CreateProfile(_wantedProfileName);
_trainingHandler.CreateProfile(_wantedProfileName, _workingHeadsetId);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Src/CortexClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ private void HandleWarning(int code, JToken messageData)
string message = messageData["behavior"].ToString();
HeadsetConnectNotify(this, new HeadsetConnectEventArgs(false, message, headsetId));
}
else if (code == WarningCode.CortexAutoUnloadProfile)
{
// the current profile is unloaded automatically
UnloadProfileDone(this, true);
}
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Src/DataStreamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private DataStreamManager()
}
public static DataStreamManager Instance { get; } = new DataStreamManager();
public bool IsDataBufferUsing { get => _isDataBufferUsing; set => _isDataBufferUsing = value; }
public bool IsSessionCreated {get => _isSessActivated;}

private void Init()
{
Expand Down
20 changes: 14 additions & 6 deletions Src/EmotivUnityItf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ public class EmotivUnityItf
private DataStreamManager _dsManager = DataStreamManager.Instance;
private BCITraining _bciTraining = BCITraining.Instance;
private RecordManager _recordMgr = RecordManager.Instance;
private CortexClient _ctxClient = CortexClient.Instance;

bool _isAuthorizedOK = false;
bool _isSessionCreated = false;

bool _isRecording = false;

bool _isProfileLoaded = false;
Expand All @@ -33,7 +32,7 @@ public class EmotivUnityItf

public bool IsAuthorizedOK => _isAuthorizedOK;

public bool IsSessionCreated => _isSessionCreated;
public bool IsSessionCreated => _dsManager.IsSessionCreated;

public bool IsProfileLoaded => _isProfileLoaded;

Expand Down Expand Up @@ -99,6 +98,8 @@ public void Init(string clientId, string clientSecret, string appName,

// bci training
_bciTraining.InformLoadUnLoadProfileDone += OnInformLoadUnLoadProfileDone;
// get error message
_ctxClient.ErrorMsgReceived += MessageErrorRecieved;
}

/// <summary>
Expand All @@ -117,7 +118,6 @@ public void Stop()
_dsManager.Stop();
_isAuthorizedOK = false;
_isProfileLoaded = false;
_isSessionCreated = false;
_workingHeadsetId = "";
}

Expand All @@ -138,7 +138,7 @@ public void CreateSessionWithHeadset(string headsetId)
/// </summary>
public void SubscribeData(List<string> streamNameList)
{
if (_isSessionCreated)
if (_dsManager.IsSessionCreated)
_dsManager.SubscribeMoreData(streamNameList);
else
UnityEngine.Debug.LogWarning("Please wait session created successfully before subscribe data ");
Expand Down Expand Up @@ -462,7 +462,6 @@ private void OnLicenseValidTo(object sender, DateTime validTo)

private void OnSessionActiveOK(object sender, string headsetId)
{
_isSessionCreated = true;
_workingHeadsetId = headsetId;
_messageLog = "A session working with " + headsetId + " is activated successfully.";
}
Expand Down Expand Up @@ -592,5 +591,14 @@ private void OnFacialExpReceived(object sender, FacEventArgs data)
UnityEngine.Debug.Log(dataText);
}

private void MessageErrorRecieved(object sender, ErrorMsgEventArgs errorInfo)
{
string message = errorInfo.MessageError;
string method = errorInfo.MethodName;
int errorCode = errorInfo.Code;

_messageLog = "Get Error: errorCode " + errorCode.ToString() + ", message: " + message + ", API: " + method;
}

}
}
4 changes: 2 additions & 2 deletions Src/TrainingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ public void DoTraining(string action, string status, string detection)
_ctxClient.Training(cortexToken, sessionId, status, detection, action);
}

public void CreateProfile(string profileName)
public void CreateProfile(string profileName, string headsetId)
{
string cortexToken = _authorizer.CortexToken;
_ctxClient.SetupProfile(cortexToken, profileName, "create");
_ctxClient.SetupProfile(cortexToken, profileName, "create", headsetId);
}

public void LoadProfile(string profileName, string headsetId)
Expand Down

0 comments on commit 6dddea6

Please sign in to comment.