diff options
author | mdomlop | 2021-01-14 09:46:46 +0100 |
---|---|---|
committer | mdomlop | 2021-01-14 09:46:46 +0100 |
commit | ef2b4716e599b92f5451665cbf4c1d99dfce4ed2 (patch) | |
tree | a015f9353271a4900b087268e94deab0d564d78d | |
parent | 64898a23a2290dcbc535f9badcded36a6d28c5d4 (diff) |
Version 0.2
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | INFO | 2 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/rgbtemp.c | 178 | ||||
-rw-r--r-- | src/rgbtemp.service | 1 |
5 files changed, 123 insertions, 81 deletions
@@ -1,6 +1,19 @@ -snapman (0.1) unstable; urgency=medium +rgbtemp +======= - * Release 0.1. - + First release. +Release 0.2 +----------- + +By Manuel <mdomlop@gmail.com> Wed, 03 Apr 2020 14:34:17 +0200 + +- No hardcoded values for hwmon file. +- Supply such file by RGBTEMP environment variable or by command line. + + +Release 0.1 +----------- + +By Manuel <mdomlop@gmail.com > Wed, 03 Apr 2020 14:34:17 +0200 + +- First release. - -- Manuel Domínguez López <mdomlop@gmail.com > Wed, 03 Apr 2020 14:34:17 +0200 @@ -1,7 +1,7 @@ PROGRAM_NAME=RGB Temperature Monitor EXECUTABLE_NAME=rgbtemp DESCRIPTION=Change RGB colors according to temperature. -VERSION=0.1 +VERSION=0.2 AUTHOR=Manuel Domínguez López SOURCE=https://github.com/mdomlop/rgbtemp LICENSE=GPL-3 @@ -31,7 +31,7 @@ arch_install_services: arch_pkg: $(ARCHPKG) $(ARCHPKG): PKGBUILD ChangeLog - makepkg -d + makepkg -fd @echo @echo Package done! @echo You can install it as root with: diff --git a/src/rgbtemp.c b/src/rgbtemp.c index 547fb57..8ab1ada 100644 --- a/src/rgbtemp.c +++ b/src/rgbtemp.c @@ -2,14 +2,17 @@ #include <stdlib.h> /* For exit() function */ #include <unistd.h> /* For sleep() function */ #include <signal.h> +#include <string.h> unsigned int sleep(unsigned int seconds); #define FALSE 0 #define TRUE 1 +#define SLEEP 2 /* Sleeping time in seconds */ + #define BLACK "00000000 00000000 00000000" /* off */ -#define WHITE "FFFFFFFF FFFFFFFF FFFFFFFF" /* >2Fº */ +#define WHITE "FFFFFFFF FFFFFFFF FFFFFFFF" /* >20º */ #define CYAN "00000000 FFFFFFFF FFFFFFFF" /* >30º */ #define BLUE "00000000 00000000 FFFFFFFF" /* >40º */ #define GREEN "00000000 FFFFFFFF 00000000" /* >50º */ @@ -18,87 +21,112 @@ unsigned int sleep(unsigned int seconds); #define RED "FFFFFFFF 00000000 00000000" /* >80º */ #define PINK "FFFFFFFF 00000000 FFFFFFFF" /* >90º */ -char fileaddr[] = "/sys/class/hwmon/hwmon0/temp1_input"; +/* #define DEF_PATH "/sys/class/hwmon/hwmon1/temp3_input" */ + int running = TRUE; void set_color(int celsius) { - /* printf("Los grados son: %i\n", celsius); */ - int exitstatus = 0; - if (celsius > 90000) { exitstatus = system("msi-rgb --base-port 4e --pulse " PINK); } - else if (celsius > 80000) { exitstatus = system("msi-rgb --base-port 4e --pulse " RED); } - else if (celsius > 70000) { exitstatus = system("msi-rgb --base-port 4e --pulse " ORANGE); } - else if (celsius > 60000) { exitstatus = system("msi-rgb --base-port 4e --pulse " YELLOW); } - else if (celsius > 50000) { exitstatus = system("msi-rgb --base-port 4e --pulse " GREEN); } - else if (celsius > 40000) { exitstatus = system("msi-rgb --base-port 4e --pulse " BLUE); } - else if (celsius > 30000) { exitstatus = system("msi-rgb --base-port 4e --pulse " CYAN); } - else if (celsius > 20000) { exitstatus = system("msi-rgb --base-port 4e --pulse " WHITE); } - else { exitstatus = system("msi-rgb --base-port 4e --pulse " BLACK); } - - if (exitstatus) running = FALSE; + /* printf("Los grados son: %i\n", celsius); */ + int exitstatus = 0; + if (celsius > 90000) { exitstatus = system("msi-rgb --base-port 4e --pulse " PINK); } + else if (celsius > 80000) { exitstatus = system("msi-rgb --base-port 4e --pulse " RED); } + else if (celsius > 70000) { exitstatus = system("msi-rgb --base-port 4e --pulse " ORANGE); } + else if (celsius > 60000) { exitstatus = system("msi-rgb --base-port 4e --pulse " YELLOW); } + else if (celsius > 50000) { exitstatus = system("msi-rgb --base-port 4e --pulse " GREEN); } + else if (celsius > 40000) { exitstatus = system("msi-rgb --base-port 4e --pulse " BLUE); } + else if (celsius > 30000) { exitstatus = system("msi-rgb --base-port 4e --pulse " CYAN); } + else if (celsius > 20000) { exitstatus = system("msi-rgb --base-port 4e --pulse " WHITE); } + else { exitstatus = system("msi-rgb --base-port 4e --pulse " BLACK); } + + if (exitstatus) running = FALSE; } void sig_handler(int signo) { - if (signo == SIGUSR1) { - fprintf(stderr, "\nINFO: Received SIGUSR1\n"); - running = FALSE; - } - else if (signo == SIGTERM) { - fprintf(stderr, "\nINFO: Received SIGTERM\n"); - running = FALSE; - } - else if (signo == SIGINT) { - fprintf(stderr, "\nINFO: Received SIGINT\n"); - running = FALSE; - } - else if (signo == SIGKILL) - fprintf(stderr, "\nINFO: Received SIGKILL\n"); - else if (signo == SIGSTOP) - fprintf(stderr, "\nINFO: Received SIGSTOP\n"); - else - fprintf(stderr, "\nINFO: Received: %d", signo); + if (signo == SIGUSR1) { + fprintf(stderr, "\nINFO: Received SIGUSR1\n"); + running = FALSE; + } + else if (signo == SIGTERM) { + fprintf(stderr, "\nINFO: Received SIGTERM\n"); + running = FALSE; + } + else if (signo == SIGINT) { + fprintf(stderr, "\nINFO: Received SIGINT\n"); + running = FALSE; + } + else if (signo == SIGKILL) + fprintf(stderr, "\nINFO: Received SIGKILL\n"); + else if (signo == SIGSTOP) + fprintf(stderr, "\nINFO: Received SIGSTOP\n"); + else + fprintf(stderr, "\nINFO: Received: %d", signo); } -int main() { - int i; - int cleanexit; - int fscanf_ok; - char c[8]; - FILE *fptr; - - if (signal(SIGUSR1, sig_handler) == SIG_ERR) - fprintf(stderr, "WARNING: Can't catch SIGUSR1\n"); - if (signal(SIGTERM, sig_handler) == SIG_ERR) - fprintf(stderr, "WARNING: Can't catch SIGTERM\n"); - if (signal(SIGINT, sig_handler) == SIG_ERR) - fprintf(stderr, "WARNING: Can't catch SIGINT\n"); - /*if (signal(SIGKILL, sig_handler) == SIG_ERR) - fprintf(stderr, "%s", "WARNING: Can't catch SIGKILL\n"); - if (signal(SIGSTOP, sig_handler) == SIG_ERR) - fprintf(stderr, "%s", "WARNING: Can't catch SIGSTOP\n"); */ - - while (running) { - if ((fptr = fopen(fileaddr, "r")) == NULL) { - fprintf(stderr, "ERROR: Opening file"); - /* Program exits if file pointer returns NULL. */ - exit(1); - } - - /* Reads text until newline is encountered */ - fscanf_ok = fscanf(fptr, "%[^\n]", c); - fclose(fptr); - - if (!fscanf_ok) { return 0; } - - i = atoi(c); - set_color(i); - sleep(2); - } - - /* system("msi-rgb --disable --base-port 4e " WHITE); */ - cleanexit = system("msi-rgb --base-port 4e " BLACK); /* No pulsing */ - - if (cleanexit) { return 1; } - - return 0; +int main(int argc, char *argv[]) { + int i; + int cleanexit; + int fscanf_ok; + char c[8]; + char fileaddr[255]; + + const char* env = getenv("RGBTEMP"); + + FILE *fptr; + + switch (argc) + { + case 1: + if (env != NULL) strcpy(fileaddr, env); + else + { + fprintf(stderr, "RGBTEMP environment variable is empty.\n" + "Please, supply a file in such variable or by command line.\n" + "Exiting.\n"); + exit(2); + } + break; + case 2: + strcpy(fileaddr, argv[1]); + break; + default: + fprintf(stderr, "\nWarning: incorrect number of args: %d.", argc); + break; + } + + if (signal(SIGUSR1, sig_handler) == SIG_ERR) + fprintf(stderr, "WARNING: Can't catch SIGUSR1\n"); + if (signal(SIGTERM, sig_handler) == SIG_ERR) + fprintf(stderr, "WARNING: Can't catch SIGTERM\n"); + if (signal(SIGINT, sig_handler) == SIG_ERR) + fprintf(stderr, "WARNING: Can't catch SIGINT\n"); + /*if (signal(SIGKILL, sig_handler) == SIG_ERR) + fprintf(stderr, "%s", "WARNING: Can't catch SIGKILL\n"); + if (signal(SIGSTOP, sig_handler) == SIG_ERR) + fprintf(stderr, "%s", "WARNING: Can't catch SIGSTOP\n"); */ + + while (running) { + if ((fptr = fopen(fileaddr, "r")) == NULL) { + fprintf(stderr, "ERROR: Opening file %s", fileaddr); + /* Program exits if file pointer returns NULL. */ + exit(1); + } + + /* Reads text until newline is encountered */ + fscanf_ok = fscanf(fptr, "%[^\n]", c); + fclose(fptr); + + if (!fscanf_ok) { return 0; } + + i = atoi(c); + set_color(i); + sleep(SLEEP); + } + + /* system("msi-rgb --disable --base-port 4e " WHITE); */ + cleanexit = system("msi-rgb --base-port 4e " BLACK); /* No pulsing */ + + if (cleanexit) { return 1; } + + return 0; } diff --git a/src/rgbtemp.service b/src/rgbtemp.service index d70b76d..434e65b 100644 --- a/src/rgbtemp.service +++ b/src/rgbtemp.service @@ -2,6 +2,7 @@ Description=Change RGB colors according to temperature [Service] +Environment=RGBTEMP=/path/to/sys/hwmon/temp_input_file Type=simple ExecStart=rgbtemp KillMode=process |