Browse Source

Merge pull request #421 from julianoes/fix_console_input

px4io test and fmu test now work over USB as well
sbg
Lorenz Meier 12 years ago
parent
commit
e7bc322b2d
  1. 17
      src/drivers/px4fmu/fmu.cpp
  2. 13
      src/drivers/px4io/px4io.cpp

17
src/drivers/px4fmu/fmu.cpp

@ -1096,10 +1096,11 @@ fmu_start(void)
void void
test(void) test(void)
{ {
int fd; int fd;
unsigned servo_count = 0; unsigned servo_count = 0;
unsigned pwm_value = 1000; unsigned pwm_value = 1000;
int direction = 1; int direction = 1;
int ret;
fd = open(PX4FMU_DEVICE_PATH, O_RDWR); fd = open(PX4FMU_DEVICE_PATH, O_RDWR);
@ -1114,9 +1115,9 @@ test(void)
warnx("Testing %u servos", (unsigned)servo_count); warnx("Testing %u servos", (unsigned)servo_count);
int console = open("/dev/console", O_NONBLOCK | O_RDONLY | O_NOCTTY); struct pollfd fds;
if (!console) fds.fd = 0; /* stdin */
err(1, "failed opening console"); fds.events = POLLIN;
warnx("Press CTRL-C or 'c' to abort."); warnx("Press CTRL-C or 'c' to abort.");
@ -1166,15 +1167,17 @@ test(void)
/* Check if user wants to quit */ /* Check if user wants to quit */
char c; char c;
if (read(console, &c, 1) == 1) { ret = poll(&fds, 1, 0);
if (c == 0x03 || c == 0x63) { if (ret > 0) {
read(0, &c, 1);
if (c == 0x03 || c == 0x63 || c == 'q') {
warnx("User abort\n"); warnx("User abort\n");
break; break;
} }
} }
} }
close(console);
close(fd); close(fd);
exit(0); exit(0);

13
src/drivers/px4io/px4io.cpp

@ -2131,10 +2131,9 @@ test(void)
if (ioctl(fd, PWM_SERVO_ARM, 0)) if (ioctl(fd, PWM_SERVO_ARM, 0))
err(1, "failed to arm servos"); err(1, "failed to arm servos");
/* Open console directly to grab CTRL-C signal */ struct pollfd fds;
int console = open("/dev/console", O_NONBLOCK | O_RDONLY | O_NOCTTY); fds.fd = 0; /* stdin */
if (!console) fds.events = POLLIN;
err(1, "failed opening console");
warnx("Press CTRL-C or 'c' to abort."); warnx("Press CTRL-C or 'c' to abort.");
@ -2175,10 +2174,12 @@ test(void)
/* Check if user wants to quit */ /* Check if user wants to quit */
char c; 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') { if (c == 0x03 || c == 0x63 || c == 'q') {
warnx("User abort\n"); warnx("User abort\n");
close(console);
exit(0); exit(0);
} }
} }

Loading…
Cancel
Save