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

PIC for x86-64 *nix linking & a non-blocking poll in C API #90

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*build*
*.pyc
*.pyc
.*.swp
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required (VERSION 2.6)
cmake_minimum_required (VERSION 2.8.9)
PROJECT(emokit)

SET(BUILD_SHARED_LIBS false)
SET_TARGET_PROPERTIES(emokit PROPERTIES POSITION_INDEPENDENT_CODE TRUE)

LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
Expand Down
72 changes: 0 additions & 72 deletions cmake_modules/Findlibusb-1.0.cmake

This file was deleted.

9 changes: 9 additions & 0 deletions include/emokit/emokit.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ extern "C"
* @return 0 if successful, < 0 for error
*/
EMOKIT_DECLSPEC int emokit_read_data(struct emokit_device* dev);

/**
* Poll the device. Like emokit_read_data, but non-blocking.
*
* @param dev Opened device structure
*
* @return 0 if nothing read, >=1 if report was read, < 0 for error
*/
EMOKIT_DECLSPEC int emokit_poll_data(struct emokit_device* dev);

EMOKIT_DECLSPEC struct emokit_frame
emokit_get_next_frame(struct emokit_device* dev);
Expand Down
20 changes: 13 additions & 7 deletions python/emokit/emotiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ def updateStdout(self):
os.system('cls')
else:
os.system('clear')
print "Packets Received: %s Packets Processed: %s" % (self.packetsReceived, self.packetsProcessed)
print("Packets Received: %s Packets Processed: %s" % (self.packetsReceived, self.packetsProcessed))
print('\n'.join("%s Reading: %s Strength: %s" % (k[1], self.sensors[k[1]]['value'],self.sensors[k[1]]['quality']) for k in enumerate(self.sensors)))
print "Battery: %i" % g_battery
print("Battery: %i" % g_battery)
gevent.sleep(1)

def getLinuxSetup(self):
Expand All @@ -388,7 +388,7 @@ def getLinuxSetup(self):
with open(input[0] + "/serial", 'r') as f:
serial = f.readline().strip()
f.close()
print "Serial: " + serial + " Device: " + input[1]
print("Serial: " + serial + " Device: " + input[1])
# Great we found it. But we need to use the second one...
hidraw = input[1]
id_hidraw = int(hidraw[-1])
Expand All @@ -398,7 +398,7 @@ def getLinuxSetup(self):
print "Serial: " + serial + " Device: " + hidraw + " (Active)"
return [serial, hidraw, ]
except IOError as e:
print "Couldn't open file: %s" % e
print("Couldn't open file: %s" % e)

def setupWin(self):
devices = []
Expand Down Expand Up @@ -508,7 +508,7 @@ def setupCrypto(self, sn):
key = ''.join(k)
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_ECB, iv)
for i in k: print "0x%.02x " % (ord(i))
for i in k: print("0x%.02x " % (ord(i)))
while self._goOn:
while not tasks.empty():
task = tasks.get()
Expand All @@ -522,8 +522,14 @@ def setupCrypto(self, sn):
def dequeue(self):
try:
return self.packets.get()
except Exception, e:
print e
except Exception as e:
print(e)

def dequeue_nowait(self):
try:
return self.packets.get_nowait()
except Exception as e:
return None

def close(self):
if windows:
Expand Down
15 changes: 14 additions & 1 deletion src/emokit.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,20 @@ int emokit_close(struct emokit_device* s)

int emokit_read_data(struct emokit_device* s)
{
return hid_read(s->_dev, s->raw_frame, 32);
int res = hid_set_nonblocking(s->_dev, 0);
if(res < 0)
return res;
else
return hid_read(s->_dev, s->raw_frame, 32);
}

int emokit_poll_data(struct emokit_device* s)
{
int res = hid_set_nonblocking(s->_dev, 1);
if(res < 0)
return res;
else
return hid_read(s->_dev, s->raw_frame, 32);
}

EMOKIT_DECLSPEC
Expand Down