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