summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2019-07-16 00:10:06 -0600
committerAaron Ball <nullspoon@oper.io>2019-07-16 00:10:06 -0600
commit4021b5cd0ae053afcacedbbe1b4554665819abb8 (patch)
tree660f328e30eff703dc1d8dde383d19a227937d6a /src
downloadkbd-fade-4021b5cd0ae053afcacedbbe1b4554665819abb8.tar.gz
kbd-fade-4021b5cd0ae053afcacedbbe1b4554665819abb8.tar.xz
Initial commit
This fades through the rainbow spectrum. The sleep time between next color change is confurable along with step (color hex distance).
Diffstat (limited to 'src')
-rw-r--r--src/main.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..0d035b4
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,122 @@
+/**
+ * Kbd-fade fades keyboard led backlighting
+ * Copyright (C) 2019 Aaron Ball <nullspoon@oper.io>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define COLORFILE "/sys/class/leds/system76::kbd_backlight/color_left"
+
+
+struct rgb {
+ int r;
+ int g;
+ int b;
+};
+
+
+void writecolor(struct rgb color, int usec_wait) {
+ FILE* fd;
+ fd = fopen(COLORFILE, "w");
+ fprintf(fd, "%02X%02X%02X\n", color.r, color.g, color.b);
+ fclose(fd);
+ usleep(usec_wait);
+}
+
+
+void load_current_state(struct rgb* srgb) {
+ char chan[3];
+ FILE* fd;
+
+ chan[3] = '\0';
+ fd = fopen(COLORFILE, "r");
+
+ chan[0] = fgetc(fd);
+ chan[1] = fgetc(fd);
+ srgb->r = atoi(chan);
+
+ chan[0] = fgetc(fd);
+ chan[1] = fgetc(fd);
+ srgb->g = atoi(chan);
+
+ chan[0] = fgetc(fd);
+ chan[1] = fgetc(fd);
+ srgb->b = atoi(chan);
+
+ fclose(fd);
+}
+
+
+int main(int argc, char* argv[]) {
+ int step = 4;
+ int wait = 10000;
+
+ struct rgb color;
+ load_current_state(&color);
+
+ // Set wait time between steps
+ if(argc >= 2)
+ wait = atoi(argv[1]) * 1000;
+
+ // Step size
+ if(argc == 3)
+ step = atoi(argv[2]);
+
+ while(1) {
+ // Increase green
+ while(color.g < 256) {
+ writecolor(color, wait);
+ color.g += step;
+ }
+ color.g = 255;
+
+ // Decrease red
+ while(color.r > 0) {
+ writecolor(color, wait);
+ color.r -= step;
+ }
+ color.r = 0;
+
+ // Increase blue
+ while(color.b < 256) {
+ writecolor(color, wait);
+ color.b += step;
+ }
+ color.b = 255;
+
+ // Decrease green
+ while(color.g > 0) {
+ writecolor(color, wait);
+ color.g -= step;
+ }
+ color.g = 0;
+
+ // Increase red
+ while(color.r < 256) {
+ writecolor(color, wait);
+ color.r += step;
+ }
+ color.r = 255;
+
+ // Decrease blue
+ while(color.b > 0) {
+ writecolor(color, wait);
+ color.b -= step;
+ }
+ color.b = 0;
+ }
+}

Generated by cgit