Skip to content

Commit

Permalink
use non blocking mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Whitfield committed Aug 3, 2011
1 parent fb5551a commit d0f2f8e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion example/src/gamepadExampleApp.cpp
Expand Up @@ -5,7 +5,7 @@ void gamepadExampleApp::setup(){
ofSetWindowTitle("gamepadExampleApp");
ofBackground(0,0,0);

ofSetFrameRate(60);
ofSetFrameRate(120);
ofSetLogLevel(OF_LOG_NOTICE);

}
Expand Down
2 changes: 1 addition & 1 deletion src/ofxGamepad.cpp
@@ -1,6 +1,6 @@
#include "ofxGamepad.h"

ofxGamepad::ofxGamepad():axisMinVal(-32767),axisMaxVal(32767)
ofxGamepad::ofxGamepad():axisMinVal(-32768),axisMaxVal(32767)
{
}

Expand Down
25 changes: 13 additions & 12 deletions src/ofxGamepadLinux.cpp
Expand Up @@ -27,6 +27,8 @@ ofxGamepadLinux::ofxGamepadLinux(string f):ofxGamepad()
} else {
name = name_c_str;
}

fcntl( fd, F_SETFL, O_NONBLOCK );
}

string msg=name;
Expand All @@ -42,19 +44,18 @@ ofxGamepadLinux::~ofxGamepadLinux()
void ofxGamepadLinux::update()
{
struct js_event event;
ssize_t len = read(fd, &event, sizeof(struct js_event));
if (len < 0) {
std::ostringstream str;
ofLog(OF_LOG_WARNING, "something strange happend while reading joystick data");
} else if (len == sizeof(event)) {
if (event.type & JS_EVENT_AXIS) {
axisChanged(int(event.number), int(event.value));
} else if (event.type & JS_EVENT_BUTTON) {
buttonChanged(int(event.number), bool(event.value));
}
} else {
ofLog(OF_LOG_ERROR, "Joystick::update(): unknown read error");
read(fd, &event, sizeof(struct js_event));

/* see what to do with the event */
switch (event.type & ~JS_EVENT_INIT) {
case JS_EVENT_AXIS:
axisChanged(event.number, event.value);
break;
case JS_EVENT_BUTTON:
buttonChanged(event.number, event.value);
break;
}

}
void ofxGamepadLinux::exit()
{
Expand Down

0 comments on commit d0f2f8e

Please sign in to comment.