Skip to content
This repository was archived by the owner on Apr 14, 2018. It is now read-only.

Commit

Permalink
Add Timeout Based Read And Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fundamental committed Sep 19, 2014
1 parent 6594ff0 commit 813be80
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/emokit/emokit.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ extern "C"
*/
EMOKIT_DECLSPEC int emokit_read_data(struct emokit_device* dev);

/**
* Read a single raw report from the device.
*
* @param dev Opened device structure
* @param timeout Max wait time in ms
*
* @return <0 for error, otherwise return the number of bytes read.
*/
EMOKIT_DECLSPEC int emokit_read_data_timeout(struct emokit_device* dev,
unsigned timeout);

EMOKIT_DECLSPEC struct emokit_frame
emokit_get_next_frame(struct emokit_device* dev);

Expand Down
17 changes: 17 additions & 0 deletions src/emokit.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int emokit_open(struct emokit_device* s, int device_vid, int device_pid, unsigne
{
int dev_type;
int count = 0;
int found = 0;
struct hid_device_info* devices;
struct hid_device_info* device_cur;
if (!s->_is_inited)
Expand All @@ -145,15 +146,26 @@ int emokit_open(struct emokit_device* s, int device_vid, int device_pid, unsigne
devices = hid_enumerate(device_vid, device_pid);

device_cur = devices;
if(!devices) {
fprintf(stderr, "libemokit: No Matching Devices, check USB ID\n");
return E_EMOKIT_NOT_OPENED;
}

while(device_cur) {
if(count == device_index) {
s->_dev = hid_open_path(device_cur->path);
if(!s->_dev)
fprintf(stderr, "libemokit: Failed to open device #%d, insuffient permissions?\n", count+1);
found = 1;
break;
}
++count;
device_cur = device_cur->next;
}

if(found == 0)
fprintf(stderr, "libemokit: Insuffient Devices Found For #%d out of %d\n", device_index+1, count);

hid_free_enumeration(devices);
if(!s->_dev) {
return E_EMOKIT_NOT_OPENED;
Expand Down Expand Up @@ -181,6 +193,11 @@ int emokit_read_data(struct emokit_device* s)
return hid_read(s->_dev, s->raw_frame, 32);
}

int emokit_read_data_timeout(struct emokit_device* s, unsigned timeout)
{
return hid_read_timeout(s->_dev, s->raw_frame, 32, timeout);
}

EMOKIT_DECLSPEC
void emokit_get_crypto_key(struct emokit_device* s, int dev_type) {
unsigned char type = (unsigned char) dev_type;
Expand Down

0 comments on commit 813be80

Please sign in to comment.