px4io test and fmu test now work over USB as well

This commit is contained in:
Julian Oes
2013-09-22 17:23:43 +02:00
parent 07f82efe9b
commit 166dba09de
2 changed files with 17 additions and 13 deletions
+10 -7
View File
@@ -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);
+7 -6
View File
@@ -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);
} }
} }