当前位置: 首页>>代码示例>>C++>>正文


C++ Serial::readByte方法代码示例

本文整理汇总了C++中Serial::readByte方法的典型用法代码示例。如果您正苦于以下问题:C++ Serial::readByte方法的具体用法?C++ Serial::readByte怎么用?C++ Serial::readByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Serial的用法示例。


在下文中一共展示了Serial::readByte方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setup

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();
}
开发者ID:AKS2346,项目名称:Cinder,代码行数:45,代码来源:SerialCommunicationApp.cpp

示例2: serialInitiallized

bool SerialCommunicationApp::serialInitiallized(){
    //SERIAL HANDSHAKE WITH ARDUINO
    
	if (contact != '*'){
		contact = (char) serial.readByte();
        return false;
	}else{
        serial.writeByte('0');
        return true;
    }
    
}
开发者ID:dmelancon,项目名称:Prototypes,代码行数:12,代码来源:SerialCommunicationApp.cpp

示例3: update

void gravApp::update()
{
	float now = getElapsedSeconds();
	float dt = now - last;
	last = now;
	
	turncounter += dt;
	
	if(turncounter >= turntime)
	{
		turncounter = .0f;
		turn = (turn == 1 ? 2 : 1);
		if(turn == 1)	curMoon = moon1;
		else			curMoon = moon2;
	}
	
	params.turn = turn;
	
	if(collInert > .0f) collInert -= dt;
	if(collInert < .0f) collInert = .0f;
	
	vector<Planet*>::iterator it;
	for(it = planets.begin(); it < planets.end(); it++)
	{
		(*it)->update(dt);
	}
	
	moon1->update(dt, planets, params);
	moon2->update(dt, planets, params);
	
	egen->update(dt);
	
	int num1 = egen->collide(moon1->pos, MOONSIZE, true);
	int num2 = egen->collide(moon2->pos, MOONSIZE, true);
	
	moon1->score += num1;
	moon2->score += num2;
	
	if(num1 > 0 || num2 > 0)
		audio::Output::play( s_up );
	
	if(moon1->pos.distance(moon2->pos) < 3*MOONSIZE)
	{
		Moon* loser = moon1->vel.length() < moon2->vel.length() ? moon1 : moon2;
		Moon* winner = (loser == moon1 ? moon2 : moon1);
		
		if(loser->losing.size() == 0 && loser->score >= 3 && !collInert)
		{
			audio::Output::play( s_hit );
			loser->score -= 3;
			loser->loseScore(winner->vel, 3);
			
			collInert = 5.0f;
		}
		
	}
	
	if(num1 > 0)
		cout << "SCORE P1";
	if(num2 > 0)
		cout << "SCORE P2";
	
	
	mFreqTarget = math<float>::clamp(moon1->nearest->pos.distance(moon1->pos) + 80.0f, 100.0f, 1000.0f);
	mFreqTargetQ = math<float>::clamp(moon2->nearest->pos.distance(moon2->pos) + 80.0f, 100.0f, 1000.0f);
	
	if(moon1->score >= 12)
	{
		end = true;
		winner = moon1;
	} else if(moon2->score >= 12)
	{
		end = true;
		winner = moon2;
	}
	
	
	/// SERIAL
	
	lastUpdate = now;
	sinceLastRead += dt;
	
	if(sinceLastRead > .05)
	{
		bSendSerialMessage = true;
		sinceLastRead = 0.0;
	}
	
	
	if (bSendSerialMessage)
	{
		// request next chunk
		serial.writeByte(ctr);
		
		int on;
		
		try{
			// read until newline, to a maximum of BUFSIZE bytes
			on = serial.readByte();
			
//.........这里部分代码省略.........
开发者ID:pholz,项目名称:grav,代码行数:101,代码来源:gravApp.cpp

示例4: setup

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();
//.........这里部分代码省略.........
开发者ID:pholz,项目名称:grav,代码行数:101,代码来源:gravApp.cpp


注:本文中的Serial::readByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。