mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 07:12:08 +02:00
manager: actively poll GPIO when quitting
For some reason, during system the main loop exits before we call g_main_loop_quit(), so don't rely on it and use a simple polling loop to check for modem poweroff.
This commit is contained in:
@@ -17,39 +17,29 @@
|
||||
|
||||
#include <glib-unix.h>
|
||||
|
||||
static gboolean quit_timeout_cb(struct EG25Manager *manager)
|
||||
{
|
||||
g_message("Modem down, quitting...");
|
||||
g_main_loop_quit(manager->loop);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean gpio_poll_cb(struct EG25Manager *manager)
|
||||
{
|
||||
if (gpio_check_poweroff(manager)) {
|
||||
quit_timeout_cb(manager);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean quit_app(struct EG25Manager *manager)
|
||||
{
|
||||
int i;
|
||||
|
||||
g_message("Request to quit...");
|
||||
|
||||
at_destroy(manager);
|
||||
mm_iface_destroy(manager);
|
||||
suspend_destroy(manager);
|
||||
|
||||
if (manager->modem_state >= EG25_STATE_STARTED) {
|
||||
g_message("Powering down the modem...");
|
||||
gpio_sequence_shutdown(manager);
|
||||
manager->modem_state = EG25_STATE_FINISHING;
|
||||
g_timeout_add(500, G_SOURCE_FUNC(gpio_poll_cb), manager);
|
||||
g_timeout_add_seconds(30, G_SOURCE_FUNC(quit_timeout_cb), manager);
|
||||
for (i = 0; i < 30; i++) {
|
||||
if (gpio_check_poweroff(manager))
|
||||
break;
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
g_message("Modem down, quitting...");
|
||||
|
||||
mm_iface_destroy(manager);
|
||||
suspend_destroy(manager);
|
||||
g_bus_unwatch_name(manager->mm_watch);
|
||||
g_main_loop_quit(manager->loop);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@@ -160,7 +150,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
g_main_loop_run(manager.loop);
|
||||
|
||||
at_destroy(&manager);
|
||||
gpio_destroy(&manager);
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user