Exemplo n.º 1
0
static void os_delay(void)
{
	double delay_time;
	target_clock_t start, stop;

	target_yield();

	delay_time = adv_measure_step(os_wait, 0.0001, 0.2, 7);

	if (delay_time > 0) {
		log_std(("os: sleep granularity %g\n", delay_time));
		target_usleep_granularity(delay_time * 1000000);
	} else {
		log_std(("ERROR:os: sleep granularity NOT measured\n"));
		target_usleep_granularity(20000 /* 20 ms */);
	}

	target_yield();

	start = target_clock();
	stop = target_clock();
	while (stop == start)
		stop = target_clock();

	log_std(("os: clock granularity %g\n", (stop - start) / (double)TARGET_CLOCKS_PER_SEC));
}
Exemplo n.º 2
0
void run(void)
{
	target_clock_t last;

	printf("Press ESC or Break to exit\n\r");

	signal(SIGINT, sigint);

	last = target_clock();

	while (!done) {

		if (inputb_hit()) {
			unsigned k;

			target_clock_t current = target_clock();
			double period = (current - last) * 1000.0 / TARGET_CLOCKS_PER_SEC;

			k = inputb_get();

			last = current;

			if (k > 32 && k < 256)
				printf("(%6.1f ms) %d '%c'\n\r", period, k, (char)k);
			else
				printf("(%6.1f ms) %d\n\r", period, k);

			if (k == 27)
				done = 1;
		}

		os_poll();
		target_yield();
	}
}
Exemplo n.º 3
0
void run(void)
{
	char msg[1024];
	char new_msg[1024];
	int i, j, k;
	target_clock_t last;

	printf("Press Break to exit\n");

	signal(SIGINT, sigint);

	last = target_clock();
	msg[0] = 0;
	while (!done) {

		new_msg[0] = 0;
		for (i = 0; i < joystickb_count_get(); ++i) {

			if (i != 0)
				sncat(new_msg, sizeof(new_msg), "\n");

			snprintf(new_msg + strlen(new_msg), sizeof(new_msg) - strlen(new_msg), "joy %d, [", i);
			for (j = 0; j < joystickb_button_count_get(i); ++j) {
				if (joystickb_button_get(i, j))
					sncat(new_msg, sizeof(new_msg), "_");
				else
					sncat(new_msg, sizeof(new_msg), "-");
			}
			sncat(new_msg, sizeof(new_msg), "], ");
			for (j = 0; j < joystickb_stick_count_get(i); ++j) {
				for (k = 0; k < joystickb_stick_axe_count_get(i, j); ++k) {
					char digital;
					if (joystickb_stick_axe_digital_get(i, j, k, 0))
						digital = '\\';
					else if (joystickb_stick_axe_digital_get(i, j, k, 1))
						digital = '/';
					else
						digital = '-';
					sncatf(new_msg, sizeof(new_msg), " %d/%d [%6d %c]", j, k, joystickb_stick_axe_analog_get(i, j, k), digital);
				}
			}

			sncat(new_msg, sizeof(new_msg), " [");

			for (j = 0; j < joystickb_rel_count_get(i); ++j) {
				if (j != 0)
					sncat(new_msg, sizeof(new_msg), "/");
				sncatf(new_msg, sizeof(new_msg), "%d", joystickb_rel_get(i, j));
			}

			sncat(new_msg, sizeof(new_msg), "]");
		}

		if (strcmp(msg, new_msg) != 0) {
			target_clock_t current = target_clock();
			double period = (current - last) * 1000.0 / TARGET_CLOCKS_PER_SEC;
			last = current;
			sncpy(msg, sizeof(msg), new_msg);
			printf("%s (%4.0f ms)\n", msg, period);
		}

		os_poll();
		joystickb_poll();
		target_yield();
	}
}