Ejemplo n.º 1
0
        static void SavingLoadingFunction(int mode)
        {
            int getNumberProfile = EmotivCloudClient.EC_GetAllProfileName(userCloudID);

            if (mode == 0)
            {
                int profileID = EmotivCloudClient.EC_GetProfileId(userCloudID, profileName);

                if (profileID >= 0)
                {
                    Console.WriteLine("Profile with " + profileName + " is existed");
                    Console.WriteLine("Updating....");
                    if (EmotivCloudClient.EC_UpdateUserProfile(userCloudID, 0, profileID) == EmotivCloudClient.EC_OK)
                    {
                        Console.WriteLine("Updating finished");
                    }
                    else
                    {
                        Console.WriteLine("Updating failed");
                    }
                }
                else
                {
                    Console.WriteLine("Saving...");

                    if (EmotivCloudClient.EC_SaveUserProfile(userCloudID, (int)0, profileName,
                                                             EmotivCloudClient.profileFileType.TRAINING) == EmotivCloudClient.EC_OK)
                    {
                        Console.WriteLine("Saving finished");
                    }
                    else
                    {
                        Console.WriteLine("Saving failed");
                    }
                }

                return;
            }
            if (mode == 1)
            {
                if (getNumberProfile > 0)
                {
                    Console.WriteLine("Loading...");

                    if (EmotivCloudClient.EC_LoadUserProfile(userCloudID, 0,
                                                             EmotivCloudClient.EC_GetProfileId(userCloudID, profileName), version) == EmotivCloudClient.EC_OK)
                    {
                        Console.WriteLine("Loading finished");
                    }
                    else
                    {
                        Console.WriteLine("Loading failed");
                    }
                }

                return;
            }
        }
Ejemplo n.º 2
0
    void loginWindow(int id)
    {
        GUI.Label(new Rect(10, 20, 100, 30), "User Name");
        username = GUI.TextField(new Rect(10, 40, 180, 30), username);
        GUI.Label(new Rect(10, 90, 100, 30), "Password");
        password = GUI.PasswordField(new Rect(10, 110, 180, 30), password, '*');
        if (GUI.Button(new Rect(10, 150, 80, 30), "Cancel"))
        {
            isLogin = false;
        }
        if (GUI.Button(new Rect(100, 150, 80, 30), "Login"))
        {
            int connect_result = EmotivCloudClient.EC_Connect();
            if (connect_result == EmotivCloudClient.EC_OK)
            {
                var login_result = EmotivCloudClient.EC_Login(username, password);
                if (login_result == EmotivCloudClient.EC_OK)
                {
                    Debug.Log("login success");
                    EmotivCloudClient.EC_GetUserDetail(ref userCloudId);
                    Debug.Log("user cloud id: " + userCloudId.ToString());
                    nProfile = EmotivCloudClient.EC_GetAllProfileName(userCloudId);
                    Debug.Log("number profiles: " + nProfile.ToString());
                    profiles = new List <PROFILE>();
                    for (var i = 0; i < nProfile; i++)
                    {
                        //Debug.Log("delete profile: ");
                        //var _id = EmotivCloudClient.EC_ProfileIDAtIndex(userCloudId, i);
                        //EmotivCloudClient.EC_DeleteUserProfile(userCloudId, _id);

                        int ii = EmotivCloudClient.EC_ProfileIDAtIndex(userCloudId, i);
                        EmotivCloudClient.Plugin_EC_ProfileNameAtIndex(userCloudId, 0);
                        PROFILE t = new PROFILE();
                        t.id   = EmotivCloudClient.EC_ProfileIDAtIndex(userCloudId, i);
                        t.name = EmotivCloudClient.Plugin_EC_ProfileNameAtIndex(userCloudId, i);
                        profiles.Add(t);
                        Debug.Log("profile name: " + profiles[i].name + " profile id: " + profiles[i].id.ToString());
                    }
                    isLogin = false;
                }

                else
                {
                    Debug.Log("cannot login, error: " + login_result.ToString());
                }
            }
            else
            {
                Debug.Log("cannot connect to emotiv cloud, error: " + connect_result.ToString());
            }
        }
        if (userCloudId != -1) //logged in
        {
            if (GUI.Button(new Rect(10, 150, 80, 30), "Load Profile"))
            {
            }
        }
    }
