Exemplo n.º 1
0
bool chladniRC::setupArduinoSerial(){
	
	// by default, connect to the first Arduino-looking device
	
	std::vector<ofx::IO::SerialDeviceInfo> devicesInfo = ofx::IO::SerialDeviceUtils::listDevices();
	
	if (!devicesInfo.empty()){
		for (std::size_t i = 0; i < devicesInfo.size(); ++i) {
			if( devicesInfo[i].getDescription().find("Arduino") != devicesInfo[i].getDescription().npos ){
				
				// try connect
				if(connectToArduino(devicesInfo[i])){
					return true;
				}
				else {
					// continue searching for arduino devices
					continue;
				}
			}
			else {
				// continue searching for arduino devices
				continue;
			}
			
		}
	}
	
	return false;
}
//--------------------------------------------------------------
void ofApp::setup(){
    serial.listDevices();
    bool connectionStatus = connectToArduino();
    ofLog() << "Connect To Arduino returned: " << connectionStatus;
    if(!connectionStatus){
        ofExit();
    }

    cubes = vector<Cube>(nrCubes, Cube());
    //place the cubes
    for(int i = 0; i < nrCubes; i++){
        cubes[i].setup(i, this);
    }
    updateCubes();

    ofAddListener(Cube::cubeTriggered, this, &ofApp::onCubeTriggered);
    ofAddListener(CopyBridge::copyingDone, this, &ofApp::onCopyingDone);

    seq = new Sequencer(this, 120);

    //GUI
    gui.setup();
    run.addListener(this, &ofApp::toggleSequencer);
    gui.add(run.setup("run sequencer", false));
    tempo.addListener(this, &ofApp::setTempo);
    gui.add(tempo.setup("tempo", 120, 80, 140));
}
Exemplo n.º 3
0
bool chladniRC::connectToArduino(const int &_deviceID){
	
	// get devices list
	std::vector<ofx::IO::SerialDeviceInfo> devicesInfo = ofx::IO::SerialDeviceUtils::listDevices();
	
//	for (std::size_t i = 0; i < devicesInfo.size(); ++i) {
//		cout << devicesInfo[i];
//	}
	
	if( !devicesInfo.empty() && _deviceID >= 0 && _deviceID < devicesInfo.size() ){
		
		devicesInfo.size();
		ofx::IO::SerialDeviceInfo deviceInfo = devicesInfo[_deviceID];
		
		return connectToArduino(deviceInfo);
	}
	else {
		// device unavailable
	}
	
}