예제 #1
0
int
	main(
		int argc,
const char ** argv
	)
{
	int width = 64;
	int height = 64;

	ledscape_config_t * config = &ledscape_matrix_default;
	if (argc > 1)
	{
		config = ledscape_config(argv[1]);
		if (!config)
			return EXIT_FAILURE;
	}

	if (config->type == LEDSCAPE_MATRIX)
	{
		config->matrix_config.width = width;
		config->matrix_config.height = height;
	}

	ledscape_t * const leds = ledscape_init(config, 0);

	printf("init done\n");
	time_t last_time = time(NULL);
	unsigned last_i = 0;

	unsigned i = 0;
	uint32_t * const p = calloc(width*height,4);

	render_game(p);

	i++;
	ledscape_draw(leds, p);

	usleep(20000);

	// wait for the previous frame to finish;
	//const uint32_t response = ledscape_wait(leds);
	const uint32_t response = 0;
	time_t now = time(NULL);
	if (now != last_time)
	{
		printf("%d fps. starting %d previous %"PRIx32"\n",
		i - last_i, i, response);
		last_i = i;
		last_time = now;
	}

	printf("init done\n");
	ledscape_close(leds);

	return EXIT_SUCCESS;
}
예제 #2
0
int
main(
	int argc,
	char ** argv
)
{
	ledscape_t * const leds = ledscape_init(width, height);


	printf("init done\n");
	time_t last_time = time(NULL);
	unsigned last_i = 0;

	unsigned i = 0;
	uint32_t * const p = calloc(width*height,4);
	int scroll_x = 128;
	memset(p, 0x10, width*height*4);

	for (int x = 0 ; x < 128 ; x += 32)
	{
		for (int y = 0 ; y < 128 ; y += 16)
		{
			char buf[32];
			snprintf(buf, sizeof(buf), "%d,%d", x, y);
			font_write(p, 0xFF0000, x, y, buf);
		}
	}

	while (1)
	{
		ledscape_draw(leds, p);
		usleep(20000);

		// wait for the previous frame to finish;
		//const uint32_t response = ledscape_wait(leds);
		const uint32_t response = 0;
		time_t now = time(NULL);
		if (now != last_time)
		{
			printf("%d fps. starting %d previous %"PRIx32"\n",
				i - last_i, i, response);
			last_i = i;
			last_time = now;
		}

	}

	ledscape_close(leds);

	return EXIT_SUCCESS;
}
예제 #3
0
int
main(
	int argc,
	char ** argv
)
{
	uint16_t port = 9999;
	uint16_t num_pixels = 256;
	uint16_t num_strips = LEDSCAPE_NUM_STRIPS;

	extern char *optarg;
	int opt;
	while ((opt = getopt(argc, argv, "p:c:d:")) != -1)
	{
		switch (opt)
		{
		case 'p':
			port = atoi(optarg);
			break;
		case 'c':
			num_pixels = atoi(optarg);
			break;
		case 'd': {
			int width=0, height=0;

			if (sscanf(optarg,"%dx%d", &width, &height) == 2) {
				num_pixels = width * height;
			} else {
				printf("Invalid argument for -d; expected NxN; actual: %s", optarg);
				exit(EXIT_FAILURE);
			}
		}
		break;
		default:
			fprintf(stderr, "Usage: %s [-p <port>] [-c <led_count> | -d <width>x<height>]\n", argv[0]);
			exit(EXIT_FAILURE);
		}
	}

	const int sock = socket(AF_INET, SOCK_DGRAM, 0);
	struct sockaddr_in addr = {
		.sin_family = AF_INET,
		.sin_addr.s_addr = INADDR_ANY,
		.sin_port = htons(port),
	};

	if (sock < 0)
		die("socket failed: %s\n", strerror(errno));

	if (bind(sock, (const struct sockaddr*) &addr, sizeof(addr)) < 0)
		die("bind port %d failed: %s\n", port, strerror(errno));

	ledscape_t * const leds = ledscape_init(num_pixels);

	fprintf(stderr, "Started LEDscape UDP receiver on port %d for %d pixels\n", port, num_pixels);
	fprintf(stderr, "WARNING: udp-rx is deprecated! opc-rx supports more options and should be used instead.\n\n");

	unsigned frame_num = 0;

	uint8_t buf[num_pixels * num_strips * 4];

	time_t last_time = time(NULL);
	int fps_counter=0;
	while (1)
	{
		const ssize_t rc = recv(sock, buf, sizeof(buf), 0);
		if (rc < 0) {
			printf("recv failed: %s\n", strerror(errno));
			continue;
		}

		ledscape_frame_t * const frame
			= ledscape_frame(leds, frame_num);

		for(uint16_t x=0 ; x < num_pixels ; x++)
		{
			for(uint16_t strip = 0 ; strip < num_strips ; strip++)
			{
				const uint8_t r = buf[strip*num_pixels*3 + x*3 + 0];
				const uint8_t g = buf[strip*num_pixels*3 + x*3 + 1];
				const uint8_t b = buf[strip*num_pixels*3 + x*3 + 2];
				ledscape_set_color(frame, strip, x, r, g, b);
			}
		}

		ledscape_wait(leds);
		ledscape_draw(leds, frame_num);

		time_t now = time(NULL);

		if (now != last_time)
		{
			printf("%d fps\n", fps_counter);
			last_time = now;
			fps_counter = 0;
		}
		fps_counter++;


		frame_num = (frame_num+1) % 2;
	}

	ledscape_close(leds);
	return 0;
}
예제 #4
0
int
main(
	int argc,
	char ** argv
)
{
	const int width = 256;
	const int height = 128;

	ledscape_config_t * config = &ledscape_matrix_default;
	if (argc > 1)
	{
		config = ledscape_config(argv[1]);
		if (!config)
			return EXIT_FAILURE;
	}

	if (config->type == LEDSCAPE_MATRIX)
	{
		config->matrix_config.width = width;
		config->matrix_config.height = height;
	}

	ledscape_t * const leds = ledscape_init(config, 0);

	//printf("init done %d,%d\n", width, height);
	time_t last_time = time(NULL);
	unsigned last_i = 0;

	unsigned i = 0;
	uint32_t * const p = calloc(width*height,4);
	int scroll_x = 128;
	memset(p, 0x10, width*height*4);

	for (int i = 0 ; i < 8 ; i++)
	{
		for (int j = 0 ; j < 8 ; j++)
		{
			ledscape_printf(
				&p[8+j*32 + width*i*16],
				width,
				0xFF0000, // red
				"%d-%d",
				i,
				j
			);
			ledscape_printf(
				&p[1+j*32 + width*i*16],
				width,
				0x00FF00, // green
				"^"
			);
			ledscape_printf(
				&p[1+j*32 + width*(i*16+8)],
				width,
				0x0000FF, // blue
				"|"
			);
			p[j*32+width*i*16] = 0xFFFF00;
		}
	}

	while (1)
	{
		ledscape_draw(leds, p);
		usleep(20000);

		// wait for the previous frame to finish;
		//const uint32_t response = ledscape_wait(leds);
		const uint32_t response = 0;
		time_t now = time(NULL);
		if (now != last_time)
		{
			printf("%d fps. starting %d previous %"PRIx32"\n",
				i - last_i, i, response);
			last_i = i;
			last_time = now;
		}

	}

	ledscape_close(leds);

	return EXIT_SUCCESS;
}