Added README.md

This commit is contained in:
Josh Ashton
2023-11-09 14:53:18 -07:00
parent d423988442
commit 9c67490dec
5 changed files with 49 additions and 11 deletions
+22
View File
@@ -0,0 +1,22 @@
<h1 align="center">Battery Monitor</h1>
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
Symlink
+1
View File
@@ -0,0 +1 @@
/usr/local/etc/data.txt
+1 -1
View File
@@ -15,7 +15,7 @@ ax = fig.add_subplot(111)
# Read your data from a CSV file # Read your data from a CSV file
data = [] data = []
with open('/tmp/data.txt', 'r') as csvfile: with open('/usr/local/etc/data.txt', 'r') as csvfile:
reader = csv.reader(csvfile) reader = csv.reader(csvfile)
for row in reader: for row in reader:
data.append(row) data.append(row)
+13 -2
View File
@@ -57,12 +57,17 @@ void recordData() {
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm_info); strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm_info);
// Write the data to a file // 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); fprintf(fp, "%s, %d, %s\n", datetime, batteryPercentage, batteryStatus);
fclose(fp); fclose(fp);
} }
int main() { 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");
// Daemonize the process // Daemonize the process
pid_t pid, sid; pid_t pid, sid;
pid = fork(); pid = fork();
@@ -74,6 +79,12 @@ int main() {
if (sid < 0) exit(EXIT_FAILURE); if (sid < 0) exit(EXIT_FAILURE);
if ((chdir("/")) < 0) exit(EXIT_FAILURE); if ((chdir("/")) < 0) exit(EXIT_FAILURE);
}
} else {
printf("Usage: %s [--daemonize|-d]\n", argv[0]);
exit(EXIT_FAILURE);
}
while (1) { while (1) {
recordData(); recordData();
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/bin/zsh
gcc -o battery-mon main.c;
./battery-mon --daemonize;