Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update emotiv.py #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions libmushu/driver/emotiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from libmushu.amplifier import Amplifier


VENDOR_ID = 0x1234
PRODUCT_ID = 0xed02
VENDOR_ID = 0x21a1
PRODUCT_ID = 0x0001

ENDPOINT_IN = usb.util.ENDPOINT_IN | 2 # second endpoint

Expand All @@ -39,7 +39,11 @@ def __init__(self):
# find amplifier
self.dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
if self.dev is None:
raise RuntimeError('Emotiv device is not connected.')
VENDOR_ID = 0x1234
PRODUCT_ID = 0xed01
self.dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
if self.dev is None:
raise RuntimeError('Emotiv device is not connected.')
# pyusb docs say you *have* to call set_configuration, but it does not
# work unless i *don't* call it.
#dev.set_configuration()
Expand All @@ -58,6 +62,8 @@ def __init__(self):
# is not sent with every frame.
self._battery = 0
self._quality = [0 for i in range(14)]
#sampling frequency
self.fs = 128
# channel info
self.channel = ['Counter', 'Battery',
'F3', 'FC5', 'AF3', 'F7', 'T7', 'P7', 'O1',
Expand All @@ -71,22 +77,28 @@ def __init__(self):

def get_data(self):
try:
raw = self.dev.read(ENDPOINT_IN, 32, 1, timeout=1000)
raw = self.dev.read(ENDPOINT_IN, 32, 1, timeout=10000)
raw = self.decrypt(raw)
data = self.parse_raw(raw)
data = np.array(data)
except Exception as e:
print e
data = np.array()
return data.reshape(1, -1)
return data.reshape(1, -1),[]

def get_sampling_frequency(self):
return self.fs

def get_channels(self):
return self.channel

@staticmethod
def is_available():
if usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID) is None:
return False
else:
return True

def generate_key(self, sn, research=True):
"""Generate the encryption key.

Expand Down