ardupilot/libraries/Desktop/support/main.cpp

85 lines
1.4 KiB
C++
Raw Normal View History

#include <stdio.h>
2011-10-09 06:41:03 -03:00
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sched.h>
#include <wiring.h>
#include <getopt.h>
#include <signal.h>
2011-10-29 22:40:54 -03:00
#include "desktop.h"
void setup(void);
void loop(void);
// the state of the desktop simulation
struct desktop_state desktop_state;
static void usage(void)
{
printf("Options:\n");
printf("\t-s enable CLI slider switch\n");
printf("\t-w wipe eeprom and dataflash\n");
}
void sig_alarm(int sig)
{
printf("alarm signal in desktop emulation - loop not running\n");
exit(1);
}
int main(int argc, char * const argv[])
{
int opt;
// default state
desktop_state.slider = false;
gettimeofday(&desktop_state.sketch_start_time, NULL);
while ((opt = getopt(argc, argv, "swh")) != -1) {
switch (opt) {
case 's':
desktop_state.slider = true;
break;
case 'w':
unlink("eeprom.bin");
unlink("dataflash.bin");
break;
default:
usage();
exit(1);
}
}
signal(SIGALRM, sig_alarm);
alarm(5);
// run main setup() function from sketch
setup();
2011-10-09 06:41:03 -03:00
while (true) {
struct timeval tv;
2011-10-29 22:40:54 -03:00
fd_set fds;
int fd_high = 0;
alarm(5);
2011-10-29 22:40:54 -03:00
FD_ZERO(&fds);
2011-11-09 01:15:28 -04:00
FD_SET(0, &fds);
2011-10-09 06:41:03 -03:00
loop();
2011-10-29 22:40:54 -03:00
desktop_serial_select_setup(&fds, &fd_high);
tv.tv_sec = 0;
tv.tv_usec = 100;
2011-11-09 01:15:28 -04:00
if (select(fd_high+1, &fds, NULL, NULL, &tv) > 0 &&
FD_ISSET(0, &fds)) {
char c;
if (read(0, &c, 1) != 1) {
// EOF on stdin
exit(1);
}
}
2011-10-09 06:41:03 -03:00
}
return 0;
}