diff options
author | mdomlop | 2020-05-18 11:48:10 +0200 |
---|---|---|
committer | mdomlop | 2020-05-18 11:48:10 +0200 |
commit | 64898a23a2290dcbc535f9badcded36a6d28c5d4 (patch) | |
tree | c32a6f7d378804ff9cfa8aa9eb6ffb15022b1abe | |
parent | ae590ab48714bc2de0a7567108c85fe3c247e79f (diff) |
Initial commit.0.1
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | INFO | 7 | ||||
-rw-r--r-- | Makefile | 44 | ||||
-rw-r--r-- | PKGBUILD | 26 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | rgbtemp.gif | bin | 0 -> 80516 bytes | |||
-rw-r--r-- | src/rgbtemp.c | 104 | ||||
-rw-r--r-- | src/rgbtemp.service | 11 |
8 files changed, 204 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..cc4f92e --- /dev/null +++ b/ChangeLog @@ -0,0 +1,6 @@ +snapman (0.1) unstable; urgency=medium + + * Release 0.1. + + First release. + + -- Manuel Domínguez López <mdomlop@gmail.com > Wed, 03 Apr 2020 14:34:17 +0200 @@ -0,0 +1,7 @@ +PROGRAM_NAME=RGB Temperature Monitor +EXECUTABLE_NAME=rgbtemp +DESCRIPTION=Change RGB colors according to temperature. +VERSION=0.1 +AUTHOR=Manuel Domínguez López +SOURCE=https://github.com/mdomlop/rgbtemp +LICENSE=GPL-3 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3f157cb --- /dev/null +++ b/Makefile @@ -0,0 +1,44 @@ +PREFIX = '/usr' +DESTDIR = '' +CFLAGS = -march=native -mtune=native -O2 -ansi -pedantic -Wall + + +PROGRAM_NAME := $(shell grep ^PROGRAM_NAME INFO | cut -d= -f2) +EXECUTABLE_NAME := $(shell grep ^EXECUTABLE_NAME INFO | cut -d= -f2) +VERSION := $(shell grep ^VERSION INFO | cut -d= -f2) + +ARCHPKG = $(EXECUTABLE_NAME)-$(VERSION)-1-any.pkg.tar.xz + +src/$(EXECUTABLE_NAME): + +install: install_executables install_services +clean: arch_clean + rm -f src/$(EXECUTABLE_NAME) + +install_executables: + install -Dm 755 src/$(EXECUTABLE_NAME) $(DESTDIR)$(PREFIX)/bin/$(EXECUTABLE_NAME) + +install_services: + install -Dm 644 src/$(EXECUTABLE_NAME).service $(DESTDIR)/lib/systemd/system/$(EXECUTABLE_NAME).service + +uninstall: + rm -f $(PREFIX)/bin/$(EXECUTABLE_NAME) + rm -f /lib/systemd/system/$(EXECUTABLE_NAME).service + +arch_install: install_executables arch_install_services +arch_install_services: + install -Dm644 src/$(EXECUTABLE_NAME).service $(DESTDIR)$(PREFIX)/lib/systemd/system/$(EXECUTABLE_NAME).service + +arch_pkg: $(ARCHPKG) +$(ARCHPKG): PKGBUILD ChangeLog + makepkg -d + @echo + @echo Package done! + @echo You can install it as root with: + @echo pacman -U $@ + +arch_clean: + rm -rf pkg + rm -f $(ARCHPKG) + +.PHONY: clean arch_pkg arch_clean diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..a517f82 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,26 @@ +# Maintainer: Manuel Domínguez López <mdomlop at gmail dot com> + +_pkgver_year=2020 +_pkgver_month=04 +_pkgver_day=03 + +pkgname=rgbtemp +pkgver=0.1 +pkgrel=1 +pkgdesc='Change RGB colors according to temperature.' +url='https://github.com/mdomlop/rgbtemp' +source=() +license=('GPL3') +arch=('any') +depends=('msi-rgb') +changelog=ChangeLog + +build() { + cd "$startdir" + make + } + +package() { + cd "$startdir" + make arch_install DESTDIR="$pkgdir" +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..c0ff069 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +![rgbtemp-preview](https://raw.githubusercontent.com/mdomlop/rgbtemp/master/rgbtemp.gif "rgbtemp running") + +RGB temperature monitor +======================= + +Change RGB colors according to temperature. diff --git a/rgbtemp.gif b/rgbtemp.gif Binary files differnew file mode 100644 index 0000000..f6b75e8 --- /dev/null +++ b/rgbtemp.gif diff --git a/src/rgbtemp.c b/src/rgbtemp.c new file mode 100644 index 0000000..547fb57 --- /dev/null +++ b/src/rgbtemp.c @@ -0,0 +1,104 @@ +#include <stdio.h> +#include <stdlib.h> /* For exit() function */ +#include <unistd.h> /* For sleep() function */ +#include <signal.h> + +unsigned int sleep(unsigned int seconds); + +#define FALSE 0 +#define TRUE 1 + +#define BLACK "00000000 00000000 00000000" /* off */ +#define WHITE "FFFFFFFF FFFFFFFF FFFFFFFF" /* >2Fº */ +#define CYAN "00000000 FFFFFFFF FFFFFFFF" /* >30º */ +#define BLUE "00000000 00000000 FFFFFFFF" /* >40º */ +#define GREEN "00000000 FFFFFFFF 00000000" /* >50º */ +#define YELLOW "FFFFFFFF FFFFFFFF 00000000" /* >60º */ +#define ORANGE "FFFFFFFF 33333333 00000000" /* >70º */ +#define RED "FFFFFFFF 00000000 00000000" /* >80º */ +#define PINK "FFFFFFFF 00000000 FFFFFFFF" /* >90º */ + +char fileaddr[] = "/sys/class/hwmon/hwmon0/temp1_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; +} + +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); +} + +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; +} diff --git a/src/rgbtemp.service b/src/rgbtemp.service new file mode 100644 index 0000000..d70b76d --- /dev/null +++ b/src/rgbtemp.service @@ -0,0 +1,11 @@ +[Unit] +Description=Change RGB colors according to temperature + +[Service] +Type=simple +ExecStart=rgbtemp +KillMode=process +KillSignal=SIGUSR1 + +[Install] +WantedBy=multi-user.target |