Skip to content

Commit 1ac4373

Browse files
author
Séverin Lemaignan
committed
Added some detection code to emotiv.py to know if we are using a system daemon to uncode the EPOC stream
1 parent c52a167 commit 1ac4373

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

emotiv.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
except:
55
windows = False
66

7-
import sys
7+
import sys, os
88
import logging
99
logger = logging.getLogger("emotiv")
1010

@@ -58,7 +58,7 @@ def __repr__(self):
5858
)
5959

6060
class Emotiv(object):
61-
def __init__(self, headsetId=0, research_headset = False):
61+
def __init__(self, headsetId=0, research_headset = True):
6262

6363
if research_headset:
6464
self.rijn = rijndael(research_key, 16)
@@ -69,9 +69,9 @@ def __init__(self, headsetId=0, research_headset = False):
6969
self.packets = []
7070

7171
if self.setupWin(headsetId) if windows else self.setupPosix(headsetId):
72-
logger.info("Fine, connected to the Emotiv receiver")
72+
logger.info("Fine, connected to the Emotiv EPOC receiver")
7373
else:
74-
logger.error("Unable to connect to the Emotiv receiver :-(")
74+
logger.error("Unable to connect to the Emotiv EPOC receiver :-(")
7575
sys.exit(1)
7676

7777
def setupWin(self, headsetId):
@@ -88,11 +88,26 @@ def handle(data):
8888

8989
def setupPosix(self, headsetId):
9090
def reader():
91-
self.hidraw = open("/dev/hidraw1")
91+
_os_decryption = False
92+
if os.path.exists('/dev/eeg/raw'):
93+
#The decrpytion is handled by the Linux epoc daemon. We don't need to handle it there.
94+
_os_decryption = True
95+
self.hidraw = open("/dev/eeg/raw")
96+
else:
97+
if os.path.exists("/dev/hidraw2"):
98+
self.hidraw = open("/dev/hidraw2")
99+
else:
100+
self.hidraw = open("/dev/hidraw2")
101+
92102
while self._goOn:
93103
data = self.hidraw.read(32)
94104
if data != "":
95-
self.gotData(data)
105+
if _os_decryption:
106+
self.packets.append(EmotivPacket(data))
107+
else:
108+
#Decrypt it!
109+
self.gotData(data)
110+
96111
self._dataReader = Thread(target=reader)
97112
self._dataReader.start()
98113
return True

0 commit comments

Comments
 (0)