示例#1
0
文件: trivia.c 项目: smipi1/onion
int lamp_control_task(char *device)
{
	int fd;
	fd = open(device, O_RDWR);
	if(fd == -1) {
		printf("error: open lamp device (%s): %s\n", device, strerror(errno));
		exit(1);
	}
	if(setup_device_for_lamp(fd, device) == -1) {
		printf("error: setup_device_for_lamp(%s): %s\n", device, strerror(errno));
		exit(1);
	}
	tcflush(fd, TCIOFLUSH);
	reset_to_factory_test(fd);
	while(1) {
		char *frame;
		static int color_init_attempts = 0;
		int size;
		if((size = get_frame(fd, device, &frame)) == -1) {
			printf("error: get_frame(%s): %s\n", device, strerror(errno));
			return 1;
		}
		if(!size) {
			printf("lamp timeout: re-establishing comms\n");
			reset_to_factory_test(fd);
			continue;
		}
#ifdef VERBOSE_COMMS
		printf("rx:[%s]\n", frame);
#endif
		if(strcmp("TH,Ready,0", frame) == 0) {
			sleep(1);
			init_color_test(fd);
			color_init_attempts++;
		} else if((strcmp("SYS,Error,Incorrect format", frame) == 0) ||
				  (strcmp("SYS,Error,Unknown component", frame) == 0)) {
			if((color_init_attempts > 0) && (color_init_attempts < 5)) {
				init_color_test(fd);
				color_init_attempts++;
			} else {
				color_init_attempts = 0;
				reset_to_factory_test(fd);
			}
		} else if(strcmp("ColorTest,Init,0", frame) == 0) {
			printf("lamp initialized: sending colors\n");
			send_colors(fd);
		} else if(strcmp("ColorTest,SetDutyCycles,0", frame) == 0) {
			send_colors(fd);
			fade_colors();
			usleep(33333);
		} else if(strstr(frame, "ColorTest") != NULL) {
			reset_to_factory_test(fd);
		}
	}
	return 1;
}
示例#2
0
int main(void)
{
	int i;

	struct color colors[COLOR_COUNT];

	clock_setup();
	gpio_setup();

	reset_colors(colors, COLOR_COUNT);
	init_colors(colors, COLOR_COUNT);

	while (1) {
		gpio_toggle(GPIOC, GPIO12);	/* LED on/off */

		send_colors(colors, COLOR_COUNT);

		step_colors(colors, COLOR_COUNT);

		for (i = 0; i < 1000000; i++)	/* Wait a bit. */
			__asm__("nop");
	}

	return 0;
}