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
78
src/main.c
78
src/main.c
|
|
@ -31,19 +31,24 @@
|
||||||
|
|
||||||
bool led_ok, wayland_ok;
|
bool led_ok, wayland_ok;
|
||||||
static struct cag_option options[] = {
|
static struct cag_option options[] = {
|
||||||
{
|
{
|
||||||
.identifier = 'c',
|
.identifier = 'c',
|
||||||
.access_letters = "c",
|
.access_letters = "c",
|
||||||
.access_name = "config",
|
.access_name = "config",
|
||||||
.value_name = "PATH",
|
.value_name = "PATH",
|
||||||
.description = "Config file"
|
.description = "Config file"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.identifier = 'h',
|
.identifier = 'd',
|
||||||
.access_letters = "h",
|
.access_letters = "d",
|
||||||
.access_name = "help",
|
.description = "Emit debug info"
|
||||||
.description = "Shows the command help"
|
},
|
||||||
}
|
{
|
||||||
|
.identifier = 'h',
|
||||||
|
.access_letters = "h",
|
||||||
|
.access_name = "help",
|
||||||
|
.description = "Shows the command help"
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -68,10 +73,10 @@ on_battery_event(char *percent, bool plugged)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
wrap(wayland_ok, wayland_set_idle_lock(false));
|
wrap(wayland_ok, wayland_set_idle_lock(false));
|
||||||
} else {
|
} else {
|
||||||
wrap(led_ok, led_set_rate(0));
|
wrap(led_ok, led_set_rate(0));
|
||||||
wrap(wayland_ok, wayland_set_idle_lock(true));
|
wrap(wayland_ok, wayland_set_idle_lock(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(percent);
|
free(percent);
|
||||||
|
|
@ -84,32 +89,36 @@ 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;
|
||||||
|
|
||||||
cag_option_init(&context, options, CAG_ARRAY_SIZE(options), argc, argv);
|
cag_option_init(&context, options, CAG_ARRAY_SIZE(options), argc, argv);
|
||||||
while (cag_option_fetch(&context)) {
|
while (cag_option_fetch(&context)) {
|
||||||
switch (cag_option_get_identifier(&context)) {
|
switch (cag_option_get_identifier(&context)) {
|
||||||
case 'c':
|
case 'c':
|
||||||
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 'h':
|
case 'd':
|
||||||
printf("Usage: eh [OPTION]...\n");
|
debug = true;
|
||||||
cag_option_print(options, CAG_ARRAY_SIZE(options), stdout);
|
break;
|
||||||
return EXIT_SUCCESS;
|
case 'h':
|
||||||
case '?':
|
printf("Usage: eh [OPTION]...\n");
|
||||||
cag_option_print_error(&context, stdout);
|
cag_option_print(options, CAG_ARRAY_SIZE(options), stdout);
|
||||||
break;
|
return EXIT_SUCCESS;
|
||||||
}
|
case '?':
|
||||||
|
cag_option_print_error(&context, stdout);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* configure the led blinking formula */
|
/* configure the led blinking formula */
|
||||||
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);
|
||||||
|
|
@ -119,7 +128,7 @@ main(int argc, char *argv[])
|
||||||
led_ok = false;
|
led_ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the wayland thread */
|
/* create the wayland thread */
|
||||||
if (wayland_create_thread()) {
|
if (wayland_create_thread()) {
|
||||||
wayland_ok = false;
|
wayland_ok = false;
|
||||||
}
|
}
|
||||||
|
|
@ -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