Changeset 335
- Timestamp:
- 03/25/12 10:59:39 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Puzzlebox/Synapse/Emotiv/Protocol.py
r332 r335 16 16 try: 17 17 import PySide as PyQt4 18 from PySide import QtCore , QtGui, QtNetwork18 from PySide import QtCore # , QtGui, QtNetwork 19 19 except Exception, e: 20 20 print "ERROR: Exception importing PySide:", 21 21 print e 22 configuration.ENABLE_PYSIDE = False 22 #configuration.ENABLE_PYSIDE = False 23 ENABLE_PYSIDE = False 23 24 else: 24 print "INFO: [Synapse: Interface] Using PySide module"25 print "INFO: [Synapse:Emotiv:Protocol] Using PySide module" 25 26 26 else: 27 print "INFO: [Synapse:Interface] Using PyQt4 module" 28 from PyQt4 import QtCore, QtGui, QtNetwork 27 #if not configuration.ENABLE_PYSIDE: 28 if not ENABLE_PYSIDE: 29 print "INFO: [Synapse:Emotiv:Protocol] Using PyQt4 module" 30 from PyQt4 import QtCore # , QtGui, QtNetwork 29 31 30 32 … … 33 35 34 36 35 from PyEpoc import * 36 37 EmotivEngine = EpocHandler() 38 choice = str() 39 engineeventhandle = EmotivEngine.EE_EmoEngineEventCreate() 40 statehandle = EmotivEngine.EE_EmoStateCreate() 41 EmotivEngine.ES_Init(statehandle) 37 #from PyEpoc.PyEpoc import * 38 import PyEpoc.PyEpoc 42 39 43 40 … … 75 72 76 73 #self.device_id = device_id 77 #self.device_model = device_model 78 79 #self.device = None 80 #self.buffer = '' 81 #self.payload_timestamp = time.time() 82 83 #self.device = serial_device 84 #self.auto_connect_timestamp = time.time() 85 86 #self.data_packet = {} 87 #self.data_packet['eegPower'] = {} 88 #self.data_packet['eSense'] = {} 89 90 #self.packet_count = 0 91 #self.bad_packets = 0 92 #self.session_start_time = None 74 self.device_model = device_model 75 self.device = serial_device 93 76 94 77 #self.keep_running = True 95 78 79 self.EmotivEngine = PyEpoc.PyEpoc.EpocHandler() 80 self.engineeventhandle = self.EmotivEngine.EE_EmoEngineEventCreate() 81 self.statehandle = self.EmotivEngine.EE_EmoStateCreate() 82 self.EmotivEngine.ES_Init(self.statehandle) 83 96 84 97 85 ################################################################## … … 108 96 # Connect 109 97 if self.choice == "a": 110 if EmotivEngine.EE_EngineRemoteConnect("127.0.0.1",1726) !=ERRCODE['EDK_OK']:98 if self.EmotivEngine.EE_EngineRemoteConnect("127.0.0.1", 1726) != PyEpoc.PyEpoc.ERRCODE['EDK_OK']: 111 99 print "Could not connect!" 112 100 quit() 113 101 else: print "Connected to EmoComposer!" 114 102 elif self.choice == "b": 115 if EmotivEngine.EE_EngineConnect() !=ERRCODE['EDK_OK']:103 if self.EmotivEngine.EE_EngineConnect() != PyEpoc.PyEpoc.ERRCODE['EDK_OK']: 116 104 print "Could not connect!" 117 105 quit() 118 106 else: print "Connected to Headset!" 119 107 120 print """Engine Event handle at: %s""" %( engineeventhandle)121 print """Emo State handle at: %s""" % (s tatehandle)108 print """Engine Event handle at: %s""" %(self.engineeventhandle) 109 print """Emo State handle at: %s""" % (self.statehandle) 122 110 123 111 # Start 124 112 while True: 125 state = EmotivEngine.EE_EngineGetNextEvent(engineeventhandle)113 state = self.EmotivEngine.EE_EngineGetNextEvent(self.engineeventhandle) 126 114 127 if state == ERRCODE['EDK_OK']:128 event = EmotivEngine.EE_EmoEngineEventGetType(engineeventhandle)129 user = EmotivEngine.EE_EmoEngineEventGetUserId(engineeventhandle)[1]130 if (event == EVENT['EE_EmoStateUpdated']):131 EmotivEngine.EE_EmoEngineEventGetEmoState(engineeventhandle,statehandle)115 if state == PyEpoc.PyEpoc.ERRCODE['EDK_OK']: 116 event = self.EmotivEngine.EE_EmoEngineEventGetType(self.engineeventhandle) 117 user = self.EmotivEngine.EE_EmoEngineEventGetUserId(self.engineeventhandle)[1] 118 if (event == PyEpoc.PyEpoc.EVENT['EE_EmoStateUpdated']): 119 self.EmotivEngine.EE_EmoEngineEventGetEmoState(self.engineeventhandle, self.statehandle) 132 120 #status 133 battery = EmotivEngine.ES_GetBatteryChargeLevel(statehandle)134 wireless = EmotivEngine.ES_GetWirelessSignalStatus(statehandle)135 timestamp = EmotivEngine.ES_GetTimeFromStart(statehandle)121 battery = self.EmotivEngine.ES_GetBatteryChargeLevel(self.statehandle) 122 wireless = self.EmotivEngine.ES_GetWirelessSignalStatus(self.statehandle) 123 timestamp = self.EmotivEngine.ES_GetTimeFromStart(self.statehandle) 136 124 #emo 137 meditation = EmotivEngine.ES_AffectivGetMeditationScore(statehandle)138 shortexcitement = EmotivEngine.ES_AffectivGetExcitementShortTermScore(statehandle)139 longexcitement = EmotivEngine.ES_AffectivGetExcitementLongTermScore(statehandle)140 frustration = EmotivEngine.ES_AffectivGetFrustrationScore(statehandle)125 meditation = self.EmotivEngine.ES_AffectivGetMeditationScore(self.statehandle) 126 shortexcitement = self.EmotivEngine.ES_AffectivGetExcitementShortTermScore(self.statehandle) 127 longexcitement = self.EmotivEngine.ES_AffectivGetExcitementLongTermScore(self.statehandle) 128 frustration = self.EmotivEngine.ES_AffectivGetFrustrationScore(self.statehandle) 141 129 #cognitiv 142 currentaction = EmotivEngine.ES_CognitivGetCurrentAction(statehandle)143 currentactionpower = EmotivEngine.ES_CognitivGetCurrentActionPower(statehandle)130 currentaction = self.EmotivEngine.ES_CognitivGetCurrentAction(self.statehandle) 131 currentactionpower = self.EmotivEngine.ES_CognitivGetCurrentActionPower(self.statehandle) 144 132 print """--------------------------------------------------------------------------------""" 145 print """Timestamp: %s\tUser: %s\tEvent: %s\tW.Signal: %s\tBattery: %s""" % (timestamp,user,hex(event), wireless,battery)146 print """S.Excite: %s\tL.Excite: %s\tMeditation: %s\tFrustr: %s""" % (shortexcitement, longexcitement,meditation,frustration)147 print """Curr.Action: %s\tAction Pwr: %s""" % (hex(currentaction), currentactionpower)133 print """Timestamp: %s\tUser: %s\tEvent: %s\tW.Signal: %s\tBattery: %s""" % (timestamp,user,hex(event), wireless, battery) 134 print """S.Excite: %s\tL.Excite: %s\tMeditation: %s\tFrustr: %s""" % (shortexcitement, longexcitement, meditation, frustration) 135 print """Curr.Action: %s\tAction Pwr: %s""" % (hex(currentaction), currentactionpower) 148 136
Note: See TracChangeset
for help on using the changeset viewer.