Skip to content
Permalink
Browse files

Replaced hid by direct access to /dev/hidraw2 on Posix system

Doesn't seem to give any useful data for now. It may be due to different encrytion key on
the developers headset.
  • Loading branch information...
Séverin Lemaignan
Séverin Lemaignan committed Sep 13, 2010
1 parent 6da14a6 commit e98ee4b1a7deda2e9cc41741d99a408e48c75776
Showing with 17 additions and 16 deletions.
  1. +17 −16 emotiv.py
@@ -2,7 +2,6 @@
import pywinusb.hid as hid
windows = True
except:
import hid
windows = False

import sys
@@ -12,6 +11,8 @@
from aes import rijndael
import struct

from threading import Thread

key = '\x31\x00\x35\x54\x38\x10\x37\x42\x31\x00\x35\x48\x38\x00\x37\x50'
rijn = rijndael(key, 16)

@@ -63,6 +64,9 @@ def __repr__(self):

class Emotiv(object):
def __init__(self, headsetId=0):

self._goOn = True

if self.setupWin(headsetId) if windows else self.setupPosix(headsetId):
logger.info("Fine, connected to the Emotiv receiver")
else:
@@ -83,22 +87,16 @@ def handle(data):
self.device.set_raw_data_handler(handle)

def setupPosix(self, headsetId):
hid.hid_set_debug(hid.HID_DEBUG_ALL)
hid.hid_init()
matcher = hid.HIDInterfaceMatcher()
matcher.vendor_id = 0x21a1
matcher.product_id = 0x0001
self.interface = interface = hid.hid_new_HIDInterface()
if hid.hid_force_open(interface, 0, matcher, 1000) != hid.HID_RET_SUCCESS:
self.interface = interface = hid.hid_new_HIDInterface()
if hid.hid_force_open(interface, 1, matcher, 1000) != hid.HID_RET_SUCCESS:
return False
def reader():
while True:
ret, data = hid.hid_interrupt_read(interface, 0x81, 0x20, 0)
if ret == 0:
self.hidraw = open("/dev/hidraw2")
while self._goOn:
#ret, data = hid.hid_interrupt_read(interface, 0x81, 0x20, 0)
data = self.hidraw.read(32)
if data != "":
self.gotData(data)
thread.start_new_thread(reader, ())
self._dataReader = Thread(target=reader)
self._dataReader.start()
return True

def gotData(self, data):
assert len(data) == 32
@@ -113,4 +111,7 @@ def close(self):
if windows:
self.device.close()
else:
hid.hid_close(self.interface)
self._goOn = False
self._dataReader.join()

self.hidraw.close()

0 comments on commit e98ee4b

Please sign in to comment.
You can’t perform that action at this time.