aboutsummaryrefslogtreecommitdiff
path: root/src/systemcmds
diff options
context:
space:
mode:
authorJulian Oes <julian@oes.ch>2013-10-11 10:48:49 +0200
committerJulian Oes <julian@oes.ch>2013-10-11 10:48:49 +0200
commit9cd3c40606f023a7943b1418a748abb046e36ecb (patch)
treeebe00440628f40f3764b31f09a6e1ec4ab4735a9 /src/systemcmds
parent6b079f41b27442d2efbe5467be2be0d8607b6746 (diff)
downloadpx4-firmware-9cd3c40606f023a7943b1418a748abb046e36ecb.tar.gz
px4-firmware-9cd3c40606f023a7943b1418a748abb046e36ecb.tar.bz2
px4-firmware-9cd3c40606f023a7943b1418a748abb046e36ecb.zip
Set the PWM values only once or continuous if specified
Diffstat (limited to 'src/systemcmds')
-rw-r--r--src/systemcmds/pwm/pwm.c63
1 files changed, 40 insertions, 23 deletions
diff --git a/src/systemcmds/pwm/pwm.c b/src/systemcmds/pwm/pwm.c
index 25f8c4e75..b3975de9d 100644
--- a/src/systemcmds/pwm/pwm.c
+++ b/src/systemcmds/pwm/pwm.c
@@ -72,7 +72,7 @@ usage(const char *reason)
warnx("%s", reason);
errx(1,
"usage:\n"
- "pwm arm|disarm|rate|min|max|disarmed|test|info ...\n"
+ "pwm arm|disarm|rate|min|max|disarmed|set|info ...\n"
"\n"
" arm Arm output\n"
" disarm Disarm output\n"
@@ -91,10 +91,11 @@ usage(const char *reason)
" [-a] Configure all outputs\n"
" -p <pwm value> PWM value\n"
"\n"
- " test ... Directly set PWM values\n"
+ " set ... 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"
@@ -113,6 +114,7 @@ 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;
@@ -125,7 +127,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:")) != EOF) {
+ while ((ch = getopt(argc-1, &argv[1], "d:vc:g:m:ap:r:e")) != EOF) {
switch (ch) {
case 'd':
@@ -182,6 +184,9 @@ pwm_main(int argc, char *argv[])
if (*ep != '\0')
usage("bad alternative rate provided");
break;
+ case 'e':
+ repeated_pwm_output = true;
+ break;
default:
break;
}
@@ -357,7 +362,7 @@ pwm_main(int argc, char *argv[])
}
exit(0);
- } else if (!strcmp(argv[1], "test")) {
+ } else if (!strcmp(argv[1], "set")) {
if (set_mask == 0) {
usage("no channels set");
@@ -367,14 +372,38 @@ pwm_main(int argc, char *argv[])
/* perform PWM output */
- /* Open console directly to grab CTRL-C signal */
- struct pollfd fds;
- fds.fd = 0; /* stdin */
- fds.events = POLLIN;
+ if (repeated_pwm_output) {
+
+ /* 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) {
- while (1) {
+ read(0, &c, 1);
+ if (c == 0x03 || c == 0x63 || c == 'q') {
+ warnx("User abort\n");
+ exit(0);
+ }
+ }
+ }
+ } else {
+ /* only set the values once */
for (unsigned i = 0; i < servo_count; i++) {
if (set_mask & 1<<i) {
ret = ioctl(fd, PWM_SERVO_SET(i), pwm_value);
@@ -382,18 +411,6 @@ 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);
@@ -476,7 +493,7 @@ pwm_main(int argc, char *argv[])
exit(0);
}
- usage("specify arm|disarm|rate|min|max|disarmed|test|info");
+ usage("specify arm|disarm|rate|min|max|disarmed|set|info");
return 0;
}