diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2013-09-22 13:11:01 -0700 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2013-09-22 13:11:01 -0700 |
commit | e7bc322b2d749aa840ca05d589f89ee5e276bda9 (patch) | |
tree | 2d36062431232d678755e9c6466cb08a65271312 /src | |
parent | 7108c9f475c27c687dbef2532a673e990afbc918 (diff) | |
parent | 166dba09de38642ec656d857e225c08d9a36fc72 (diff) | |
download | px4-firmware-e7bc322b2d749aa840ca05d589f89ee5e276bda9.tar.gz px4-firmware-e7bc322b2d749aa840ca05d589f89ee5e276bda9.tar.bz2 px4-firmware-e7bc322b2d749aa840ca05d589f89ee5e276bda9.zip |
Merge pull request #421 from julianoes/fix_console_input
px4io test and fmu test now work over USB as well
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/px4fmu/fmu.cpp | 17 | ||||
-rw-r--r-- | src/drivers/px4io/px4io.cpp | 13 |
2 files changed, 17 insertions, 13 deletions
diff --git a/src/drivers/px4fmu/fmu.cpp b/src/drivers/px4fmu/fmu.cpp index 6d4019f24..b1dd55dd7 100644 --- a/src/drivers/px4fmu/fmu.cpp +++ b/src/drivers/px4fmu/fmu.cpp @@ -1096,10 +1096,11 @@ fmu_start(void) void test(void) { - int fd; + int fd; unsigned servo_count = 0; unsigned pwm_value = 1000; int direction = 1; + int ret; fd = open(PX4FMU_DEVICE_PATH, O_RDWR); @@ -1114,9 +1115,9 @@ test(void) warnx("Testing %u servos", (unsigned)servo_count); - int console = open("/dev/console", O_NONBLOCK | O_RDONLY | O_NOCTTY); - if (!console) - err(1, "failed opening console"); + struct pollfd fds; + fds.fd = 0; /* stdin */ + fds.events = POLLIN; warnx("Press CTRL-C or 'c' to abort."); @@ -1166,15 +1167,17 @@ test(void) /* Check if user wants to quit */ char c; - if (read(console, &c, 1) == 1) { - if (c == 0x03 || c == 0x63) { + ret = poll(&fds, 1, 0); + if (ret > 0) { + + read(0, &c, 1); + if (c == 0x03 || c == 0x63 || c == 'q') { warnx("User abort\n"); break; } } } - close(console); close(fd); exit(0); diff --git a/src/drivers/px4io/px4io.cpp b/src/drivers/px4io/px4io.cpp index 952453a8c..133646051 100644 --- a/src/drivers/px4io/px4io.cpp +++ b/src/drivers/px4io/px4io.cpp @@ -2131,10 +2131,9 @@ test(void) if (ioctl(fd, PWM_SERVO_ARM, 0)) err(1, "failed to arm servos"); - /* Open console directly to grab CTRL-C signal */ - int console = open("/dev/console", O_NONBLOCK | O_RDONLY | O_NOCTTY); - if (!console) - err(1, "failed opening console"); + struct pollfd fds; + fds.fd = 0; /* stdin */ + fds.events = POLLIN; warnx("Press CTRL-C or 'c' to abort."); @@ -2175,10 +2174,12 @@ test(void) /* Check if user wants to quit */ char c; - if (read(console, &c, 1) == 1) { + ret = poll(&fds, 1, 0); + if (ret > 0) { + + read(0, &c, 1); if (c == 0x03 || c == 0x63 || c == 'q') { warnx("User abort\n"); - close(console); exit(0); } } |