-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInsight.py
executable file
·167 lines (138 loc) · 7.25 KB
/
Insight.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import sys, os, ctypes
class Insight(object):
#Ports EmoComposer=1726, ControlPanel=3008
def __init__(self, composerConnect=False, composerPort=3008
, userID=0):
self.composerConnect = composerConnect
self.composerPort = composerPort
self.userID = ctypes.c_uint(userID)
self.user = ctypes.pointer(self.userID)
self.FE_SURPRISE = 64
self.FE_FROWN = 32
self.FE_SMILE = 128
self.FE_CLENCH = 256
self.FacialExpressionStates = {}
self.FacialExpressionStates[self.FE_FROWN] = 0
self.FacialExpressionStates[self.FE_SURPRISE] = 0
self.FacialExpressionStates[self.FE_SMILE] = 0
self.FacialExpressionStates[self.FE_CLENCH] = 0
try:
if sys.platform.startswith('win32'):
self.libEDK = ctypes.cdll.LoadLibrary("edk.dll")
if sys.platform.startswith('linux'):
srcDir = os.getcwd()
libPath = srcDir + "/libedk.so"
self.libEDK = ctypes.CDLL(libPath)
except:
print 'Error : cannot load dll lib'
IEE_EmoEngineEventCreate = self.libEDK.IEE_EmoEngineEventCreate
IEE_EmoEngineEventCreate.restype = ctypes.c_void_p
self.eEvent = IEE_EmoEngineEventCreate()
IEE_EmoStateCreate = self.libEDK.IEE_EmoStateCreate
IEE_EmoStateCreate.restype = ctypes.c_void_p
self.eState = IEE_EmoStateCreate()
def disconnect(self):
self.libEDK.IEE_EngineDisconnect()
self.libEDK.IEE_EmoStateFree(eState)
self.libEDK.IEE_EmoEngineEventFree(eEvent)
def connect(self):
if self.composerConnect:
self.libEDK.IEE_EngineRemoteConnect("127.0.0.1", self.composerPort)
else:
self.libEDK.IEE_EngineConnect("Emotiv Systems-5")
def get_state(self, eEvent):
return self.libEDK.IEE_EngineGetNextEvent(eEvent)
def get_event_type(self, eEvent):
return self.libEDK.IEE_EmoEngineEventGetType(eEvent)
def get_engine_event_emo_state(self, eEvent, eState):
IEE_EmoEngineEventGetEmoState = \
self.libEDK.IEE_EmoEngineEventGetEmoState
IEE_EmoEngineEventGetEmoState.argtypes = [
ctypes.c_void_p, ctypes.c_void_p]
IEE_EmoEngineEventGetEmoState.restype = ctypes.c_int
return IEE_EmoEngineEventGetEmoState(eEvent, eState)
def get_userID(self, eEvent, user):
return self.libEDK.IEE_EmoEngineEventGetUserId(eEvent, user)
def get_time_from_start(self, eState):
IS_GetTimeFromStart = self.libEDK.IS_GetTimeFromStart
IS_GetTimeFromStart.argtypes = [ctypes.c_void_p]
IS_GetTimeFromStart.restype = ctypes.c_float
return IS_GetTimeFromStart(eState)
def get_wireless_signal_status(self, eState):
IS_GetWirelessSignalStatus = self.libEDK.IS_GetWirelessSignalStatus
IS_GetWirelessSignalStatus.restype = ctypes.c_int
IS_GetWirelessSignalStatus.argtypes = [ctypes.c_void_p]
return IS_GetWirelessSignalStatus(eState)
def get_facial_expression_is_blink(self, eState):
IS_FacialExpressionIsBlink = self.libEDK.IS_FacialExpressionIsBlink
IS_FacialExpressionIsBlink.restype = ctypes.c_int
IS_FacialExpressionIsBlink.argtypes = [ctypes.c_void_p]
return IS_FacialExpressionIsBlink(eState)
def get_left_wink(self, eState):
IS_FacialExpressionIsLeftWink = \
self.libEDK.IS_FacialExpressionIsLeftWink
IS_FacialExpressionIsLeftWink.restype = ctypes.c_int
IS_FacialExpressionIsLeftWink.argtypes = [ctypes.c_void_p]
return IS_FacialExpressionIsLeftWink(eState)
def get_right_wink(self, eState):
IS_FacialExpressionIsRightWink = \
self.libEDK.IS_FacialExpressionIsRightWink
IS_FacialExpressionIsRightWink.restype = ctypes.c_int
IS_FacialExpressionIsRightWink.argtypes = [ctypes.c_void_p]
return IS_FacialExpressionIsRightWink(eState)
def get_upper_face_action(self, eState):
IS_FacialExpressionGetUpperFaceAction = \
self.libEDK.IS_FacialExpressionGetUpperFaceAction
IS_FacialExpressionGetUpperFaceAction.restype = ctypes.c_int
IS_FacialExpressionGetUpperFaceAction.argtypes = [ctypes.c_void_p]
return IS_FacialExpressionGetUpperFaceAction(eState)
def get_upper_face_action_power(self, eState):
IS_FacialExpressionGetUpperFaceActionPower = \
self.libEDK.IS_FacialExpressionGetUpperFaceActionPower
IS_FacialExpressionGetUpperFaceActionPower.restype = ctypes.c_float
IS_FacialExpressionGetUpperFaceActionPower.argtypes = [ctypes.c_void_p]
return IS_FacialExpressionGetUpperFaceActionPower(eState)
def get_lower_face_action(self, eState):
IS_FacialExpressionGetLowerFaceAction = \
self.libEDK.IS_FacialExpressionGetLowerFaceAction
IS_FacialExpressionGetLowerFaceAction.restype = ctypes.c_int
IS_FacialExpressionGetLowerFaceAction.argtypes = [ctypes.c_void_p]
return IS_FacialExpressionGetLowerFaceAction(eState)
def get_lower_face_action_power(self, eState):
IS_FacialExpressionGetLowerFaceActionPower = \
self.libEDK.IS_FacialExpressionGetLowerFaceActionPower
IS_FacialExpressionGetLowerFaceActionPower.restype = ctypes.c_float
IS_FacialExpressionGetLowerFaceActionPower.argtypes = [ctypes.c_void_p]
return IS_FacialExpressionGetLowerFaceActionPower(eState)
def get_mental_command_current_action(self, eState):
IS_MentalCommandGetCurrentAction = \
self.libEDK.IS_MentalCommandGetCurrentAction
IS_MentalCommandGetCurrentAction.restype = ctypes.c_int
IS_MentalCommandGetCurrentAction.argtypes = [ctypes.c_void_p]
return IS_MentalCommandGetCurrentAction(eState)
def get_mental_command_current_action_power(self, eState):
IS_MentalCommandGetCurrentActionPower = \
self.libEDK.IS_MentalCommandGetCurrentActionPower
IS_MentalCommandGetCurrentActionPower.restype = ctypes.c_float
IS_MentalCommandGetCurrentActionPower.argtypes = [ctypes.c_void_p]
return IS_MentalCommandGetCurrentActionPower(eState)
def lower_facial_expression_states(self, eState):
lower_face_action = self.get_lower_face_action(eState)
lower_face_action_power = self.get_lower_face_action_power(eState)
self.FacialExpressionStates[lower_face_action] = lower_face_action_power
def upper_facial_expression_states(self, eState):
self.upper_face_action = self.get_upper_face_action(eState)
self.upper_face_action_power = self.get_upper_face_action_power(eState)
self.FacialExpressionStates[self.upper_face_action] = self.upper_face_action_power
def get_surprise(self, eState):
self.upper_facial_expression_states(eState)
return self.FacialExpressionStates[self.FE_SURPRISE]
def get_frown(self, eState):
self.upper_facial_expression_states(eState)
return self.FacialExpressionStates[self.FE_FROWN]
def get_smile(self, eState):
self.lower_facial_expression_states(eState)
return self.FacialExpressionStates[self.FE_SMILE]
def get_clench(self, eState):
self.lower_facial_expression_states(eState)
return self.FacialExpressionStates[self.FE_CLENCH]