void SerialCommunicationApp::update()
{
	if (serialInitiallized()){
        if(serial.getNumBytesAvailable() > 0){
            console() << "Bytes available: " << serial.getNumBytesAvailable() << std::endl;
            try{
                lastString = serial.readStringUntil('\n');
            } catch(SerialTimeoutExc e) {
                console() << "timeout" << endl;
            }
            console() << lastString << endl;
            int16_t temp = lastString[0];
            
            //OSC MESSAGE
            osc::Message message;
            message.addIntArg(temp);
            message.setAddress("coinTrigger");
            message.setRemoteEndpoint(host, port);
            sender.sendMessage(message);
           
            TextLayout simple;
            simple.setFont( Font( "Arial Black", 54 ) );
            simple.setColor( Color( .7, .7, .2 ) );
            simple.addLine( lastString );
            simple.setLeadingOffset( 0 );
            mTexture = gl::Texture( simple.render( true, false ) );
            bTextureComplete = true;
            serial.flush();
        }
    }
    serial.flush();
}
예제 #2
0
void SerialCommunicationApp::setup()
{
	ctr = 0;
	lastString = "";
	sinceLastRead = 0.0;
	lastUpdate = 0.0;
	
	bSendSerialMessage = false;
	bTextureComplete = false;

	// print the devices
	const vector<Serial::Device> &devices( Serial::getDevices() );
	for( vector<Serial::Device>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) {
		console() << "Device: " << deviceIt->getName() << endl;
	}
	
	try {
		Serial::Device dev = Serial::findDeviceByNameContains("tty.usbserial");
		serial = Serial( dev, 9600);
	}
	catch( ... ) {
		console() << "There was an error initializing the serial device!" << std::endl;
		exit( -1 );
	}
	
	// wait for * as a sign for first contact
	char contact = 0;
	while(contact != '*')
	{
		contact = (char) serial.readByte();
	}
	
	// request actual data
	serial.writeByte(ctr);
	
	// clear accumulated contact messages in buffer
	char b = '*';
	while(serial.getNumBytesAvailable() > -1)
	{
		b = serial.readByte();
		console() << b << "_";
	}
		
	serial.flush();
}
예제 #3
0
파일: gravApp.cpp 프로젝트: pholz/grav
void gravApp::setup()
{
	egen = new EnemyGenerator(1.0f, 10.0f);
	
	planets = vector<Planet*>();
	planets.push_back(new Planet(Vec2f(750.0f, 600.0f), 40.0f));
	planets.push_back(new Planet(Vec2f(430.0f, 270.0f), 50.0f));
	planets.push_back(new Planet(Vec2f(650.0f, 400.0f), 30.0f));
	planets.push_back(new Planet(Vec2f(450.0f, 320.0f), 70.0f));
	planets.push_back(new Planet(Vec2f(520.0f, 560.0f), 40.0f));
//	planets.push_back(new Planet(Vec2f(930.0f, 260.0f), 40.0f));
//	planets.push_back(new Planet(Vec2f(1120.0f, 760.0f), 50.0f));
//	planets.push_back(new Planet(Vec2f(1200.0f, 800.0f), 30.0f));
	
	moon1 = new Moon(Vec2f(50.0f, 50.0f), Vec2f(50.0f, .0f), Vec2f(.0f, .0f), 1);
	moon2 = new Moon(Vec2f(250.0f, 750.0f), Vec2f(-50.0f, .0f), Vec2f(.0f, .0f), 2);
	
	moon1->color = Color(1.0f,			133.0f/255.0f,	163.0f/255.0f);
	moon2->color = Color(224.0f/255.0f, 1.0f,			133.0f/255.0f);
	
	last = getElapsedSeconds();
	
	params.speed = .7f;
	params.repulse = 5000.0f;
	params.distFactor = 1.0f;
	
	// Setup the parameters
	ifParams = params::InterfaceGl( "Parameters", Vec2i( 200, 400 ) );
	ifParams.addParam( "Speed", &(params.speed), "min=0.1 max=1.0 step=0.01 keyIncr=Z keyDecr=z" );
	ifParams.addParam( "x", &(params.repulse), "min=0.1 max=1.0 step=0.01 keyIncr=X keyDecr=x" );
	ifParams.addParam( "y", &(params.distFactor), "min=0.1 max=1.0 step=0.01 keyIncr=C keyDecr=c" );	
	
	turntime = 8.0f;
	turncounter = .0f;
	turn = 1;
	collInert = .0f;
	
	gl::enableAlphaBlending( false );
	
	curMoon = moon1;
	
	// audio
	
	mMaxFreq = 2000.0f;
	mFreqTarget = 0.0f;
	mPhase = 0.0f;
	mPhaseAdjust = 0.0f;
	
	mMaxFreqQ = 2000.0f;
	mFreqTargetQ = 0.0f;
	mPhaseQ = 0.0f;
	mPhaseAdjustQ = 0.0f;
	
	
	
	s_hit = audio::load( loadResource( RES_HIT ) );
	s_up = audio::load( loadResource( RES_UP ) );
	
	end = false;
	winner = 0;
	
	
	/// SERIAL
	
	ctr = 0;
	lastString = "";
	sinceLastRead = 0.0;
	lastUpdate = 0.0;
	
	bSendSerialMessage = false;
	
	const vector<Serial::Device> &devices( Serial::getDevices() );
	for( vector<Serial::Device>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) {
		console() << "Device: " << deviceIt->getName() << endl;
	}
	
	try {
		Serial::Device dev = Serial::findDeviceByNameContains("tty.usbserial");
		serial = Serial( dev, 9600);
	}
	catch( ... ) {
		console() << "There was an error initializing the serial device!" << std::endl;
		exit( -1 );
	}
	
	// wait for * as a sign for first contact
	char contact = 0;
	while(contact != '*')
	{
		contact = (char) serial.readByte();
	}
	
	// request actual data
	serial.writeByte(ctr);
	
	// clear accumulated contact messages in buffer
	char b = '*';
	while(serial.getNumBytesAvailable() > -1)
	{
		b = serial.readByte();
		console() << b << "_";
	}
	
	serial.flush();
	
	lastOn = 0;
	
}