diff --git a/conf/boards/ardrone2_raw.makefile b/conf/boards/ardrone2_raw.makefile index 6166a3e2ef..633bad948f 100644 --- a/conf/boards/ardrone2_raw.makefile +++ b/conf/boards/ardrone2_raw.makefile @@ -43,6 +43,9 @@ $(TARGET).CFLAGS += -DUART1_DEV=\"/dev/ttyUSB0\" # for distinction between RAW and SDK version $(TARGET).CFLAGS +=-DARDRONE2_RAW +# handle linux signals by hand +$(TARGET).CFLAGS += -DUSE_LINUX_SIGNAL + # ----------------------------------------------------------------------- # default LED configuration diff --git a/conf/boards/bebop.makefile b/conf/boards/bebop.makefile index 1c12666850..37c3118282 100644 --- a/conf/boards/bebop.makefile +++ b/conf/boards/bebop.makefile @@ -29,6 +29,9 @@ GPS_PORT ?= UART1 GPS_BAUD ?= B230400 $(TARGET).CFLAGS += -DUART1_DEV=\"/dev/ttyPA1\" +# handle linux signals by hand +$(TARGET).CFLAGS += -DUSE_LINUX_SIGNAL + # ----------------------------------------------------------------------- # default LED configuration diff --git a/sw/airborne/arch/linux/mcu_arch.c b/sw/airborne/arch/linux/mcu_arch.c index 5a8f012bd6..b56aaf53d7 100644 --- a/sw/airborne/arch/linux/mcu_arch.c +++ b/sw/airborne/arch/linux/mcu_arch.c @@ -29,4 +29,46 @@ #include "mcu_arch.h" +#if USE_LINUX_SIGNAL + +/** + * Handle linux signals by hand if the program is not launch + * by a shell already doing it + */ + +#include +#include +#include + +/** + * catch SIGINT signal two times to stop the main program + */ +static void sig_handler(int signo) +{ + static int nb_signal = 0; + + if (signo == SIGINT) { + printf("Received SIGINT\n"); + if (nb_signal == 0) { + printf("Press Ctrl-C again to stop the program\n"); + nb_signal++; + } else { + printf("Leaving now\n"); + exit(0); + } + } +} + +void mcu_arch_init(void) +{ + if (signal(SIGINT, sig_handler) == SIG_ERR) { + printf("Can't catch SIGINT\n"); + } +} + +#else + void mcu_arch_init(void) { } + +#endif +