Created
June 28, 2016 19:46
-
-
Save mgerlach-klick/d04c1dc9f9be79ed31268133f79e7e03 to your computer and use it in GitHub Desktop.
community sdk / averagebandpowers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.emotiv.examples.AverageBandPowers; | |
import com.emotiv.Iedk.*; | |
import com.sun.jna.Pointer; | |
import com.sun.jna.ptr.*; | |
public class AverageBandPowers { | |
public static void main(String[] args) { | |
Pointer eEvent = Edk.INSTANCE.IEE_EmoEngineEventCreate(); | |
Pointer eState = Edk.INSTANCE.IEE_EmoStateCreate(); | |
IntByReference userID = null; | |
boolean ready = false; | |
int state = 0; | |
Edk.IEE_DataChannels_t dataChannel; | |
userID = new IntByReference(0); | |
if (Edk.INSTANCE.IEE_EngineRemoteConnect("127.0.0.1", (short) 3008, "Emotiv Systems-5") != EdkErrorCode.EDK_OK.ToInt()) { | |
System.out.println("Emotiv Engine start up failed."); | |
System.out.println("Reason:" + Edk.INSTANCE.IEE_EngineRemoteConnect("127.0.0.1", (short) 3008, "Emotiv Systems-5")); | |
System.out.println("we wanted:" + EdkErrorCode.EDK_OK.ToInt()); | |
return; | |
} | |
System.out.println("Start receiving Data!"); | |
System.out.println("Theta, Alpha, Low_beta, High_beta, Gamma"); | |
while (true) { | |
state = Edk.INSTANCE.IEE_EngineGetNextEvent(eEvent); | |
// System.out.println("state:" + state); | |
// System.out.println("we need:" + EdkErrorCode.EDK_OK.ToInt()); | |
// New event needs to be handled | |
if (state == EdkErrorCode.EDK_OK.ToInt()) { | |
int eventType = Edk.INSTANCE.IEE_EmoEngineEventGetType(eEvent); | |
Edk.INSTANCE.IEE_EmoEngineEventGetUserId(eEvent, userID); | |
// System.out.println("Event type:" + eventType); | |
// Log the EmoState if it has been updated | |
if (eventType == Edk.IEE_Event_t.IEE_UserAdded.ToInt()) | |
if (userID != null) { | |
System.out.println("User added"); | |
System.out.println("User:"+userID.getValue()); | |
ready = true; | |
} | |
} else if (state != EdkErrorCode.EDK_NO_EVENT.ToInt()) { | |
System.out.println("Internal error in Emotiv Engine!"); | |
break; | |
} | |
if (ready) { | |
DoubleByReference alpha = new DoubleByReference(0); | |
DoubleByReference low_beta = new DoubleByReference(0); | |
DoubleByReference high_beta = new DoubleByReference(0); | |
DoubleByReference gamma = new DoubleByReference(0); | |
DoubleByReference theta = new DoubleByReference(0); | |
for(int i = 0 ; i < 17 ; i++) | |
{ | |
System.out.println("Sensor: "+i); | |
int result = Edk.INSTANCE.IEE_GetAverageBandPowers(userID.getValue(), i, theta, alpha, low_beta, high_beta, gamma); | |
if(result == EdkErrorCode.EDK_OK.ToInt()){ | |
System.out.print(theta.getValue()); System.out.print(", "); | |
System.out.print(alpha.getValue()); System.out.print(", "); | |
System.out.print(low_beta.getValue()); System.out.print(", "); | |
System.out.print(high_beta.getValue()); System.out.print(", "); | |
System.out.print(gamma.getValue()); System.out.print(", "); | |
} else { | |
System.out.println("Error: "+result); | |
} | |
// System.out.println(); | |
} | |
} | |
} | |
Edk.INSTANCE.IEE_EngineDisconnect(); | |
Edk.INSTANCE.IEE_EmoStateFree(eState); | |
Edk.INSTANCE.IEE_EmoEngineEventFree(eEvent); | |
System.out.println("Disconnected!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi,
Could i know if you are using unity to connect your Epoc+ or insight?
We have an issue about the variable state in your case give me 512 convert to hexadecimal value is 0x0200. (EDK_CANNOT_ACQUIRE_DATA).
Greeting from Spain