Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a88ca1b8c | |||
| 1456db633d | |||
| d4c1c34016 |
4 changed files with 127 additions and 100 deletions
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#define LED_BLINK_TRIGGER_DISABLED 101
|
||||
|
||||
/**
|
||||
* @brief parse the config file
|
||||
*
|
||||
|
|
@ -14,6 +12,11 @@ void parse_config_file(char *path);
|
|||
*/
|
||||
void setup_led_formula(void);
|
||||
|
||||
/**
|
||||
* @brief ensure that the config paths are valid
|
||||
*/
|
||||
void check_config();
|
||||
|
||||
extern char *battery_status_path;
|
||||
extern char *battery_power_source;
|
||||
|
||||
|
|
|
|||
26
src/config.c
26
src/config.c
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <log.h>
|
||||
#include <sys/stat.h>
|
||||
#include <toml.h>
|
||||
#include <tinyexpr.h>
|
||||
|
||||
|
|
@ -13,7 +14,7 @@
|
|||
if (!v) { \
|
||||
log_warn("missing [%s]", vn); \
|
||||
} \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#define set_str_conf(op, tt, v) do { \
|
||||
toml_datum_t val; \
|
||||
|
|
@ -21,7 +22,7 @@
|
|||
if (val.ok) { \
|
||||
op = val.u.s; \
|
||||
} \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#define set_int_conf(op, tt, v) do { \
|
||||
toml_datum_t val; \
|
||||
|
|
@ -29,7 +30,15 @@
|
|||
if (val.ok) { \
|
||||
op = val.u.i; \
|
||||
} \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
#define check_path(path) do { \
|
||||
struct stat sb; \
|
||||
if (stat(path, &sb) == -1) { \
|
||||
log_fatal("path does not exist: %s", path); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static te_expr *expr;
|
||||
static double percentage;
|
||||
|
|
@ -105,5 +114,16 @@ parse_config_file(char *path)
|
|||
set_str_conf(led_blink_timing_formula, led_blink, "timing_formula");
|
||||
set_str_conf(acpi_daemon_socket_path, acpi_daemon, "socket_path");
|
||||
|
||||
check_config();
|
||||
|
||||
toml_free(config);
|
||||
}
|
||||
|
||||
void
|
||||
check_config()
|
||||
{
|
||||
check_path(battery_status_path);
|
||||
check_path(battery_power_source);
|
||||
check_path(led_brightness_path);
|
||||
check_path(acpi_daemon_socket_path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ int
|
|||
main(int argc, char *argv[])
|
||||
{
|
||||
cag_option_context context;
|
||||
bool plugged = plugged_in(battery_power_source);
|
||||
bool plugged;
|
||||
char buffer[MAX_BUFLEN], *out[4], *config_path, *percent;
|
||||
int sock_fd;
|
||||
bool debug = false;
|
||||
|
|
@ -113,6 +113,10 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
}
|
||||
}
|
||||
check_config();
|
||||
|
||||
/* get current plugged in state */
|
||||
plugged = plugged_in(battery_power_source);
|
||||
|
||||
/* configure the led blinking formula */
|
||||
setup_led_formula();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue