Revert "Set the PWM values only once or continuous if specified"

This reverts commit 9cd3c40606.
This commit is contained in:
Julian Oes
2013-10-11 16:33:52 +02:00
parent 2d23d5fd4e
commit 3cbe1ee1a8
+23 -40
View File
@@ -72,7 +72,7 @@ usage(const char *reason)
warnx("%s", reason);
errx(1,
"usage:\n"
"pwm arm|disarm|rate|min|max|disarmed|set|info ...\n"
"pwm arm|disarm|rate|min|max|disarmed|test|info ...\n"
"\n"
" arm Arm output\n"
" disarm Disarm output\n"
@@ -91,11 +91,10 @@ usage(const char *reason)
" [-a] Configure all outputs\n"
" -p <pwm value> PWM value\n"
"\n"
" set ... Directly set PWM values\n"
" test ... Directly set PWM values\n"
" [-c <channels>] Supply channels (e.g. 1234)\n"
" [-m <chanmask> ] Directly supply channel mask (e.g. 0xF)\n"
" [-a] Configure all outputs\n"
" [-e] Repeat setting the values until stopped\n"
" -p <pwm value> PWM value\n"
"\n"
" info Print information about the PWM device\n"
@@ -114,7 +113,6 @@ pwm_main(int argc, char *argv[])
uint32_t alt_channel_groups = 0;
bool alt_channels_set = false;
bool print_verbose = false;
bool repeated_pwm_output = false;
int ch;
int ret;
char *ep;
@@ -127,7 +125,7 @@ pwm_main(int argc, char *argv[])
if (argc < 1)
usage(NULL);
while ((ch = getopt(argc-1, &argv[1], "d:vc:g:m:ap:r:e")) != EOF) {
while ((ch = getopt(argc-1, &argv[1], "d:vc:g:m:ap:r:")) != EOF) {
switch (ch) {
case 'd':
@@ -184,9 +182,6 @@ pwm_main(int argc, char *argv[])
if (*ep != '\0')
usage("bad alternative rate provided");
break;
case 'e':
repeated_pwm_output = true;
break;
default:
break;
}
@@ -362,7 +357,7 @@ pwm_main(int argc, char *argv[])
}
exit(0);
} else if (!strcmp(argv[1], "set")) {
} else if (!strcmp(argv[1], "test")) {
if (set_mask == 0) {
usage("no channels set");
@@ -372,38 +367,14 @@ pwm_main(int argc, char *argv[])
/* perform PWM output */
if (repeated_pwm_output) {
/* Open console directly to grab CTRL-C signal */
struct pollfd fds;
fds.fd = 0; /* stdin */
fds.events = POLLIN;
/* Open console directly to grab CTRL-C signal */
struct pollfd fds;
fds.fd = 0; /* stdin */
fds.events = POLLIN;
warnx("Press CTRL-C or 'c' to abort.");
warnx("Press CTRL-C or 'c' to abort.");
while (1) {
for (unsigned i = 0; i < servo_count; i++) {
if (set_mask & 1<<i) {
ret = ioctl(fd, PWM_SERVO_SET(i), pwm_value);
if (ret != OK)
err(1, "PWM_SERVO_SET(%d)", i);
}
}
/* abort on user request */
char c;
ret = poll(&fds, 1, 0);
if (ret > 0) {
read(0, &c, 1);
if (c == 0x03 || c == 0x63 || c == 'q') {
warnx("User abort\n");
exit(0);
}
}
}
} else {
/* only set the values once */
while (1) {
for (unsigned i = 0; i < servo_count; i++) {
if (set_mask & 1<<i) {
ret = ioctl(fd, PWM_SERVO_SET(i), pwm_value);
@@ -411,6 +382,18 @@ pwm_main(int argc, char *argv[])
err(1, "PWM_SERVO_SET(%d)", i);
}
}
/* abort on user request */
char c;
ret = poll(&fds, 1, 0);
if (ret > 0) {
read(0, &c, 1);
if (c == 0x03 || c == 0x63 || c == 'q') {
warnx("User abort\n");
exit(0);
}
}
}
exit(0);
@@ -493,7 +476,7 @@ pwm_main(int argc, char *argv[])
exit(0);
}
usage("specify arm|disarm|rate|min|max|disarmed|set|info");
usage("specify arm|disarm|rate|min|max|disarmed|test|info");
return 0;
}