// Initialize Camera and Sensors
void initDevices(void) {
	struct pxacam_setting camset;
	
	// Backboard uart init
	fdBackBoard = openSerial();

	// 3-axis sensor init 
	fdThreeAxis = open("/dev/MMA_ADC", O_RDONLY);
	ASSERT(fdThreeAxis);

	ioctl(fdThreeAxis,MMA_VIN_ON, 0);
	ioctl(fdThreeAxis,MMA_SLEEP_MODE_ON, 0);
	ioctl(fdThreeAxis,MMA_SENS_60G, 0);

	// infrared sensor init
	fdInfra = open("/dev/FOUR_ADC", O_NOCTTY);
	ASSERT(fdInfra);

	// Camera init
	fdCamera = camera_open(NULL,0);
	ASSERT(fdCamera);

	memset(&camset,0,sizeof(camset));
	camset.mode = CAM_MODE_VIDEO;
	camset.format = pxavid_ycbcr422;

	camset.width = 320;
	camset.height = 240;

	camera_config(fdCamera,&camset);
	camera_start(fdCamera);

	fdOverlay2 = overlay2_open(NULL,pxavid_ycbcr422,NULL, 320, 240, 0 , 0);

	overlay2_getbuf(fdOverlay2, &vidbuf_overlay);
	len_vidbuf = vidbuf_overlay.width * vidbuf_overlay.height;

	cImg.width=camset.width*2;
	cImg.height=camset.height;

	// init finish
	printf("Initializing Device Finished\n");	
}
// Initialize Camera and Sensors
void initDevices(void) {
	struct pxacam_setting camset;
	
	printf("-----Initializing Device Started-----\n");	
	
	// Backboard uart init
	fdBackBoard = openSerial();
	printf("Initializing BackBoard complete!\n");	
		
	// 적외선 센서 init
	fdInfra = open("/dev/FOUR_ADC", O_NOCTTY);
		
		
	// Camera init
	fdCamera = camera_open(NULL,0);
	ASSERT(fdCamera);

	system("echo b > /proc/invert/tb"); //LCD DriverIC top-bottom invert ctrl

	memset(&camset,0,sizeof(camset));
	camset.mode = CAM_MODE_VIDEO;
	camset.format = pxavid_ycbcr422;

	
	camset.width = MAX_X;
	camset.height = MAX_Y;

	camera_config(fdCamera,&camset);
	camera_start(fdCamera);

	fdOverlay2 = overlay2_open(NULL,pxavid_ycbcr422,NULL, MAX_X, MAX_Y, 0 , 0);

	overlay2_getbuf(fdOverlay2, &vidbuf_overlay);
	len_vidbuf = vidbuf_overlay.width * vidbuf_overlay.height;

	printf("Initializing Camera complete!\n");	
	
	// init finish
	printf("-----Initializing Device Finished-----\n");	
}
示例#3
0
int main(int argc, char *argv[])
{
	/* definition of basic variables */
	int state;

	/* Handle signals. This is useful to intercept accidental Ctrl+C
	 * which would otherwise just kill the process without any cleanup.
	 * This could also be useful when the process is managed by some
	 * other program, e.g. systemD.
	 * - SIGINT will be send by pressing Ctrl+C
	 * - SIGTERM will be send by process managers, e.g. systemD
	 *   wishing to stop the process
	 *
	 * Windows has its own ctrl handlers, we only really care about
	 * Ctrl+C, but others could be implemented as well (see above).
	 */
#ifdef POSIX
	struct sigaction sa, osa;
	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = &stop_program;
	sigaction(SIGINT, &sa, &osa);
	sigaction(SIGTERM, &sa, &osa);
#else
	if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE)) {
		log_error("Control handler could not be installed, Ctrl+C won't work");
	}
#endif

	/* initiate the logfile and start logging */
	state = log_init();
	if (state != 0) {
		/*
		 * if creating a logfile fails we have to terminate the program.
		 * The error message then has to go directly to the screen
		 */
		printf("creating a logfile failed. Program is aborting...\n");
		stop_program(state);
		return state;
	}

	/*
	 * set default values, read config file and process cli arguments,
	 * which override settings in the config file
	 */
	config.dHistMinInterval = 350;
	config.dHistPercentage = 5;
	config.dInterFrameDelay = 10;
	config.dBufferlength = 1376256;

	state = load_config("configurations//SO2Config.conf", &config);
	if (state != 0) {
		log_error("loading configuration failed");
		stop_program(1);
		return 1;
	}

	state = process_cli_arguments(argc, argv, &config);
	if (state != 0) {
		log_error("Could not handle command line arguments");
		return state;
	}

	/* Initialise parameter structures */
	structInit(&sParameters_A, &config, 'a');
	structInit(&sParameters_B, &config, 'b');

	/* initialize IO */
	state = io_init(&config);
	if (state != 0) {
		log_error("io_init failed");
		stop_program(1);
		return state;
	}

	/* init filterwheel */
	state = filterwheel_init(&config);
	if (state != 0) {
		log_error("failed to initialize filterwheel");
		stop_program(1);
		return state;
	}
	log_message("filterwheel initialized");

	/* open filterwheel */
	state = filterwheel_send(FILTERWHEEL_OPENED_A);
	if (state != 0) {
		/* this is critical if this function fails no camera handle is returned */
		log_error("failed to open filterwheel");
		stop_program(1);
		return state;
	}
	log_message("filterwheel opened");

	/* initiate camera */
	state = camera_init(&sParameters_A);
	if (state != 0) {
		/* this is critical if this function fails no camera handle is returned */
		log_error("camera_init for Camera A failed");
		stop_program(1);
		return state;
	}
	log_message("camera A initialized");

	state = camera_init(&sParameters_B);
	if (state != 0) {
		/* this is critical if this function fails no camera handle is returned */
		log_error("camera_init for Camera B failed");
		stop_program(1);
		return state;
	}
	log_message("camera B initialized");

	/* configure camera */
	state = camera_config(&sParameters_A);
	if (state != 0) {
		log_error("config camera A failed");
		stop_program(1);
		return 1;
	}
	log_message("camera A configured");

	state = camera_config(&sParameters_B);
	if (state != 0) {
		log_error("config camera B failed");
		stop_program(1);
		return 1;
	}
	log_message("camera B configured");

	/* set exposure */
	state = setExposureTime(&sParameters_A, &config);
	if (state != 0) {
		log_error("setExposureTime for cam B failed");
		stop_program(1);
		return 1;
	}
	log_message("exposure time for cam A set");

	state = setExposureTime(&sParameters_B, &config);
	if (state != 0) {
		log_error("setExposureTime for cam B failed");
		stop_program(1);
		return 1;
	}
	log_message("exposure time for cam B set");

	/*
	 * Starting the acquisition with the exposure parameter set in
	 * configurations.c and exposureTimeControl.c
	 */
	state = startAquisition(&sParameters_A, &sParameters_B, &config);
	log_message("Aquisition stopped");
	if (state != 0) {
		log_error("Aquisition failed");
		stop_program(1);
		return 1;
	}

	/* we're done! */
	stop_program(0);

	return 0;
}