Exemple #1
0
Fichier : mw.c Projet : coder03/ldd
main(){
	int fd;
	struct termios *oldser,*newser,*oldter,*newter;
	oldser=(struct termios *)malloc(sizeof(struct termios));
	newser=(struct termios *)malloc(sizeof(struct termios));
	oldter=(struct termios *)malloc(sizeof(struct termios));
	newter=(struct termios *)malloc(sizeof(struct termios));
	fd=openSerial("/dev/ttyS1");
	setSerial(fd,oldser,newser);
	/* next stop echo and buffering for stdin */
 	tcgetattr(0,oldter);
 	tcgetattr(0,newter); /* get working stdtio */
 	newter->c_lflag &= ~(ICANON | ECHO);
 	tcsetattr(0,TCSANOW,newter);
	writeToSerial(fd,'x');
   	tcsetattr(fd,TCSANOW,oldser); /* restore old serial setings */
	close(fd);
   	tcsetattr(0,TCSANOW,oldter); /* restore old tty setings */
	exit(0);
}
CameraController::CameraController(string serialPort, int target_x, int target_y)
{
	this->last_x = 0;
	this->last_y = 0;
	
	this->target_x = target_x;
	this->target_y = target_y;
	
	this->lastAngle_x = 90;
	this->lastAngle_y = 90;
	
	int serial_status = this->serial.openPort(serialPort);
	if (serial_status == -1)
	{
		printf("Failed to open serial port\n");
	}
	else
	{
		writeToSerial(this->lastAngle_x, this->lastAngle_y);
	}
}
void CameraController::turnCamera(int new_x, int new_y)
{
	int *angles = getNewAngleFromPoint(new_x, new_y);
	
	int s = writeToSerial(angles[0], angles[1]);
	if (s != -1)
	{
		printf("SENT %d %d\n", angles[0], angles[1]);
	}
	else
	{
		printf("Failed to send data to serial device");
	}
	
	this->last_x = new_x;
	this->last_y = new_y;
	
	this->lastAngle_x = angles[0];
	this->lastAngle_y = angles[1];
	
	delete [] angles;
}