diff --git a/src/gpio.c b/src/gpio.c index af61d64..994d228 100644 --- a/src/gpio.c +++ b/src/gpio.c @@ -434,16 +434,18 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[]) return 0; } -gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down) +void gpio_force_off(struct EG25Manager *manager) +{ + if (manager->gpio_out[GPIO_OUT_RESET]) { + g_message("Setting the reset pin to ensure the modem stays off"); + gpio_line_set_value(manager, GPIO_OUT_RESET, GPIOD_LINE_VALUE_ACTIVE); + } +} + +gboolean gpio_check_poweroff(struct EG25Manager *manager) { if (manager->gpio_in[GPIO_IN_STATUS] && gpio_line_get_value(manager, GPIO_IN_STATUS) == GPIOD_LINE_VALUE_ACTIVE) { - - if (keep_down && manager->gpio_out[GPIO_OUT_RESET]) { - // Asserting RESET line to prevent modem from rebooting - gpio_line_set_value(manager, GPIO_OUT_RESET, GPIOD_LINE_VALUE_ACTIVE); - } - return TRUE; } diff --git a/src/gpio.h b/src/gpio.h index 50dcdba..256ef60 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -18,4 +18,5 @@ int gpio_sequence_resume(struct EG25Manager *state); int gpio_sequence_wake(struct EG25Manager *state); int gpio_sequence_sleep(struct EG25Manager *state); -gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down); +void gpio_force_off(struct EG25Manager *manager); +gboolean gpio_check_poweroff(struct EG25Manager *manager); diff --git a/src/manager.c b/src/manager.c index 47cbc11..9b13ca2 100644 --- a/src/manager.c +++ b/src/manager.c @@ -62,13 +62,17 @@ static gboolean quit_app(struct EG25Manager *manager) gpio_sequence_shutdown(manager); manager->modem_state = EG25_STATE_FINISHING; for (i = 0; i < 30; i++) { - if (gpio_check_poweroff(manager, TRUE)) + if (gpio_check_poweroff(manager)) { + g_message("Modem successfully powered down"); break; + } sleep(1); } } - g_message("Modem down, quitting..."); + gpio_force_off(manager); + + g_message("Modem down, quitting..."); g_main_loop_quit(manager->loop); return FALSE; @@ -98,7 +102,7 @@ static gboolean modem_start(struct EG25Manager *manager) libusb_free_device_list(devices, 1); libusb_exit(ctx); - } else if (!gpio_check_poweroff(manager, FALSE)) { + } else if (!gpio_check_poweroff(manager)) { g_message("STATUS is low, modem already powered"); should_boot = FALSE; }