forked from jorenver/LP_Proyecto_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneuroListener.py
129 lines (98 loc) · 4.19 KB
/
neuroListener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# python version >= 2.5
import ctypes
import sys
import os
from ctypes import *
from numpy import *
import time
from ctypes.util import find_library
libEDK = cdll.LoadLibrary(".\\edk.dll")
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------
write = sys.stdout.write
EE_EmoEngineEventCreate = libEDK.EE_EmoEngineEventCreate
EE_EmoEngineEventCreate.restype = c_void_p
eEvent = EE_EmoEngineEventCreate()
EE_EmoEngineEventGetEmoState = libEDK.EE_EmoEngineEventGetEmoState
EE_EmoEngineEventGetEmoState.argtypes=[c_void_p,c_void_p]
EE_EmoEngineEventGetEmoState.restype = c_int
ES_GetTimeFromStart = libEDK.ES_GetTimeFromStart
ES_GetTimeFromStart.argtypes=[ctypes.c_void_p]
ES_GetTimeFromStart.restype = c_float
EE_EmoStateCreate = libEDK.EE_EmoStateCreate
EE_EmoStateCreate.restype = c_void_p
eState=EE_EmoStateCreate()
ES_GetWirelessSignalStatus=libEDK.ES_GetWirelessSignalStatus
ES_GetWirelessSignalStatus.restype = c_int
ES_GetWirelessSignalStatus.argtypes = [c_void_p]
ES_CognitivGetCurrentAction=libEDK.ES_CognitivGetCurrentAction
ES_CognitivGetCurrentAction.restype = c_int
ES_CognitivGetCurrentAction.argtypes= [c_void_p]
ES_CognitivGetCurrentActionPower=libEDK.ES_CognitivGetCurrentActionPower
ES_CognitivGetCurrentActionPower.restype = c_float
ES_CognitivGetCurrentActionPower.argtypes= [c_void_p]
userID = c_uint(0)
user = pointer(userID)
composerPort = c_uint(1726)
timestamp = c_float(0.0)
option = c_int(0)
state = c_int(0)
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------
def logEmoState(userID,eState):
print "informacion\n"
#print ES_GetTimeFromStart(eState),",",
print "id Usuario: ",userID.value,"\n",
#print ES_GetWirelessSignalStatus(eState),",",
#Cognitiv Suite results
print "\t\tAccion Current\n"
print "Accion: ",ES_CognitivGetCurrentAction(eState),"\n"
if(ES_CognitivGetCurrentAction(eState)==0x0020):
izquierda()
if(ES_CognitivGetCurrentAction(eState)==0x0002):
push()
if(ES_CognitivGetCurrentAction(eState)==0x0040):
derecha()
if(ES_CognitivGetCurrentAction(eState)==0x0001):
neutro()
print ES_CognitivGetCurrentActionPower(eState)
print "poder: ",ES_CognitivGetCurrentActionPower(eState),"\n"
print '\n'
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
def izquierda():
print "izquierda\n"
def derecha():
print "derecha\n"
def neutro():
print "neutral\n"
def push():
print "push\n"
#------------------------------------------------------------------------------------------------------------------------------------------------------------
print "Comienza"
#if libEDK.EE_EngineConnect("Emotiv Systems-5") != 0:
if libEDK.EE_EngineRemoteConnect("127.0.0.1",3008)!=0:
print "Emotiv Engine start up failed."
eProfile = libEDK.EE_ProfileEventCreate()
libEDK.EE_GetBaseProfile(eProfile)
libEDK.EE_GetUserProfile(userID, eProfile)
else:
print "else else else"
while (1):
state = libEDK.EE_EngineGetNextEvent(eEvent)
#print "entre al while"
if state == 0:
#print "*********"
eventType = libEDK.EE_EmoEngineEventGetType(eEvent)
libEDK.EE_EmoEngineEventGetUserId(eEvent, user)
if eventType == 64: #libEDK.EE_Event_enum.EE_EmoStateUpdated
libEDK.EE_EmoEngineEventGetEmoState(eEvent,eState)
timestamp = ES_GetTimeFromStart(eState)
print "%10.3f New EmoState from user %d ...\r" %(timestamp,userID.value)
logEmoState(userID,eState)
elif state != 0x0600:
print "Internal error in Emotiv Engine ! "
time.sleep(0.1)
#---------------------------------------------------------------------------------------------------------------------------------------------------------------
desconectar()
def desconectar():
libEDK.EE_EngineDisconnect()
libEDK.EE_EmoStateFree(eState)
libEDK.EE_EmoEngineEventFree(eEvent)