mirror of
https://gitlab.com/mobian1/eg25-manager.git
synced 2025-08-29 23:32:14 +02:00
manager: only start the modem if it isn't already on
This commit is contained in:
@@ -44,6 +44,7 @@ mgr_deps = [
|
|||||||
dependency('glib-2.0'),
|
dependency('glib-2.0'),
|
||||||
dependency('gio-unix-2.0'),
|
dependency('gio-unix-2.0'),
|
||||||
dependency('libgpiod'),
|
dependency('libgpiod'),
|
||||||
|
dependency('libusb-1.0'),
|
||||||
dependency('mm-glib'),
|
dependency('mm-glib'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
11
src/gpio.c
11
src/gpio.c
@@ -57,7 +57,7 @@ int gpio_sequence_poweron(struct EG25Manager *manager)
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_PWRKEY], 0);
|
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_PWRKEY], 0);
|
||||||
|
|
||||||
g_message("Executed power-on sequence");
|
g_message("Executed power-on/off sequence");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -172,13 +172,16 @@ int gpio_init(struct EG25Manager *manager)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean gpio_check_poweroff(struct EG25Manager *manager)
|
gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down)
|
||||||
{
|
{
|
||||||
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
if (manager->gpio_in[GPIO_IN_STATUS] &&
|
||||||
gpiod_line_get_value(manager->gpio_in[GPIO_IN_STATUS]) == 1) {
|
gpiod_line_get_value(manager->gpio_in[GPIO_IN_STATUS]) == 1) {
|
||||||
|
|
||||||
// Asserting RESET line to prevent modem from rebooting
|
if (keep_down) {
|
||||||
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
// Asserting RESET line to prevent modem from rebooting
|
||||||
|
gpiod_line_set_value(manager->gpio_out[GPIO_OUT_RESET], 1);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,4 +16,4 @@ int gpio_sequence_shutdown(struct EG25Manager *state);
|
|||||||
int gpio_sequence_suspend(struct EG25Manager *state);
|
int gpio_sequence_suspend(struct EG25Manager *state);
|
||||||
int gpio_sequence_resume(struct EG25Manager *state);
|
int gpio_sequence_resume(struct EG25Manager *state);
|
||||||
|
|
||||||
gboolean gpio_check_poweroff(struct EG25Manager *manager);
|
gboolean gpio_check_poweroff(struct EG25Manager *manager, gboolean keep_down);
|
||||||
|
@@ -16,6 +16,10 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <glib-unix.h>
|
#include <glib-unix.h>
|
||||||
|
#include <libusb.h>
|
||||||
|
|
||||||
|
#define EG25_USB_VID 0x2c7c
|
||||||
|
#define EG25_USB_PID 0x0125
|
||||||
|
|
||||||
static gboolean quit_app(struct EG25Manager *manager)
|
static gboolean quit_app(struct EG25Manager *manager)
|
||||||
{
|
{
|
||||||
@@ -32,7 +36,7 @@ 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))
|
if (gpio_check_poweroff(manager, TRUE))
|
||||||
break;
|
break;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
@@ -46,9 +50,40 @@ static gboolean quit_app(struct EG25Manager *manager)
|
|||||||
|
|
||||||
static gboolean modem_start(struct EG25Manager *manager)
|
static gboolean modem_start(struct EG25Manager *manager)
|
||||||
{
|
{
|
||||||
g_message("Starting modem...");
|
ssize_t i, count;
|
||||||
gpio_sequence_poweron(manager);
|
gboolean should_boot = TRUE;
|
||||||
manager->modem_state = EG25_STATE_POWERED;
|
libusb_context *ctx = NULL;
|
||||||
|
libusb_device **devices = NULL;
|
||||||
|
struct libusb_device_descriptor desc;
|
||||||
|
|
||||||
|
if (manager->braveheart) {
|
||||||
|
// BH don't have the STATUS line connected, so check if USB device is present
|
||||||
|
libusb_init(&ctx);
|
||||||
|
|
||||||
|
count = libusb_get_device_list(ctx, &devices);
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
libusb_get_device_descriptor(devices[i], &desc);
|
||||||
|
if (desc.idVendor == EG25_USB_VID && desc.idProduct == EG25_USB_PID) {
|
||||||
|
g_message("Found corresponding USB device, modem already powered");
|
||||||
|
should_boot = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
libusb_free_device_list(devices, 1);
|
||||||
|
libusb_exit(ctx);
|
||||||
|
} else if (!gpio_check_poweroff(manager, FALSE)) {
|
||||||
|
g_message("STATUS is low, modem already powered");
|
||||||
|
should_boot = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (should_boot) {
|
||||||
|
g_message("Starting modem...");
|
||||||
|
gpio_sequence_poweron(manager);
|
||||||
|
manager->modem_state = EG25_STATE_POWERED;
|
||||||
|
} else {
|
||||||
|
manager->modem_state = EG25_STATE_STARTED;
|
||||||
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user