fix battery events not getting called and add debug flag
This commit is contained in:
parent
8d676a2167
commit
eb951cda68
1 changed files with 45 additions and 33 deletions
16
src/main.c
16
src/main.c
|
|
@ -38,6 +38,11 @@ static struct cag_option options[] = {
|
||||||
.value_name = "PATH",
|
.value_name = "PATH",
|
||||||
.description = "Config file"
|
.description = "Config file"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.identifier = 'd',
|
||||||
|
.access_letters = "d",
|
||||||
|
.description = "Emit debug info"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.identifier = 'h',
|
.identifier = 'h',
|
||||||
.access_letters = "h",
|
.access_letters = "h",
|
||||||
|
|
@ -84,6 +89,7 @@ main(int argc, char *argv[])
|
||||||
bool plugged = plugged_in(battery_power_source);
|
bool plugged = plugged_in(battery_power_source);
|
||||||
char buffer[MAX_BUFLEN], *out[4], *config_path, *percent;
|
char buffer[MAX_BUFLEN], *out[4], *config_path, *percent;
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
|
bool debug = false;
|
||||||
|
|
||||||
/* defaults to working */
|
/* defaults to working */
|
||||||
led_ok = wayland_ok = true;
|
led_ok = wayland_ok = true;
|
||||||
|
|
@ -95,6 +101,9 @@ main(int argc, char *argv[])
|
||||||
config_path = (char *)cag_option_get_value(&context);
|
config_path = (char *)cag_option_get_value(&context);
|
||||||
parse_config_file(config_path);
|
parse_config_file(config_path);
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
debug = true;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
printf("Usage: eh [OPTION]...\n");
|
printf("Usage: eh [OPTION]...\n");
|
||||||
cag_option_print(options, CAG_ARRAY_SIZE(options), stdout);
|
cag_option_print(options, CAG_ARRAY_SIZE(options), stdout);
|
||||||
|
|
@ -109,7 +118,7 @@ main(int argc, char *argv[])
|
||||||
setup_led_formula();
|
setup_led_formula();
|
||||||
|
|
||||||
/* set the logging level */
|
/* set the logging level */
|
||||||
log_set_level(LOG_DEBUG);
|
log_set_level(debug ? LOG_TRACE : LOG_INFO);
|
||||||
|
|
||||||
/* open up socket address */
|
/* open up socket address */
|
||||||
sock_fd = acpi_create_socket(acpi_daemon_socket_path);
|
sock_fd = acpi_create_socket(acpi_daemon_socket_path);
|
||||||
|
|
@ -147,6 +156,7 @@ main(int argc, char *argv[])
|
||||||
if (acpi_parse(buffer, out) != 0) {
|
if (acpi_parse(buffer, out) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
log_trace("parsed buf: %s, %s, %s, %s", out[0], out[1], out[2], out[3]);
|
||||||
|
|
||||||
/* rules */
|
/* rules */
|
||||||
if (strcmp(out[0], "ac_adapter") == 0) {
|
if (strcmp(out[0], "ac_adapter") == 0) {
|
||||||
|
|
@ -154,6 +164,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (strcmp(s, "AC") == 0) {
|
if (strcmp(s, "AC") == 0) {
|
||||||
plugged = plugged_in(battery_power_source);
|
plugged = plugged_in(battery_power_source);
|
||||||
|
log_trace("%splugged", plugged ? "" : "un");
|
||||||
}
|
}
|
||||||
|
|
||||||
free(s);
|
free(s);
|
||||||
|
|
@ -164,7 +175,8 @@ main(int argc, char *argv[])
|
||||||
if (strcmp(out[2], "00000080") == 0) {
|
if (strcmp(out[2], "00000080") == 0) {
|
||||||
if (strcmp(out[3], "00000001") == 0) {
|
if (strcmp(out[3], "00000001") == 0) {
|
||||||
percent = battery_percent();
|
percent = battery_percent();
|
||||||
if (percent == NULL) {
|
log_trace("percent: %s", percent);
|
||||||
|
if (percent != NULL) {
|
||||||
on_battery_event(percent, plugged);
|
on_battery_event(percent, plugged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue