fix battery events not getting called and add debug flag

This commit is contained in:
Squibid 2026-01-05 14:13:40 -05:00
parent 8d676a2167
commit eb951cda68

View file

@ -38,6 +38,11 @@ static struct cag_option options[] = {
.value_name = "PATH",
.description = "Config file"
},
{
.identifier = 'd',
.access_letters = "d",
.description = "Emit debug info"
},
{
.identifier = 'h',
.access_letters = "h",
@ -84,6 +89,7 @@ main(int argc, char *argv[])
bool plugged = plugged_in(battery_power_source);
char buffer[MAX_BUFLEN], *out[4], *config_path, *percent;
int sock_fd;
bool debug = false;
/* defaults to working */
led_ok = wayland_ok = true;
@ -95,6 +101,9 @@ main(int argc, char *argv[])
config_path = (char *)cag_option_get_value(&context);
parse_config_file(config_path);
break;
case 'd':
debug = true;
break;
case 'h':
printf("Usage: eh [OPTION]...\n");
cag_option_print(options, CAG_ARRAY_SIZE(options), stdout);
@ -109,7 +118,7 @@ main(int argc, char *argv[])
setup_led_formula();
/* set the logging level */
log_set_level(LOG_DEBUG);
log_set_level(debug ? LOG_TRACE : LOG_INFO);
/* open up socket address */
sock_fd = acpi_create_socket(acpi_daemon_socket_path);
@ -147,6 +156,7 @@ main(int argc, char *argv[])
if (acpi_parse(buffer, out) != 0) {
continue;
}
log_trace("parsed buf: %s, %s, %s, %s", out[0], out[1], out[2], out[3]);
/* rules */
if (strcmp(out[0], "ac_adapter") == 0) {
@ -154,6 +164,7 @@ main(int argc, char *argv[])
if (strcmp(s, "AC") == 0) {
plugged = plugged_in(battery_power_source);
log_trace("%splugged", plugged ? "" : "un");
}
free(s);
@ -164,7 +175,8 @@ main(int argc, char *argv[])
if (strcmp(out[2], "00000080") == 0) {
if (strcmp(out[3], "00000001") == 0) {
percent = battery_percent();
if (percent == NULL) {
log_trace("percent: %s", percent);
if (percent != NULL) {
on_battery_event(percent, plugged);
}
}