Example #1
0
int main(int argc, char *argv[]){
	char* serial_port_name;
	if (argc ==1){
		serial_port_name = SERIALPORTDEFAULT;
	}else if (argc == 2){ // if a command line argument was supplied
		serial_port_name = argv[1]; // the argument is the name of the serial port to open
	}else if(argc > 2){
		printf("Usage is: monitor [serial port name]\n");
	}
	PRINTDEBUG&&printf("main called..\n");
	mysetup_serial_port(serial_port_name);
	PRINTDEBUG&&printf("done setup...\n");
	configureUI();
	
	// setup the log file
	if (LOG)
		logfile = open("log",O_WRONLY|O_APPEND|O_CREAT,0666);// the 0666 is an octal number which sets up proper permissions so we can actually open the log file after writing to it

	//blank out the buffers
	clear_user_command_buffer();
	clear_serial_command_buffer();
	while(1){
		read_from_serial_port(); // read in and buffer stuff in from the serial port
		buffer_input();		 // buffer user input
		refresh();		 // refresh the display
	}
	return quit();
}
//----------------------------------------------------------------
bool t_head_controller::go_to_home_position() {
	// must home the head
	head_motors_controller.send_go_home_stepper_motor(MOTOR_HEAD_HORIZONTAL);
	head_motors_controller.send_go_home_stepper_motor(MOTOR_HEAD_VERTICAL);

	printf("Head motors home started ...");
	clock_t start_time = clock();
	bool horizontal_motor_homed = false;
	bool vertical_motor_homed = false;

	while (1) {
		read_from_serial_port();

		if (!horizontal_motor_homed)
			if (head_motors_controller.query_for_event(STEPPER_MOTOR_MOVE_DONE_EVENT, MOTOR_HEAD_HORIZONTAL))  // have we received the event from Serial ?
				horizontal_motor_homed = true;

		if (!vertical_motor_homed)
			if (head_motors_controller.query_for_event(STEPPER_MOTOR_MOVE_DONE_EVENT, MOTOR_HEAD_VERTICAL))  // have we received the event from Serial ?
				vertical_motor_homed = true;

		if (horizontal_motor_homed && vertical_motor_homed)
			break;

		// measure the passed time 
		clock_t end_time = clock();

		double wait_time = (double) (end_time - start_time) / CLOCKS_PER_SEC;
		// if more than 5 seconds and no home
		if (wait_time > 5) {
			if (!vertical_motor_homed)
				printf("Cannot home vertical motor! Game over!");
			if (!horizontal_motor_homed)
				printf("Cannot home vertical motor! Game over!");
			return false;
		}
	}

	printf("DONE\n");
	return true;
}
Example #3
0
int main(int argc, char *argv[]){
	char* serial_port_name;
	if (argc ==1){
		serial_port_name = SERIALPORTDEFAULT;
	}else if (argc == 2){ // if a command line argument was supplied
		serial_port_name = argv[1];
	}else if(argc > 2){
		printf("Usage is: monitor [serial port name]\n");
	}
	PRINTDEBUG&&printf("main called..\n");
	setup_serial_port(serial_port_name);
	PRINTDEBUG&&printf("done setup...\n");
	
	// setup the log file
	logfile = open("temp_log",O_WRONLY|O_APPEND|O_CREAT,0666);// the 0666 is an octal number which sets up proper permissions so we can actually open the log file after
	write(serialport,"\r\n",2); // send a 'wake up' to the avr
	clear_serial_command_buffer();
	while(1){
		read_from_serial_port();
	}
	return quit();
}