Skip to content

Commit

Permalink
Merge pull request #2 from pach/master
Browse files Browse the repository at this point in the history
check connection test on several other connection issue + manage multiple etherdream connection
  • Loading branch information
memo committed Jun 26, 2015
2 parents c4e2557 + 396f0ba commit 729cd66
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/ofxEtherdream.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "ofxEtherdream.h"

//--------------------------------------------------------------
void ofxEtherdream::setup(bool bStartThread) {
void ofxEtherdream::setup(bool bStartThread, int idEtherdream) {

idEtherdreamConnection = idEtherdream;

etherdream_lib_start();

setPPS(30000);
Expand All @@ -10,6 +13,7 @@ void ofxEtherdream::setup(bool bStartThread) {
/* Sleep for a bit over a second, to ensure that we see broadcasts
* from all available DACs. */
usleep(1000000);

init();

if(bStartThread) start();
Expand All @@ -23,11 +27,13 @@ bool ofxEtherdream::stateIsFound() {

//--------------------------------------------------------------
bool ofxEtherdream::checkConnection(bool bForceReconnect) {
if(device->state == ST_SHUTDOWN) {
if(device->state == ST_SHUTDOWN || device->state == ST_BROKEN || device->state == ST_DISCONNECTED) {

if(bForceReconnect) {
kill();
setup();
setup(true, idEtherdreamConnection);
}

return false;
}
return true;
Expand All @@ -36,20 +42,20 @@ bool ofxEtherdream::checkConnection(bool bForceReconnect) {
//--------------------------------------------------------------
void ofxEtherdream::init() {
int device_num = etherdream_dac_count();
if (!device_num) {
if (!device_num || idEtherdreamConnection>device_num) {
ofLogWarning() << "ofxEtherdream::init - No DACs found";
return 0;
}

for (int i=0; i<device_num; i++) {
ofLogNotice() << "ofxEtherdream::init - " << i << " Ether Dream " << etherdream_get_id(etherdream_get(i));
}

device = etherdream_get(0);
}

ofLogNotice() << "ofxEtherdream::init - Connecting...";
if (etherdream_connect(device) < 0) return 1;
device = etherdream_get(idEtherdreamConnection);

ofLogNotice() << "ofxEtherdream::init - Connecting...";
if (etherdream_connect(device) < 0) return 1;

ofLogNotice() << "ofxEtherdream::init - done";

state = ETHERDREAM_FOUND;
Expand Down
4 changes: 3 additions & 1 deletion src/ofxEtherdream.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ofxEtherdream : public ofThread {
}
}

void setup(bool bStartThread = true);
void setup(bool bStartThread = true, int idEtherdream = 0);
virtual void threadedFunction();


Expand Down Expand Up @@ -71,4 +71,6 @@ class ofxEtherdream : public ofThread {

struct etherdream *device;
vector<ofxIlda::Point> points;

int idEtherdreamConnection;
};

0 comments on commit 729cd66

Please sign in to comment.