Ejemplo n.º 1
0
static void cmd_cfg(BaseSequentialStream *chp, int argc, char *argv[])
{
	const char* const command = (argc < 1) ? "" : argv[0];

	if (!strcmp(command, "list")) {
		for (int i = 0;; i++) {
			const char* name = config_name_by_index(i);
			if (!name)
				break;
			const int res = print_param(name, true);
			if (res) {
				lowsyslog("Internal error %i\n", res);
				assert(0);
			}
		}
	}
	else if (!strcmp(command, "save") || !strcmp(command, "erase")) {
		if (motor_is_idle()) {
			const bool save = !strcmp(command, "save");
			print_status((save ? config_save : config_erase)());
		} else {
			puts("I'm sorry Dave, I'm afraid I can't do that");
		}
	}
	else if (!strcmp(command, "get")) {
		if (argc < 2) {
			puts("Error: Not enough arguments");
			return;
		}
		const int ret = print_param(argv[1], false);
		if (ret)
			print_status(ret);
	}
	else if (!strcmp(command, "set")) {
		if (argc < 3) {
			puts("Error: Not enough arguments");
			return;
		}
		const char* const name = argv[1];
		const float value = atoff(argv[2]);
		const int res = config_set(name, value);
		if (res == 0)
			print_param(name, false);
		print_status(res);
	}
	else {
		puts("Usage:\n"
			"  cfg list\n"
			"  cfg save\n"
			"  cfg erase\n"
			"  cfg get <name>\n"
			"  cfg set <name> <value>");
	}
}
Ejemplo n.º 2
0
static void cmd_startstop(BaseSequentialStream *chp, int argc, char *argv[])
{
	static const int TTL_MS = 5000;

	if (argc == 0) {
		motor_stop();
		puts("Usage:\n"
			"  startstop <number of cycles> [duty cycle = 0.1]");
		return;
	}

	motor_stop();

	const int num_cycles = (int)atoff(argv[0]);
	const float dc = (argc > 1) ? atoff(argv[1]) : 0.1;

	int current_cycle = 0;

	for (; current_cycle < num_cycles; current_cycle++) {
		printf("Cycle %d of %d, dc %f...\n", current_cycle + 1, num_cycles, dc);

		// Waiting for the motor to spin down
		sleep(3);
		if (!motor_is_idle()) {
			puts("NOT STOPPED");
			break;
		}

		// Starting with the specified duty cycle
		motor_set_duty_cycle(dc, TTL_MS);

		// Checking if started and stopping
		sleep(3);
		if (!motor_is_running()) {
			puts("NOT RUNNING");
			break;
		}

		motor_stop();
	}

	printf("Finished %d cycles of %d\n", current_cycle, num_cycles);
}