예제 #1
0
//--------------------------------------------------------------
void ofxEtherdream::init() {
	cout << "ETHERDREAM INIT -----------------------------------------------" << endl;
    int device_num = etherdream_dac_count();

	cout << "FOUND " << device_num << " DEVICE(S)" << endl;
	if (!device_num) {
		ofLogWarning() << "ofxEtherdream::init - No DACs found";
		state = ETHERDREAM_CONNECTION_FAILED;

		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) {
		state = ETHERDREAM_CONNECTION_FAILED;
		return 1;
	}
    
    ofLogNotice() << "ofxEtherdream::init - done";
    
    state = ETHERDREAM_RUNNING;
}
예제 #2
0
파일: test.c 프로젝트: Janesak1977/j4cDAC
int main(int argc, char **argv) {
	etherdream_lib_start();

	/* Sleep for a bit over a second, to ensure that we see broadcasts
	 * from all available DACs. */
	usleep(1200000);

	int cc = etherdream_dac_count();
	if (!cc) {
		printf("No DACs found.\n");
		return 0;
	}

	int mode;
	if (argc > 1)
		mode = atoi(argv[1]);
	else
		mode = 0;

	int i;
	for (i = 0; i < cc; i++) {
		printf("%d: Ether Dream %06lx\n", i,
			etherdream_get_id(etherdream_get(i)));
	}

	struct etherdream *d = etherdream_get(0);

	printf("Connecting...\n");
	if (etherdream_connect(d) < 0)
		return 1;

	i = 0;
	while (1) {
		fill_circle((float)i / 50, mode);
		int res = etherdream_write(d, circle, CIRCLE_POINTS, 30000, 1);
		if (res != 0) {
			printf("write %d\n", res);
		}
		etherdream_wait_for_ready(d);
		i++;
	}

	printf("done\n");
	return 0;
}
예제 #3
0
DACList EtherDream::list_dacs()
{
    int total = etherdream_dac_count();
    DACList dacs(total);

    for(int i = 0; i < total; i++)
    {
        struct etherdream* dac = etherdream_get(i);
        unsigned long id = etherdream_get_id(dac);

        std::stringstream name;
        name << PREFIX_ETHERDREAM;
        name << std::setfill('0') << std::setw(6) << std::hex << id;

        dacs[i] = name.str();
    }

    return dacs;
}
예제 #4
0
//--------------------------------------------------------------
void ofxEtherdream::threadedFunction() {
    while (isThreadRunning() != 0) {
        
        switch (state) {
            case ETHERDREAM_WAITING:
				
				if(lock()) {
					recheckDelay --; 
					if(recheckDelay<0){
						
						//cout << ofGetElapsedTimeMillis() - waitStartMils << endl;
						if (etherdream_dac_count()>0) {
							init();
						}
						// if it's been more than 2 seconds
						if(ofGetElapsedTimeMillis() - waitStartMils > 1000){
							state = ETHERDREAM_CONNECTION_FAILED;
						}						
						recheckDelay = 1000000;
					}
							
                    unlock();
                }
	
                break;

            case ETHERDREAM_RUNNING:
                if(lock()) {
					this->blocking = true;
					if((device==NULL) || (device->state == ST_DISCONNECTED) || (device->state == ST_BROKEN) || (device->state == ST_SHUTDOWN)) {
						state = ETHERDREAM_DISCONNECTED;
					} else {
						send();
					}
                    unlock();
                }
                break;
			default:
				break;
			
        }
    }
}