From b96c8f447afcd1e62a5ced1c7d443f9e399887de Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 17 Jan 2017 10:30:40 +0100 Subject: [PATCH] posix-like ports: unify sigint handler --- port/libusb/main.c | 9 +++++---- port/posix-h4/main.c | 8 +++++--- port/posix-h5/main.c | 8 +++++--- port/windows-h4/main.c | 12 ++++++++---- port/windows-winusb/main.c | 8 +++++--- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/port/libusb/main.c b/port/libusb/main.c index 92852c9b1..ac90f5e8a 100644 --- a/port/libusb/main.c +++ b/port/libusb/main.c @@ -75,13 +75,14 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack static void sigint_handler(int param){ UNUSED(param); - -#ifndef _WIN32 + + printf("CTRL-C - SIGINT received, shutting down..\n"); + log_info("sigint_handler: shutting down"); + // reset anyway btstack_stdin_reset(); -#endif - log_info(" <= SIGINT received, shutting down..\n"); + // power down hci_power_control(HCI_POWER_OFF); hci_close(); log_info("Good bye, see you.\n"); diff --git a/port/posix-h4/main.c b/port/posix-h4/main.c index 3e9c0c2b1..8ced66009 100644 --- a/port/posix-h4/main.c +++ b/port/posix-h4/main.c @@ -108,13 +108,15 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack } static void sigint_handler(int param){ + UNUSED(param); + + printf("CTRL-C - SIGINT received, shutting down..\n"); + log_info("sigint_handler: shutting down"); -#ifndef _WIN32 // reset anyway btstack_stdin_reset(); -#endif - log_info(" <= SIGINT received, shutting down..\n"); + // power down hci_power_control(HCI_POWER_OFF); hci_close(); log_info("Good bye, see you.\n"); diff --git a/port/posix-h5/main.c b/port/posix-h5/main.c index 2913cef8e..eccb97165 100644 --- a/port/posix-h5/main.c +++ b/port/posix-h5/main.c @@ -79,13 +79,15 @@ static hci_transport_config_uart_t config = { static btstack_packet_callback_registration_t hci_event_callback_registration; static void sigint_handler(int param){ + UNUSED(param); + + printf("CTRL-C - SIGINT received, shutting down..\n"); + log_info("sigint_handler: shutting down"); -#ifndef _WIN32 // reset anyway btstack_stdin_reset(); -#endif - log_info(" <= SIGINT received, shutting down..\n"); + // power down hci_power_control(HCI_POWER_OFF); hci_close(); log_info("Good bye, see you.\n"); diff --git a/port/windows-h4/main.c b/port/windows-h4/main.c index 7372d8467..f82fe85d7 100644 --- a/port/windows-h4/main.c +++ b/port/windows-h4/main.c @@ -46,13 +46,17 @@ void hal_led_toggle(void){ } static void sigint_handler(int param){ + UNUSED(param); - // reset even if not setup before + printf("CTRL-C = SIGINT received, shutting down..\n"); + log_info("sigint_handler: shutting down"); + + // reset anyway btstack_stdin_reset(); - log_info(" <= SIGINT received, shutting down..\n"); - // hci_power_control(HCI_POWER_OFF); - // hci_close(); + // power down + hci_power_control(HCI_POWER_OFF); + hci_close(); log_info("Good bye, see you.\n"); exit(0); } diff --git a/port/windows-winusb/main.c b/port/windows-winusb/main.c index f8ce9cdca..ff809b952 100644 --- a/port/windows-winusb/main.c +++ b/port/windows-winusb/main.c @@ -72,13 +72,15 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack } static void sigint_handler(int param){ + UNUSED(param); + + printf("CTRL-C - SIGINT received, shutting down..\n"); + log_info("sigint_handler: shutting down"); -#ifndef _WIN32 // reset anyway btstack_stdin_reset(); -#endif - log_info(" <= SIGINT received, shutting down..\n"); + // power down hci_power_control(HCI_POWER_OFF); hci_close(); log_info("Good bye, see you.\n");