cam_time2.c

来自「足球机器人自动程序」· C语言 代码 · 共 57 行

C
57
字号
#include "cam.h"#include <sys/poll.h>#include <sys/time.h>#include <time.h>int main() {	struct timeval tv, tvo;	double t;	struct cam c1, c2;	cam_init(&c1, 0);	cam_init(&c2, 1);	gettimeofday(&tvo, NULL);	cam_capture(&c1);	cam_capture(&c2);	struct pollfd ufds[2] = {{c1.fd, POLLIN},{c2.fd, POLLIN}};	int i = 0;	for (; i<300; ++i) {		if (poll(ufds, 2, -1) <= 0) {			fprintf(stderr, "poll error\n");			return -1;		}		if (ufds[0].revents & POLLIN) {			cam_sync(&c1);			gettimeofday(&tv, NULL);			t = tv.tv_sec - tvo.tv_sec;			t += (double)(tv.tv_usec - tvo.tv_usec) / 1e6;			tvo = tv;			printf("%f\t", t);			cam_capture(&c1);		}		if (ufds[1].revents & POLLIN) {			cam_sync(&c2);			gettimeofday(&tv, NULL);			t = tv.tv_sec - tvo.tv_sec;			t += (double)(tv.tv_usec - tvo.tv_usec) / 1e6;			tvo = tv;			printf("%f\n", t);			cam_capture(&c2);		}	}	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?