Browse Source

Merge pull request #420 from julianoes/fix_esc_calib

Listen to all consoles plus some more small fixes
sbg
Lorenz Meier 12 years ago
parent
commit
7108c9f475
  1. 39
      src/systemcmds/esc_calib/esc_calib.c

39
src/systemcmds/esc_calib/esc_calib.c

@ -46,6 +46,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <poll.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -83,22 +84,26 @@ usage(const char *reason)
int int
esc_calib_main(int argc, char *argv[]) esc_calib_main(int argc, char *argv[])
{ {
const char *dev = PWM_OUTPUT_DEVICE_PATH; char *dev = PWM_OUTPUT_DEVICE_PATH;
char *ep; char *ep;
bool channels_selected[MAX_CHANNELS] = {false}; bool channels_selected[MAX_CHANNELS] = {false};
int ch; int ch;
int ret; int ret;
char c; char c;
struct pollfd fds;
fds.fd = 0; /* stdin */
fds.events = POLLIN;
if (argc < 2) if (argc < 2)
usage(NULL); usage(NULL);
while ((ch = getopt(argc, argv, "d:")) != EOF) { while ((ch = getopt(argc-1, argv, "d:")) != EOF) {
switch (ch) { switch (ch) {
case 'd': case 'd':
dev = optarg; dev = optarg;
argc=-2; argc-=2;
break; break;
default: default:
@ -106,7 +111,7 @@ esc_calib_main(int argc, char *argv[])
} }
} }
if(argc < 1) { if(argc < 2) {
usage("no channels provided"); usage("no channels provided");
} }
@ -124,11 +129,6 @@ esc_calib_main(int argc, char *argv[])
} }
} }
/* Wait for confirmation */
int console = open("/dev/ttyACM0", O_NONBLOCK | O_RDONLY | O_NOCTTY);
if (!console)
err(1, "failed opening console");
printf("\nATTENTION, please remove or fix propellers before starting calibration!\n" printf("\nATTENTION, please remove or fix propellers before starting calibration!\n"
"\n" "\n"
"Make sure\n" "Make sure\n"
@ -141,21 +141,21 @@ esc_calib_main(int argc, char *argv[])
/* wait for user input */ /* wait for user input */
while (1) { while (1) {
if (read(console, &c, 1) == 1) { ret = poll(&fds, 1, 0);
if (ret > 0) {
read(0, &c, 1);
if (c == 'y' || c == 'Y') { if (c == 'y' || c == 'Y') {
break; break;
} else if (c == 0x03 || c == 0x63 || c == 'q') { } else if (c == 0x03 || c == 0x63 || c == 'q') {
printf("ESC calibration exited\n"); printf("ESC calibration exited\n");
close(console);
exit(0); exit(0);
} else if (c == 'n' || c == 'N') { } else if (c == 'n' || c == 'N') {
printf("ESC calibration aborted\n"); printf("ESC calibration aborted\n");
close(console);
exit(0); exit(0);
} else { } else {
printf("Unknown input, ESC calibration aborted\n"); printf("Unknown input, ESC calibration aborted\n");
close(console);
exit(0); exit(0);
} }
} }
@ -187,13 +187,15 @@ esc_calib_main(int argc, char *argv[])
} }
} }
if (read(console, &c, 1) == 1) { ret = poll(&fds, 1, 0);
if (ret > 0) {
read(0, &c, 1);
if (c == 13) { if (c == 13) {
break; break;
} else if (c == 0x03 || c == 0x63 || c == 'q') { } else if (c == 0x03 || c == 0x63 || c == 'q') {
warnx("ESC calibration exited"); warnx("ESC calibration exited");
close(console);
exit(0); exit(0);
} }
} }
@ -218,13 +220,15 @@ esc_calib_main(int argc, char *argv[])
} }
} }
if (read(console, &c, 1) == 1) { ret = poll(&fds, 1, 0);
if (ret > 0) {
read(0, &c, 1);
if (c == 13) { if (c == 13) {
break; break;
} else if (c == 0x03 || c == 0x63 || c == 'q') { } else if (c == 0x03 || c == 0x63 || c == 'q') {
printf("ESC calibration exited\n"); printf("ESC calibration exited\n");
close(console);
exit(0); exit(0);
} }
} }
@ -234,7 +238,6 @@ esc_calib_main(int argc, char *argv[])
printf("ESC calibration finished\n"); printf("ESC calibration finished\n");
close(console);
exit(0); exit(0);
} }

Loading…
Cancel
Save