Compare commits
3 Commits
22fcfcdba9
...
master
Author | SHA1 | Date | |
---|---|---|---|
8d676a2167
|
|||
c89bcb4d68
|
|||
323cef6e35 |
28
README.md
28
README.md
@@ -3,13 +3,32 @@ My custom event handler for battery related things. Here's a brief rundown of
|
||||
all the features:
|
||||
|
||||
When the percentage gets below a specified percentage it will blink the
|
||||
specified led at any rate defined by the config file.
|
||||
specified led at any rate defined by the config file. Example:
|
||||

|
||||
|
||||
If the system is plugged in and a wayland session is running then the event
|
||||
handler will place an idle inhibitor on the session to keep the computer from
|
||||
going to sleep. The inhibitor is removed when the system is unplugged.
|
||||
|
||||
## Default Config
|
||||
> [!WARNING]
|
||||
> event-handler relies on [acpid](https://wiki.archlinux.org/title/Acpid) to
|
||||
> monitor battery events ensure you have it installed and running before using
|
||||
> event-handler
|
||||
|
||||
## Configuring
|
||||
I built event-handler to be used as a service independent of my current user
|
||||
and such event-handler does not read the configuration file from any default
|
||||
path. Instead it's up to you to choose where it is and pass the file's full
|
||||
path into event-handler like so:
|
||||
```bash
|
||||
eh -c ./config.toml
|
||||
```
|
||||
|
||||
The config is completely optional, however you will most likely need it as the
|
||||
default is setup for my framework 13 system running Void Linux. Below are the
|
||||
defaults:
|
||||
|
||||
### Default Config
|
||||
```toml
|
||||
[battery]
|
||||
status_path = "/sys/class/power_supply/BAT1"
|
||||
@@ -25,3 +44,8 @@ timing_formula = "1.7 + 18.5 * exp(-0.29 * p)" # p is the percentage of the batt
|
||||
[acpi_daemon]
|
||||
socket_path = "/run/acpid.socket"
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> The default formula may or may not work above 15 percent due to led
|
||||
> shenanigans. If you wish to craft your own formula all relevant notation may
|
||||
> be found in [this repo](https://github.com/codeplea/tinyexpr).
|
||||
|
BIN
examples/blink.mp4
Normal file
BIN
examples/blink.mp4
Normal file
Binary file not shown.
@@ -49,15 +49,12 @@ led_blink_timing_func(int percent)
|
||||
{
|
||||
percentage = percent;
|
||||
return te_eval(expr);
|
||||
|
||||
// return 1.7 + 18.5 * exp(-0.29 * percent);
|
||||
}
|
||||
|
||||
static void
|
||||
free_eval(int sig)
|
||||
{
|
||||
te_free(expr);
|
||||
exit(sig);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -67,13 +64,13 @@ setup_led_formula(void)
|
||||
|
||||
te_variable vars[] = { { "p", &percentage } };
|
||||
expr = te_compile(led_blink_timing_formula, vars, 1, &err);
|
||||
signal(SIGINT, free_eval);
|
||||
if (!expr) {
|
||||
log_fatal("%s", led_blink_timing_formula);
|
||||
log_fatal("%*s^ Error near here", err - 1, "");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
signal(SIGINT, free_eval);
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -115,8 +115,6 @@ pre_exit(int signal)
|
||||
fclose(data->pfile);
|
||||
free(data->file_name);
|
||||
free(data);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
|
@@ -118,16 +118,12 @@ pre_exit(int signal)
|
||||
|
||||
zwp_idle_inhibit_manager_v1_destroy(data->inhibitmanager);
|
||||
wl_registry_destroy(data->registry);
|
||||
// wl_display_destroy(data->display);
|
||||
wl_compositor_destroy(data->compositor);
|
||||
wl_surface_destroy(data->surface);
|
||||
/* TODO: this causes a segfault
|
||||
wl_display_destroy(data->display);
|
||||
*/
|
||||
|
||||
/* make sure to cleanup the allocated data */
|
||||
free(data);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
|
Reference in New Issue
Block a user