feat(build): use meson so I don't end up ripping my hair out
This commit is contained in:
20
Makefile
20
Makefile
@@ -1,20 +0,0 @@
|
||||
include config.mk
|
||||
|
||||
PROG ?= eh
|
||||
OBJS = main.o\
|
||||
lib/log.c/src/log.o\
|
||||
include/led.o\
|
||||
include/acpi.o\
|
||||
include/utils.o
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
# main build task
|
||||
.c.h.o:
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CC) $(CFLAGS) -o $@ $(OBJS)
|
||||
|
||||
clean:
|
||||
rm $(PROG) $(OBJS)
|
3
config.h
3
config.h
@@ -2,6 +2,9 @@
|
||||
|
||||
static const char *notification_name = "Event Handler"; /* name to use in notifications */
|
||||
static const char *battery_dir = "/sys/class/power_supply/BAT1"; /* path to the batteries directory */
|
||||
static const char *linefile = "/sys/class/power_supply/ACAD/online"; /* path to the file which tells us if we are online (plugged in) */
|
||||
static const char *ledfile = "/sys/class/leds/input0::capslock/brightness"; /* path to the file which lights up the led */
|
||||
static const char *acpid_sock = "/run/acpid.socket"; /* acpid socket file */
|
||||
static const int blink_start = 15; /* percentage to start blinking at */
|
||||
const double blink_formula(int x) { /* formula used to set the blinking rate, this function takes in one argument: the battery percentage */
|
||||
return 1.7 + 18.5 * exp(-0.29 * x);
|
||||
|
@@ -1,8 +0,0 @@
|
||||
PKG_CONFIG = pkg-config
|
||||
CC = cc
|
||||
VERSION = 0.1
|
||||
|
||||
# flags and incs
|
||||
INCLUDES = -I./lib/log.c/src
|
||||
PKGS =
|
||||
CFLAGS = -DVERSION=\"$(VERSION)\" $(INCLUDES) -DLOG_USE_COLOR -Wall -Og -g -lm
|
@@ -1,4 +1,33 @@
|
||||
int acpi_create_socket(char *socket_file);
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief parse output of acpid
|
||||
*
|
||||
* @param str input from acpi socket
|
||||
* @param out the parsed version of it
|
||||
* @return 0 on success
|
||||
*/
|
||||
int acpi_parse(char *str, char **out);
|
||||
int acpi_close_socket(int sockfd);
|
||||
|
||||
/**
|
||||
* @brief cleanup the results of acpi_parse
|
||||
*
|
||||
* @param out the pointer to the output from acpi_parse
|
||||
*/
|
||||
void acpi_clean_parse(char *out[4]);
|
||||
|
||||
/**
|
||||
* @brief create a new acpi socket connection
|
||||
*
|
||||
* @param socket_file path to the socket file
|
||||
* @return the socket fd
|
||||
*/
|
||||
int acpi_create_socket(char *socket_file);
|
||||
|
||||
/**
|
||||
* @brief close the socket connection
|
||||
*
|
||||
* @param sockfd the sockets fd
|
||||
* @return 0 on success 1 on error
|
||||
*/
|
||||
int acpi_close_socket(int sockfd);
|
||||
|
@@ -1,2 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief create the led thread
|
||||
*
|
||||
* @param file file to send blinking signals to
|
||||
* @return 0 on success
|
||||
*/
|
||||
int led_create_thread(char *file);
|
||||
|
||||
/**
|
||||
* @brief set the led rate
|
||||
*
|
||||
* @param r number of blinks per second
|
||||
*/
|
||||
void led_set_rate(double rate);
|
||||
|
@@ -1,2 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief get a substring of a string
|
||||
*
|
||||
* @param s string
|
||||
* @param pos first pos
|
||||
* @param l length
|
||||
* @return the substring
|
||||
*/
|
||||
char *get_substring(char *s, int pos, int l);
|
||||
|
||||
/**
|
||||
* @brief concatinate two strings
|
||||
*
|
||||
* @param s1 first
|
||||
* @param s2 second
|
||||
* @return the concatinated string
|
||||
*/
|
||||
char *concat(const char *s1, const char *s2);
|
||||
|
29
meson.build
Normal file
29
meson.build
Normal file
@@ -0,0 +1,29 @@
|
||||
project('acpi-event-handler', 'c')
|
||||
|
||||
add_project_arguments([
|
||||
'-DLOG_USE_COLOR' # enable colored logs
|
||||
], language: 'c')
|
||||
|
||||
srcfiles = files(
|
||||
'src/main.c',
|
||||
'src/led.c',
|
||||
'src/acpi.c',
|
||||
'src/utils.c'
|
||||
)
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
math_dep = cc.find_library('m', required: true)
|
||||
|
||||
executable('eh', srcfiles,
|
||||
dependencies: [
|
||||
math_dep
|
||||
],
|
||||
include_directories: [
|
||||
'lib/log.c/src',
|
||||
'include'
|
||||
],
|
||||
link_with: [
|
||||
static_library('log.c', 'lib/log.c/src/log.c',
|
||||
include_directories: 'lib/log.c/src')
|
||||
]
|
||||
)
|
@@ -9,13 +9,6 @@
|
||||
#include "acpi.h"
|
||||
#include "utils.h"
|
||||
|
||||
/**
|
||||
* @brief parse output of acpid
|
||||
*
|
||||
* @param str input from acpi socket
|
||||
* @param out the parsed version of it
|
||||
* @return 0 on success
|
||||
*/
|
||||
int
|
||||
acpi_parse(char *str, char **out)
|
||||
{
|
||||
@@ -46,11 +39,6 @@ acpi_parse(char *str, char **out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief cleanup the results of acpi_parse
|
||||
*
|
||||
* @param out the pointer to the output from acpi_parse
|
||||
*/
|
||||
void
|
||||
acpi_clean_parse(char *out[4])
|
||||
{
|
||||
@@ -63,12 +51,6 @@ acpi_clean_parse(char *out[4])
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief create a new acpi socket connection
|
||||
*
|
||||
* @param socket_file path to the socket file
|
||||
* @return the socket fd
|
||||
*/
|
||||
int
|
||||
acpi_create_socket(char *socket_file)
|
||||
{
|
||||
@@ -98,12 +80,6 @@ acpi_create_socket(char *socket_file)
|
||||
return sock_fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief close the socket connection
|
||||
*
|
||||
* @param sockfd the sockets fd
|
||||
* @return 0 on success 1 on error
|
||||
*/
|
||||
int
|
||||
acpi_close_socket(int sockfd) {
|
||||
if (close(sockfd) < 0) {
|
@@ -118,12 +118,6 @@ pre_exit(int signal)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief create the led thread
|
||||
*
|
||||
* @param file file to send blinking signals to
|
||||
* @return 0 on success
|
||||
*/
|
||||
int
|
||||
led_create_thread(char *file)
|
||||
{
|
||||
@@ -175,11 +169,6 @@ led_create_thread(char *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the led rate
|
||||
*
|
||||
* @param r number of blinks per second
|
||||
*/
|
||||
void
|
||||
led_set_rate(double r)
|
||||
{
|
@@ -13,14 +13,12 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "include/led.h"
|
||||
#include "include/acpi.h"
|
||||
#include "include/utils.h"
|
||||
#include "led.h"
|
||||
#include "acpi.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define SOCKET_FILE "/run/acpid.socket"
|
||||
#define LED_FILE "/sys/class/leds/input0::capslock/brightness"
|
||||
#define MAX_BUFLEN 1024
|
||||
|
||||
char
|
||||
@@ -98,7 +96,7 @@ on_battery_event(char *percent, bool plugged)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bool plugged = plugged_in("/sys/class/power_supply/ACAD/online");
|
||||
bool plugged = plugged_in((char *)linefile);
|
||||
char buffer[MAX_BUFLEN], *out[4];
|
||||
int sock_fd;
|
||||
|
||||
@@ -106,10 +104,10 @@ main(int argc, char *argv[])
|
||||
log_set_level(LOG_DEBUG);
|
||||
|
||||
/* open up socket address */
|
||||
sock_fd = acpi_create_socket(SOCKET_FILE);
|
||||
sock_fd = acpi_create_socket((char *)acpid_sock);
|
||||
|
||||
/* create the led thread */
|
||||
led_create_thread(LED_FILE);
|
||||
led_create_thread((char *)ledfile);
|
||||
|
||||
/* run events that need to be run on start to ensure that the current state
|
||||
* inside the program reflects that that is outside the program
|
@@ -5,14 +5,6 @@
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
|
||||
/**
|
||||
* @brief get a substring of a string
|
||||
*
|
||||
* @param s string
|
||||
* @param pos first pos
|
||||
* @param l length
|
||||
* @return the substring
|
||||
*/
|
||||
char
|
||||
*get_substring(char *s, int pos, int l)
|
||||
{
|
||||
@@ -41,13 +33,6 @@ char
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief concatinate two strings
|
||||
*
|
||||
* @param s1 first
|
||||
* @param s2 second
|
||||
* @return the concatinated string
|
||||
*/
|
||||
char
|
||||
*concat(const char *s1, const char *s2)
|
||||
{
|
||||
@@ -58,7 +43,7 @@ char
|
||||
len2 = strlen(s2);
|
||||
|
||||
/* attempt to allocate size for the new string */
|
||||
result = malloc(len1 + len2 + 1);
|
||||
result = malloc((len1 + len2 + 1) * sizeof(char));
|
||||
if (result == NULL) {
|
||||
log_fatal("malloc: %s", strerror(errno));
|
||||
exit(1);
|
Reference in New Issue
Block a user