mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 15:22:20 +02:00
manager: always set the reset line when exiting
This splits the logic from gpio_check_poweroff into two separate functions, allowing the caller more control over when the reset line is asserted to force the modem to turn off. Previously if the modem didn't respond to the power key sequence in quit_app, gpio_check_poweroff wouldn't set the reset pin, and eg25-manager could leave the modem running after exiting.
This commit is contained in:
16
src/gpio.c
16
src/gpio.c
@@ -434,16 +434,18 @@ int gpio_init(struct EG25Manager *manager, toml_table_t *config[])
|
|||||||
return 0;
|
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] &&
|
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
||||||
gpio_line_get_value(manager, GPIO_IN_STATUS) == GPIOD_LINE_VALUE_ACTIVE) {
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,4 +18,5 @@ int gpio_sequence_resume(struct EG25Manager *state);
|
|||||||
int gpio_sequence_wake(struct EG25Manager *state);
|
int gpio_sequence_wake(struct EG25Manager *state);
|
||||||
int gpio_sequence_sleep(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);
|
||||||
|
@@ -62,13 +62,17 @@ static gboolean quit_app(struct EG25Manager *manager)
|
|||||||
gpio_sequence_shutdown(manager);
|
gpio_sequence_shutdown(manager);
|
||||||
manager->modem_state = EG25_STATE_FINISHING;
|
manager->modem_state = EG25_STATE_FINISHING;
|
||||||
for (i = 0; i < 30; i++) {
|
for (i = 0; i < 30; i++) {
|
||||||
if (gpio_check_poweroff(manager, TRUE))
|
if (gpio_check_poweroff(manager)) {
|
||||||
|
g_message("Modem successfully powered down");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_message("Modem down, quitting...");
|
|
||||||
|
|
||||||
|
gpio_force_off(manager);
|
||||||
|
|
||||||
|
g_message("Modem down, quitting...");
|
||||||
g_main_loop_quit(manager->loop);
|
g_main_loop_quit(manager->loop);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -98,7 +102,7 @@ static gboolean modem_start(struct EG25Manager *manager)
|
|||||||
|
|
||||||
libusb_free_device_list(devices, 1);
|
libusb_free_device_list(devices, 1);
|
||||||
libusb_exit(ctx);
|
libusb_exit(ctx);
|
||||||
} else if (!gpio_check_poweroff(manager, FALSE)) {
|
} else if (!gpio_check_poweroff(manager)) {
|
||||||
g_message("STATUS is low, modem already powered");
|
g_message("STATUS is low, modem already powered");
|
||||||
should_boot = FALSE;
|
should_boot = FALSE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user