diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c954a2 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +

Battery Monitor

+ +This project is written on and for Apple Silicon MacBooks running Asahi Linux. + +The purpose is two-fold: give the user more data about their battery performance, and give the user options to optimize their battery. +From the first purpose, eventually the daemon and it's corresponding commands will allow for the user to get estimates of their time +remaining, implement power-saving modes, optimization suggestions, and other features that are built-in to MacOS. + +**Note**: An interesting trend does emerge from initial testing, the battery usage and charging appears to be a stepped linear function. + +### TODO + [ ] Gather all relavent information for the daemon: display backlight, keyboard backlight, running applications, etc. + [ ] Implement the GUI graph with GTK. + [ ] Estimated time remaining section. + [ ] Power-saving recommendations + [ ] Battery-mon daemon on startup. + [ ] Calculate estimated time remaining based upon historical data. + +### INSTALLATION + git clone https://github.com/quaxlqueen/battery-mon + cd ./battery-mon + ./make diff --git a/data.txt b/data.txt new file mode 120000 index 0000000..ca4d9f1 --- /dev/null +++ b/data.txt @@ -0,0 +1 @@ +/usr/local/etc/data.txt \ No newline at end of file diff --git a/gui.py b/gui.py index 084f6b3..ec4d55d 100644 --- a/gui.py +++ b/gui.py @@ -15,7 +15,7 @@ ax = fig.add_subplot(111) # Read your data from a CSV file data = [] -with open('/tmp/data.txt', 'r') as csvfile: +with open('/usr/local/etc/data.txt', 'r') as csvfile: reader = csv.reader(csvfile) for row in reader: data.append(row) diff --git a/main.c b/main.c index dae01ef..286849a 100644 --- a/main.c +++ b/main.c @@ -57,22 +57,33 @@ void recordData() { strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm_info); // Write the data to a file - FILE *fp = fopen("/tmp/data.txt", "a"); + FILE *fp = fopen("/usr/local/etc/data.txt", "a"); fprintf(fp, "%s, %d, %s\n", datetime, batteryPercentage, batteryStatus); fclose(fp); } -int main() { - // Daemonize the process - pid_t pid, sid; - pid = fork(); - if (pid < 0) exit(EXIT_FAILURE); - if (pid > 0) exit(EXIT_SUCCESS); +int main(int argc, char * argv[]) { + // Check if the argument is --daemonize + if (argc > 1) { + if ((strcmp(argv[1], "--daemonize") == 0) || (strcmp(argv[1], "-d") == 0)) { + printf("Daemonizing...\n"); - sid = setsid(); + // Daemonize the process + pid_t pid, sid; + pid = fork(); + if (pid < 0) exit(EXIT_FAILURE); + if (pid > 0) exit(EXIT_SUCCESS); - if (sid < 0) exit(EXIT_FAILURE); - if ((chdir("/")) < 0) exit(EXIT_FAILURE); + sid = setsid(); + + if (sid < 0) exit(EXIT_FAILURE); + if ((chdir("/")) < 0) exit(EXIT_FAILURE); + + } + } else { + printf("Usage: %s [--daemonize|-d]\n", argv[0]); + exit(EXIT_FAILURE); + } while (1) { recordData(); diff --git a/make b/make new file mode 100755 index 0000000..6b3afa2 --- /dev/null +++ b/make @@ -0,0 +1,4 @@ +#!/bin/zsh + +gcc -o battery-mon main.c; +./battery-mon --daemonize;