Ejemplo n.º 3
0
        static void SavingLoadingFunction(int mode)
        {
            int getNumberProfile = EmotivCloudClient.EC_GetAllProfileName(userCloudID);

            if (mode == 0)
            {
                int profileID = EmotivCloudClient.EC_GetProfileId(userCloudID, profileName);

                if (profileID >= 0)
                {
                    Console.WriteLine("Profile with " + profileName + " is existed");
                    if (EmotivCloudClient.EC_UpdateUserProfile(userCloudID, engineUserID, profileID, profileName))
                    {
                        Console.WriteLine("Updating finished");
                    }
                    else
                    {
                        Console.WriteLine("Updating failed");
                    }
                }
                else if (EmotivCloudClient.EC_SaveUserProfile(userCloudID, (int)engineUserID, profileName, EmotivCloudClient.profileFileType.TRAINING))
                {
                    Console.WriteLine("Saving finished");
                }
                else
                {
                    Console.WriteLine("Saving failed");
                }

                Thread.Sleep(5000);
                return;
            }
            if (mode == 1)
            {
                if (getNumberProfile > 0)
                {
                    if (EmotivCloudClient.EC_LoadUserProfile(userCloudID, engineUserID, EmotivCloudClient.EC_ProfileIDAtIndex(userCloudID, 0), version))
                    {
                        Console.WriteLine("Loading finished");
                    }
                    else
                    {
                        Console.WriteLine("Loading failed");
                    }
                }

                Thread.Sleep(5000);
                return;
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("===========================================================================");
            Console.WriteLine("Example to saving and loading profile from Emotiv Cloud.");
            Console.WriteLine("===========================================================================");
            Console.WriteLine("Press 'F1' to saving profile to Emotiv Cloud.");
            Console.WriteLine("Press 'F2' to loading profile from Emotiv Cloud.");

            SavingAndLoadingProfileCloud p = new SavingAndLoadingProfileCloud();

            // create the engine
            EmoEngine engine = EmoEngine.Instance;

            engine.UserAdded += new EmoEngine.UserAddedEventHandler(engine_UserAdded_Event);
            engine.Connect();

            ConsoleKeyInfo cki = new ConsoleKeyInfo();

            if (EmotivCloudClient.EC_Connect() != EdkDll.EDK_OK)
            {
                Console.WriteLine("Cannot connect to Emotiv Cloud.");
                Thread.Sleep(2000);
                return;
            }

            if (EmotivCloudClient.EC_Login(userName, password) != EdkDll.EDK_OK)
            {
                Console.WriteLine("Your login attempt has failed. The username or password may be incorrect");
                Thread.Sleep(2000);
                return;
            }

            Console.WriteLine("Logged in as " + userName);

            if (EmotivCloudClient.EC_GetUserDetail(ref cloudUserID) != EdkDll.EDK_OK)
            {
                return;
            }

            // Loading information of all profiles from Cloud to buffer.
            // and return number of profile in the list.
            int getNumberProfile = EmotivCloudClient.EC_GetAllProfileName(cloudUserID);

            while (true)
            {
                engine.ProcessEvents(10);

                if (!Console.KeyAvailable)
                {
                    continue;
                }
                cki = Console.ReadKey(true);

                if (cki.Key == ConsoleKey.F1)
                {
                    if (engineUserID < 0)
                    {
                        Console.WriteLine("No headset is connected.");
                        continue;
                    }

                    // If your profile is new profile. You need call this function
                    // before want to train Mental Command detections.
                    ProfileSaving();
                    break;
                }
                if (cki.Key == ConsoleKey.F2)
                {
                    if (engineUserID < 0)
                    {
                        Console.WriteLine("No headset is connected.");
                        continue;
                    }

                    if (getNumberProfile > 0)
                    {
                        ProfileLoading();
                        break;
                    }
                }
            }

            engine.Disconnect();
        }
Ejemplo n.º 5
0
        protected override bool ConnectionSetUp(out string errorMessage)
        {
            string userName    = this.username;
            string password    = this.password;
            string profileName = this.profileName;

            int state = 0;

            uint engineUserID;
            int  userCloudID;

            engineUserID = 0;
            userCloudID  = -1;

            if (EdkDll.IEE_EngineConnect("Emotiv Systems-5") != EdkDll.EDK_OK)
            {
                errorMessage = "Emotiv Engine start up failed.";
                return(false);
            }

            eEvent = EdkDll.IEE_EmoEngineEventCreate();
            eState = EdkDll.IEE_EmoStateCreate();

            UpdateBatteryLevel();
            UpdateWirelessSigmalStrength();

            if (EmotivCloudClient.EC_Connect() != EmotivCloudClient.EC_OK)
            {
                errorMessage = ("Cannot connect to Emotiv Cloud");
                return(false);
            }

            if (EmotivCloudClient.EC_Login(userName, password) != EmotivCloudClient.EC_OK)
            {
                errorMessage = ("Your login attempt has failed. The username or password may be incorrect");
                return(false);
            }

            //Debug.WriteLine("Logged in as " + userName);

            if (EmotivCloudClient.EC_GetUserDetail(ref userCloudID) != EmotivCloudClient.EC_OK)
            {
                errorMessage = "Unable to get user details";
                return(false);
            }

            state = EdkDll.IEE_EngineGetNextEvent(eEvent);

            if (state == EdkDll.EDK_OK)
            {
                var eventType = EdkDll.IEE_EmoEngineEventGetType(eEvent);
                EdkDll.IEE_EmoEngineEventGetUserId(eEvent, out engineUserID);

                // Log the EmoState if it has been updated
                if (eventType == EdkDll.IEE_Event_t.IEE_UserAdded)
                {
                    //Debug.WriteLine("User added");
                }
            }
            else if (state != EdkDll.EDK_NO_EVENT)
            {
                errorMessage = ("Internal error in Emotiv Engine!");
                return(false);
            }

            //Debug.WriteLine("userCloudID: " + userCloudID);
            //Debug.WriteLine("userEngineID: " + engineUserID);

            int version          = -1; // Lastest version
            int getNumberProfile = EmotivCloudClient.EC_GetAllProfileName(userCloudID);

            //Debug.WriteLine(getNumberProfile);

            if (getNumberProfile > 0)
            {
                int profileID = EmotivCloudClient.EC_GetProfileId(userCloudID, profileName);
                //Debug.WriteLine(profileID);
                if (EmotivCloudClient.EC_LoadUserProfile(userCloudID, (int)engineUserID, profileID, version) == EmotivCloudClient.EC_OK)
                {
                    // Debug.WriteLine("Loading finished" + EmotivCloudClient.EC_GetAllProfileName(userCloudID));
                }
                else
                {
                    errorMessage = ("Loading failed: either USB not connected or profile  \'" + profileName + "\' doesn't exist");
                    EmotivCloudClient.EC_Logout(userCloudID);
                    return(false);
                }
            }

            uint pTrainedActionsOut = 0;

            EdkDll.IEE_MentalCommandGetTrainedSignatureActions(engineUserID, out pTrainedActionsOut);
            //Debug.WriteLine("Current overall trained actions: " + pTrainedActionsOut);

            float skill = -1;

            EdkDll.IEE_MentalCommandGetOverallSkillRating(engineUserID, out skill);
            //Debug.WriteLine("Current overall skill rating: " + skill);

            errorMessage = "Profile " + profileName + " was loaded and device connected!";

            return(true);
        }