From e61da07522a060da98fa3a56db3d0360469b26cf Mon Sep 17 00:00:00 2001 From: auric <104602845+ihateamongus@users.noreply.github.com> Date: Mon, 8 Sep 2025 21:19:14 -0500 Subject: organize repository layout --- oldresources/breathing-exo-daemon/breathing.d | Bin 15912 -> 0 bytes oldresources/breathing-exo-daemon/display/display | Bin 15688 -> 0 bytes .../breathing-exo-daemon/display/display-shm-x.c | 94 --------- .../breathing-exo-daemon/display/display-shm.c | 40 ---- .../breathing-exo-daemon/display/display-x | Bin 16304 -> 0 bytes oldresources/breathing-exo-daemon/exo.c | 99 --------- oldresources/breathing-exo-daemon/v2/breathing.d | Bin 16392 -> 0 bytes oldresources/breathing-exo-daemon/v2/exo.c | 150 -------------- .../breathing-exo-daemon/v3-shm/breathing.d | Bin 16480 -> 0 bytes oldresources/breathing-exo-daemon/v3-shm/exo.c | 178 ----------------- .../breathing-exo-daemon/v3-shm/exo.c.oldnosync | 222 --------------------- .../breathing-exo-daemon/v4-clean-shm/Makefile | 17 -- .../breathing-exo-daemon/v4-clean-shm/breathing.d | Bin 20224 -> 0 bytes .../breathing-exo-daemon/v4-clean-shm/exo.c | 158 --------------- .../breathing-exo-daemon/v4-clean-shm/loadtest.c | 10 - .../breathing-exo-daemon/v4-clean-shm/test | Bin 15496 -> 0 bytes 16 files changed, 968 deletions(-) delete mode 100755 oldresources/breathing-exo-daemon/breathing.d delete mode 100755 oldresources/breathing-exo-daemon/display/display delete mode 100644 oldresources/breathing-exo-daemon/display/display-shm-x.c delete mode 100644 oldresources/breathing-exo-daemon/display/display-shm.c delete mode 100755 oldresources/breathing-exo-daemon/display/display-x delete mode 100644 oldresources/breathing-exo-daemon/exo.c delete mode 100755 oldresources/breathing-exo-daemon/v2/breathing.d delete mode 100644 oldresources/breathing-exo-daemon/v2/exo.c delete mode 100755 oldresources/breathing-exo-daemon/v3-shm/breathing.d delete mode 100644 oldresources/breathing-exo-daemon/v3-shm/exo.c delete mode 100644 oldresources/breathing-exo-daemon/v3-shm/exo.c.oldnosync delete mode 100644 oldresources/breathing-exo-daemon/v4-clean-shm/Makefile delete mode 100755 oldresources/breathing-exo-daemon/v4-clean-shm/breathing.d delete mode 100644 oldresources/breathing-exo-daemon/v4-clean-shm/exo.c delete mode 100644 oldresources/breathing-exo-daemon/v4-clean-shm/loadtest.c delete mode 100755 oldresources/breathing-exo-daemon/v4-clean-shm/test (limited to 'oldresources/breathing-exo-daemon') diff --git a/oldresources/breathing-exo-daemon/breathing.d b/oldresources/breathing-exo-daemon/breathing.d deleted file mode 100755 index 8114ecb..0000000 Binary files a/oldresources/breathing-exo-daemon/breathing.d and /dev/null differ diff --git a/oldresources/breathing-exo-daemon/display/display b/oldresources/breathing-exo-daemon/display/display deleted file mode 100755 index b181258..0000000 Binary files a/oldresources/breathing-exo-daemon/display/display and /dev/null differ diff --git a/oldresources/breathing-exo-daemon/display/display-shm-x.c b/oldresources/breathing-exo-daemon/display/display-shm-x.c deleted file mode 100644 index 2695fd0..0000000 --- a/oldresources/breathing-exo-daemon/display/display-shm-x.c +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#define SHM_NAME "/breathing_color_shm" // Shared memory name (same as in exo.c) -#define COLOR_SIZE 8 // Size for one color (e.g., #RRGGBB) - -int main() { - // Open shared memory object - int shm_fd = shm_open(SHM_NAME, O_RDONLY, 0666); - if (shm_fd == -1) { - perror("Failed to open shared memory"); - return 1; - } - - // Map shared memory into the process's address space - char *shm_ptr = mmap(NULL, COLOR_SIZE, PROT_READ, MAP_SHARED, shm_fd, 0); - if (shm_ptr == MAP_FAILED) { - perror("Failed to map shared memory"); - close(shm_fd); - return 1; - } - - // Initialize X11 - Display *display = XOpenDisplay(NULL); - if (display == NULL) { - perror("Unable to open X display"); - munmap(shm_ptr, COLOR_SIZE); - close(shm_fd); - return 1; - } - - // Create a window - int screen = DefaultScreen(display); - Window window = XCreateSimpleWindow(display, RootWindow(display, screen), 0, 0, 400, 400, 1, BlackPixel(display, screen), BlackPixel(display, screen)); - - // Set window properties - XStoreName(display, window, "Breathing Color Display"); - XMapWindow(display, window); - - // Set the window's background color initially - XFlush(display); - - // Start reading colors and updating the window - while (1) { - // Read the current color from shared memory - XColor color; - if (XParseColor(display, DefaultColormap(display, screen), shm_ptr, &color) == 0) { - fprintf(stderr, "Invalid color in shared memory: %s\n", shm_ptr); - continue; - } - - // Allocate the color in the X server - if (XAllocColor(display, DefaultColormap(display, screen), &color) == 0) { - fprintf(stderr, "Failed to allocate color: %s\n", shm_ptr); - continue; - } - - // Change the background color of the window - XSetWindowBackground(display, window, color.pixel); - XClearWindow(display, window); - - // Process X events - XEvent event; - while (XPending(display)) { - XNextEvent(display, &event); - if (event.type == ClientMessage) { - // Exit on close event (or any client message) - XDestroyWindow(display, window); - XCloseDisplay(display); - munmap(shm_ptr, COLOR_SIZE); - close(shm_fd); - return 0; - } - } - - // Sleep a little before checking for the next color update - usleep(100000); // 0.1 seconds - } - - // Clean up - XDestroyWindow(display, window); - XCloseDisplay(display); - munmap(shm_ptr, COLOR_SIZE); - close(shm_fd); - - return 0; -} - diff --git a/oldresources/breathing-exo-daemon/display/display-shm.c b/oldresources/breathing-exo-daemon/display/display-shm.c deleted file mode 100644 index 435077a..0000000 --- a/oldresources/breathing-exo-daemon/display/display-shm.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#define SHM_NAME "/breathing_color_shm" // Shared memory name (same as in exo.c) -#define COLOR_SIZE 8 // Size for one color (e.g., #RRGGBB) - -int main() { - int shm_fd; - char *shm_ptr; - - // Open shared memory object - shm_fd = shm_open(SHM_NAME, O_RDONLY, 0666); - if (shm_fd == -1) { - perror("Failed to open shared memory"); - return 1; - } - - // Map shared memory into the process's address space - shm_ptr = mmap(NULL, COLOR_SIZE, PROT_READ, MAP_SHARED, shm_fd, 0); - if (shm_ptr == MAP_FAILED) { - perror("Failed to map shared memory"); - close(shm_fd); - return 1; - } - - // Read the color from shared memory and print it - printf("Breathing color: %s\n", shm_ptr); - - // Clean up - munmap(shm_ptr, COLOR_SIZE); - close(shm_fd); - - return 0; -} - diff --git a/oldresources/breathing-exo-daemon/display/display-x b/oldresources/breathing-exo-daemon/display/display-x deleted file mode 100755 index 87622d2..0000000 Binary files a/oldresources/breathing-exo-daemon/display/display-x and /dev/null differ diff --git a/oldresources/breathing-exo-daemon/exo.c b/oldresources/breathing-exo-daemon/exo.c deleted file mode 100644 index 858cd57..0000000 --- a/oldresources/breathing-exo-daemon/exo.c +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include -#include -#include -#include -#include - -/* Convert sRGB to Linear RGB */ -double srgb_to_linear(double value) { - if (value <= 0.04045) { - return value / 12.92; - } else { - return pow((value + 0.055) / 1.055, 2.4); - } -} - -/* Convert Linear RGB to sRGB */ -double linear_to_srgb(double value) { - if (value <= 0.0031308) { - return value * 12.92; - } else { - return 1.055 * pow(value, 1.0 / 2.4) - 0.055; - } -} - -/* Interpolate between two colors in Linear RGB space */ -void interpolate_color_linear(const char *color1, const char *color2, double t, char *output) { - unsigned int r1, g1, b1, r2, g2, b2; - sscanf(color1, "#%02x%02x%02x", &r1, &g1, &b1); - sscanf(color2, "#%02x%02x%02x", &r2, &g2, &b2); - - // Convert sRGB to linear RGB - double lr1 = srgb_to_linear(r1 / 255.0); - double lg1 = srgb_to_linear(g1 / 255.0); - double lb1 = srgb_to_linear(b1 / 255.0); - - double lr2 = srgb_to_linear(r2 / 255.0); - double lg2 = srgb_to_linear(g2 / 255.0); - double lb2 = srgb_to_linear(b2 / 255.0); - - // Interpolate in linear RGB space - double lr = lr1 + t * (lr2 - lr1); - double lg = lg1 + t * (lg2 - lg1); - double lb = lb1 + t * (lb2 - lb1); - - // Convert back to sRGB - unsigned int r = (unsigned int)(linear_to_srgb(lr) * 255.0); - unsigned int g = (unsigned int)(linear_to_srgb(lg) * 255.0); - unsigned int b = (unsigned int)(linear_to_srgb(lb) * 255.0); - - // Format as hex output - snprintf(output, 8, "#%02x%02x%02x", r, g, b); -} - -int main() { - /* Define the colors to cycle through */ - const char *breathing_colors[] = { - "#ffe667", // Yellow - "#f27049", // Orange - "#3dd762", // Green - }; - int color_count = sizeof(breathing_colors) / sizeof(breathing_colors[0]); - - int current_index = 0; - double t = 0.0; // Interpolation factor - char current_color[8]; - - struct timespec ts = { 0, 5000000 }; // 5ms sleep - - while (1) { - /* Interpolate the current color */ - interpolate_color_linear( - breathing_colors[current_index], - breathing_colors[(current_index + 1) % color_count], - t, - current_color - ); - - /* Write the current color to a file */ - FILE *f = fopen("/tmp/breathing_color", "w"); - if (f) { - fprintf(f, "%s\n", current_color); - fclose(f); - } - - /* Increment interpolation factor */ - t += 0.005; // Adjust the speed of transition (smaller value = slower transition) - if (t >= 1.0) { - t = 0.0; // Reset interpolation - current_index = (current_index + 1) % color_count; // Move to the next color - } - - /* Sleep for 5ms */ - nanosleep(&ts, NULL); - } - - return 0; -} - diff --git a/oldresources/breathing-exo-daemon/v2/breathing.d b/oldresources/breathing-exo-daemon/v2/breathing.d deleted file mode 100755 index 2af754c..0000000 Binary files a/oldresources/breathing-exo-daemon/v2/breathing.d and /dev/null differ diff --git a/oldresources/breathing-exo-daemon/v2/exo.c b/oldresources/breathing-exo-daemon/v2/exo.c deleted file mode 100644 index 98027af..0000000 --- a/oldresources/breathing-exo-daemon/v2/exo.c +++ /dev/null @@ -1,150 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#define BREATHING_INTERVAL 90 // in milliseconds -#define STRESS_THRESHOLD 8.0 // System load threshold for stress mode - -// Default and stress colors -const char *default_colors[] = { - "#ffe667", // Yellow - "#f27049", // Orange - "#3dd762" // Green -}; - -const char *stress_colors[] = { - "#f60000", // Bright Red - "#8e0000", // Dark Red - "#a10000", // Muted Red - "#5a0000" // Deep Crimson -}; - -// Convert sRGB to Linear RGB -double srgb_to_linear(double value) { - if (value <= 0.04045) - return value / 12.92; - else - return pow((value + 0.055) / 1.055, 2.4); -} - -// Convert Linear RGB to sRGB -double linear_to_srgb(double value) { - if (value <= 0.0031308) - return value * 12.92; - else - return 1.055 * pow(value, 1.0 / 2.4) - 0.055; -} - -// Function to interpolate between two colors in linear RGB space -void interpolate_color(const char *color1, const char *color2, double t, char *output) { - unsigned int r1, g1, b1, r2, g2, b2; - double lr1, lg1, lb1, lr2, lg2, lb2, lr, lg, lb; - - // Parse the input hex colors - sscanf(color1, "#%02x%02x%02x", &r1, &g1, &b1); - sscanf(color2, "#%02x%02x%02x", &r2, &g2, &b2); - - // Convert sRGB to linear RGB - lr1 = srgb_to_linear(r1 / 255.0); - lg1 = srgb_to_linear(g1 / 255.0); - lb1 = srgb_to_linear(b1 / 255.0); - - lr2 = srgb_to_linear(r2 / 255.0); - lg2 = srgb_to_linear(g2 / 255.0); - lb2 = srgb_to_linear(b2 / 255.0); - - // Interpolate in linear RGB space - lr = lr1 + t * (lr2 - lr1); - lg = lg1 + t * (lg2 - lg1); - lb = lb1 + t * (lb2 - lb1); - - // Convert back to sRGB - r1 = round(linear_to_srgb(lr) * 255); - g1 = round(linear_to_srgb(lg) * 255); - b1 = round(linear_to_srgb(lb) * 255); - - // Output the interpolated color as hex - snprintf(output, 8, "#%02x%02x%02x", r1, g1, b1); -} - -// Function to read system load -double get_system_load() { - double load; - FILE *f = fopen("/proc/loadavg", "r"); - if (f) { - fscanf(f, "%lf", &load); - fclose(f); - } else { - perror("Failed to read /proc/loadavg"); - load = 0.0; - } - return load; -} - -// Function to update breathing color -void update_breathing_color() { - static int color_index = 0; - static double t = 0.0; - char new_color[8]; - - // Determine the current color set (default or stress) - const char **current_colors; - int num_colors; - - if (get_system_load() > STRESS_THRESHOLD) { - current_colors = stress_colors; - num_colors = sizeof(stress_colors) / sizeof(stress_colors[0]); - } else { - current_colors = default_colors; - num_colors = sizeof(default_colors) / sizeof(default_colors[0]); - } - - // Interpolate between the current and next color in the palette - interpolate_color( - current_colors[color_index], - current_colors[(color_index + 1) % num_colors], - t, - new_color - ); - - // Write the new color to the output file - FILE *f = fopen("/tmp/breathing_color", "w"); - if (f) { - fprintf(f, "%s\n", new_color); - fclose(f); - } - - // Update interpolation factor and color index - t += 0.02; // Adjust speed of interpolation here - if (t >= 1.0) { - t = 0.0; - color_index = (color_index + 1) % num_colors; - } -} - -int main() { - struct timespec last_breathing_update = {0}, now; - - // Initialize breathing colors - clock_gettime(CLOCK_MONOTONIC, &last_breathing_update); - - while (1) { - clock_gettime(CLOCK_MONOTONIC, &now); - - // Update breathing colors - double elapsed_breathing = (now.tv_sec - last_breathing_update.tv_sec) * 1000.0 + - (now.tv_nsec - last_breathing_update.tv_nsec) / 1.0e6; - if (elapsed_breathing >= BREATHING_INTERVAL) { - update_breathing_color(); - last_breathing_update = now; - } - - usleep(10000); // Sleep to prevent excessive CPU usage - } - - return 0; -} - diff --git a/oldresources/breathing-exo-daemon/v3-shm/breathing.d b/oldresources/breathing-exo-daemon/v3-shm/breathing.d deleted file mode 100755 index 469ea6a..0000000 Binary files a/oldresources/breathing-exo-daemon/v3-shm/breathing.d and /dev/null differ diff --git a/oldresources/breathing-exo-daemon/v3-shm/exo.c b/oldresources/breathing-exo-daemon/v3-shm/exo.c deleted file mode 100644 index 5898280..0000000 --- a/oldresources/breathing-exo-daemon/v3-shm/exo.c +++ /dev/null @@ -1,178 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BREATHING_INTERVAL 90 // in milliseconds -#define STRESS_THRESHOLD 8.0 // System load threshold for stress mode -#define SHM_NAME "/breathing_color_shm" // Shared memory name -#define SOUND_FILE_STRESS "/usr/local/share/sounds/AresEnraged.wav" // Sound for stress mode -#define SOUND_FILE_NORMAL "/usr/local/share/sounds/ThanatosVent.wav" // Sound for normal mode -#define DEFAULT_COLORS 3 -#define STRESS_COLORS 4 - -const double default_colors[DEFAULT_COLORS][3] = { - {1.0, 0.91, 0.4}, //Y - {0.95, 0.44, 0.28}, //O - {0.24, 0.85, 0.38} //G -}; - -const double stress_colors[STRESS_COLORS][3] = { - {0.96, 0.0, 0.0}, //Bright - {0.55, 0.0, 0.0}, //Dark - {0.64, 0.0, 0.0}, //Muted - {0.35, 0.0, 0.0}, //Deep -}; - -// Convert Linear RGB to sRGB -double linear_to_srgb(double value) { - if (value <= 0.0031308) - return value * 12.92; - else - return 1.055 * pow(value, 1.0 / 2.4) - 0.055; -} - -// Function to interpolate between two colors in linear RGB space -void interpolate_color(const double *color1, const double *color2, double t, char *output) { - unsigned int r1, g1, b1, r2, g2, b2; - double lr1, lg1, lb1, lr2, lg2, lb2, lr, lg, lb; - - lr1 = color1[0]; - lg1 = color1[1]; - lb1 = color1[2]; - - lr2 = color2[0]; - lg2 = color2[1]; - lb2 = color2[2]; - - // Interpolate in linear RGB space - lr = lr1 + t * (lr2 - lr1); - lg = lg1 + t * (lg2 - lg1); - lb = lb1 + t * (lb2 - lb1); - - // Convert back to sRGB - r1 = round(linear_to_srgb(lr) * 255); - g1 = round(linear_to_srgb(lg) * 255); - b1 = round(linear_to_srgb(lb) * 255); - - // Output the interpolated color as hex - snprintf(output, 8, "#%02x%02x%02x", r1, g1, b1); -} - -// Function to read system load -double get_system_load() { - double load; - FILE *f = fopen("/proc/loadavg", "r"); - if (f) { - fscanf(f, "%lf", &load); - fclose(f); - } else { - perror("Failed to read /proc/loadavg"); - load = 0.0; - } - return load; -} - -// Function to play the sound (non-blocking) -void play_sound_background(const char *sound_file) { - if (fork() == 0) { // Child process - // Use paplay or any other sound player to play the sound - char command[100]; - snprintf(command, sizeof(command), "paplay %s", sound_file); - system(command); - // If execlp fails, exit the child process - perror("execlp failed"); - exit(1); - } -} - -// Function to update breathing color -void update_breathing_color(char *shm_ptr, double *last_load, int *in_stress_mode) { - static int color_index = 0; - static double t = 0.0; - char new_color[8]; - double current_load = get_system_load(); - int new_stress_mode = current_load > STRESS_THRESHOLD; - - // Trigger sound on load crossing (up or down) - if (new_stress_mode != *in_stress_mode) { - if (new_stress_mode) { - play_sound_background(SOUND_FILE_STRESS); // Play stress sound - } else { - play_sound_background(SOUND_FILE_NORMAL); // Play normal sound - } - *in_stress_mode = new_stress_mode; - } - - // Determine the current color set (default or stress) - const double (*current_colors)[3]; - int num_colors; - - if (new_stress_mode) { - current_colors = stress_colors; - num_colors = STRESS_COLORS; - } else { - current_colors = default_colors; - num_colors = DEFAULT_COLORS; - } - - // Interpolate between the current and next color in the palette - interpolate_color( - current_colors[color_index], - current_colors[(color_index + 1) % num_colors], - t, - new_color - ); - - // Store the new color to shared memory (for example purposes) - snprintf(shm_ptr, 8, "%s", new_color); - - // Update interpolation factor and color index - t += 0.02; // Adjust speed of interpolation here - if (t >= 1.0) { - t = 0.0; - color_index = (color_index + 1) % num_colors; - } -} - -int main() { - struct timespec last_breathing_update = {0}, now; - double last_load = 0.0; - int in_stress_mode = 0; - char *shm_ptr; - - // Initialize shared memory for color - int shm_fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0666); - ftruncate(shm_fd, 8); // Set size of shared memory - shm_ptr = mmap(NULL, 8, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); - - // Initialize breathing colors - clock_gettime(CLOCK_MONOTONIC, &last_breathing_update); - - while (1) { - clock_gettime(CLOCK_MONOTONIC, &now); - - // Update breathing colors - double elapsed_breathing = (now.tv_sec - last_breathing_update.tv_sec) * 1000.0 + - (now.tv_nsec - last_breathing_update.tv_nsec) / 1.0e6; - if (elapsed_breathing >= BREATHING_INTERVAL) { - update_breathing_color(shm_ptr, &last_load, &in_stress_mode); - last_breathing_update = now; - } - - usleep(100000); // Sleep for 0.1 seconds to reduce CPU usage - } - - // Clean up shared memory - munmap(shm_ptr, 8); - shm_unlink(SHM_NAME); - - return 0; -} - diff --git a/oldresources/breathing-exo-daemon/v3-shm/exo.c.oldnosync b/oldresources/breathing-exo-daemon/v3-shm/exo.c.oldnosync deleted file mode 100644 index 29ac2a6..0000000 --- a/oldresources/breathing-exo-daemon/v3-shm/exo.c.oldnosync +++ /dev/null @@ -1,222 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BREATHING_INTERVAL 90 // in milliseconds -#define STRESS_THRESHOLD 8.0 // System load threshold for stress mode -#define SHM_NAME "/breathing_color_shm" // Shared memory name -#define SOUND_FILE_STRESS "/usr/local/share/sounds/AresEnraged.wav" // Sound for stress mode -#define SOUND_FILE_NORMAL "/usr/local/share/sounds/ThanatosVent.wav" // Sound for normal mode - -// Default and stress colors -const char *default_colors[] = { - "#ffe667", // Yellow - "#f27049", // Orange - "#3dd762" // Green -}; - -const char *stress_colors[] = { - "#f60000", // Bright Red - "#8e0000", // Dark Red - "#a10000", // Muted Red - "#5a0000" // Deep Crimson -}; - -// Convert sRGB to Linear RGB -double srgb_to_linear(double value) { - if (value <= 0.04045) - return value / 12.92; - else - return pow((value + 0.055) / 1.055, 2.4); -} - -// Convert Linear RGB to sRGB -double linear_to_srgb(double value) { - if (value <= 0.0031308) - return value * 12.92; - else - return 1.055 * pow(value, 1.0 / 2.4) - 0.055; -} - -// Function to interpolate between two colors in linear RGB space -void interpolate_color(const char *color1, const char *color2, double t, char *output) { - unsigned int r1, g1, b1, r2, g2, b2; - double lr1, lg1, lb1, lr2, lg2, lb2, lr, lg, lb; - - // Parse the input hex colors - sscanf(color1, "#%02x%02x%02x", &r1, &g1, &b1); - sscanf(color2, "#%02x%02x%02x", &r2, &g2, &b2); - - // Convert sRGB to linear RGB - lr1 = srgb_to_linear(r1 / 255.0); - lg1 = srgb_to_linear(g1 / 255.0); - lb1 = srgb_to_linear(b1 / 255.0); - - lr2 = srgb_to_linear(r2 / 255.0); - lg2 = srgb_to_linear(g2 / 255.0); - lb2 = srgb_to_linear(b2 / 255.0); - - // Interpolate in linear RGB space - lr = lr1 + t * (lr2 - lr1); - lg = lg1 + t * (lg2 - lg1); - lb = lb1 + t * (lb2 - lb1); - - // Convert back to sRGB - r1 = round(linear_to_srgb(lr) * 255); - g1 = round(linear_to_srgb(lg) * 255); - b1 = round(linear_to_srgb(lb) * 255); - - // Output the interpolated color as hex - snprintf(output, 8, "#%02x%02x%02x", r1, g1, b1); -} - -// Function to read system load -double get_system_load() { - double load; - FILE *f = fopen("/proc/loadavg", "r"); - if (f) { - fscanf(f, "%lf", &load); - fclose(f); - } else { - perror("Failed to read /proc/loadavg"); - load = 0.0; - } - return load; -} - -// Function to play the sound (once) -void play_sound(const char *sound_file) { - snd_pcm_t *pcm_handle; - snd_pcm_hw_params_t *params; - snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE; - int rate = 44100; - int channels = 2; - FILE *wav_file = fopen(sound_file, "rb"); - if (!wav_file) { - perror("Failed to open WAV file"); - return; - } - - // Initialize ALSA PCM playback - if (snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, 0) < 0) { - perror("Failed to open PCM device"); - fclose(wav_file); - return; - } - - snd_pcm_hw_params_alloca(¶ms); - snd_pcm_hw_params_any(pcm_handle, params); - snd_pcm_hw_params_set_access(pcm_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); - snd_pcm_hw_params_set_format(pcm_handle, params, format); - snd_pcm_hw_params_set_rate_near(pcm_handle, params, &rate, 0); - snd_pcm_hw_params_set_channels(pcm_handle, params, channels); - snd_pcm_hw_params(pcm_handle, params); - - // Playback loop: Play the entire WAV file - short buffer[44100 * channels]; // 1 second of audio buffer - size_t bytes_read; - - while ((bytes_read = fread(buffer, 1, sizeof(buffer), wav_file)) > 0) { - if (snd_pcm_writei(pcm_handle, buffer, bytes_read / (channels * 2)) < 0) { - perror("Error writing to PCM device"); - break; - } - } - - fclose(wav_file); - snd_pcm_drain(pcm_handle); - snd_pcm_close(pcm_handle); -} - -// Function to update breathing color -void update_breathing_color(char *shm_ptr, double *last_load, int *in_stress_mode) { - static int color_index = 0; - static double t = 0.0; - char new_color[8]; - double current_load = get_system_load(); - int new_stress_mode = current_load > STRESS_THRESHOLD; - - // Trigger sound on load crossing (up or down) - if (new_stress_mode != *in_stress_mode) { - if (new_stress_mode) { - play_sound(SOUND_FILE_STRESS); // Play stress sound - } else { - play_sound(SOUND_FILE_NORMAL); // Play normal sound - } - *in_stress_mode = new_stress_mode; - } - - // Determine the current color set (default or stress) - const char **current_colors; - int num_colors; - - if (new_stress_mode) { - current_colors = stress_colors; - num_colors = sizeof(stress_colors) / sizeof(stress_colors[0]); - } else { - current_colors = default_colors; - num_colors = sizeof(default_colors) / sizeof(default_colors[0]); - } - - // Interpolate between the current and next color in the palette - interpolate_color( - current_colors[color_index], - current_colors[(color_index + 1) % num_colors], - t, - new_color - ); - - // Store the new color to shared memory (for example purposes) - snprintf(shm_ptr, 8, "%s", new_color); - - // Update interpolation factor and color index - t += 0.02; // Adjust speed of interpolation here - if (t >= 1.0) { - t = 0.0; - color_index = (color_index + 1) % num_colors; - } -} - -int main() { - struct timespec last_breathing_update = {0}, now; - double last_load = 0.0; - int in_stress_mode = 0; - char *shm_ptr; - - // Initialize shared memory for color - int shm_fd = shm_open(SHM_NAME, O_CREAT | O_RDWR, 0666); - ftruncate(shm_fd, 8); // Set size of shared memory - shm_ptr = mmap(NULL, 8, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); - - // Initialize breathing colors - clock_gettime(CLOCK_MONOTONIC, &last_breathing_update); - - while (1) { - clock_gettime(CLOCK_MONOTONIC, &now); - - // Update breathing colors - double elapsed_breathing = (now.tv_sec - last_breathing_update.tv_sec) * 1000.0 + - (now.tv_nsec - last_breathing_update.tv_nsec) / 1.0e6; - if (elapsed_breathing >= BREATHING_INTERVAL) { - update_breathing_color(shm_ptr, &last_load, &in_stress_mode); - last_breathing_update = now; - } - - usleep(100000); // Sleep for 0.1 seconds to reduce CPU usage - } - - // Clean up shared memory - munmap(shm_ptr, 8); - shm_unlink(SHM_NAME); - - return 0; -} - diff --git a/oldresources/breathing-exo-daemon/v4-clean-shm/Makefile b/oldresources/breathing-exo-daemon/v4-clean-shm/Makefile deleted file mode 100644 index 2fef9cc..0000000 --- a/oldresources/breathing-exo-daemon/v4-clean-shm/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -CC := gcc -CFLAGS := -std=c11 -O2 -Wall -Wextra -pedantic -D_GNU_SOURCE -LDFLAGS := -lm -TARGET := breathing.d - -SRC := exo.c - -all: $(TARGET) - -$(TARGET): $(SRC) - $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) - -clean: - rm -f $(TARGET) *.o - -.PHONY: all clean - diff --git a/oldresources/breathing-exo-daemon/v4-clean-shm/breathing.d b/oldresources/breathing-exo-daemon/v4-clean-shm/breathing.d deleted file mode 100755 index cc85b67..0000000 Binary files a/oldresources/breathing-exo-daemon/v4-clean-shm/breathing.d and /dev/null differ diff --git a/oldresources/breathing-exo-daemon/v4-clean-shm/exo.c b/oldresources/breathing-exo-daemon/v4-clean-shm/exo.c deleted file mode 100644 index 9ab1f24..0000000 --- a/oldresources/breathing-exo-daemon/v4-clean-shm/exo.c +++ /dev/null @@ -1,158 +0,0 @@ -// breathing.d (hardened) -#define _POSIX_C_SOURCE 200809L -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define SHM_NAME "/breathing_color_shm" -#define MAGIC 0xBEEFCAFEu -#define VERSION 1u - -// ~12–18s full loop as before -#define STEP_MS 90 -#define STEP_T 0.02 - -// For your 7950X3D (32 threads), make “stress” mean it: -#define STRESS_THRESHOLD 16.0 - -// Sounds (optional) -#define SOUND_FILE_STRESS "/usr/local/share/sounds/AresEnraged.wav" -#define SOUND_FILE_NORMAL "/usr/local/share/sounds/ThanatosVent.wav" - -// Shared block (16B aligned, seqlock protocol: even seq = stable) -typedef struct { - uint32_t magic; - uint32_t version; - _Atomic uint32_t seq; - char color[8]; // "#RRGGBB" + '\0' guaranteed -} shm_color_t; - -static const double default_colors[][3] = { - {1.0, 0.91, 0.40}, // Y - {0.95, 0.44, 0.28}, // O - {0.24, 0.85, 0.38}, // G -}; -static const size_t DEFAULT_COLORS = sizeof(default_colors)/sizeof(default_colors[0]); - -static const double stress_colors[][3] = { - {0.96, 0.00, 0.00}, - {0.55, 0.00, 0.00}, - {0.64, 0.00, 0.00}, - {0.35, 0.00, 0.00}, -}; -static const size_t STRESS_COLORS = sizeof(stress_colors)/sizeof(stress_colors[0]); - -static inline double clamp01(double v) { - if (isnan(v) || isinf(v)) return 0.0; - if (v < 0.0) return 0.0; - if (v > 1.0) return 1.0; - return v; -} -static inline double srgb_to_linear(double v) { - v = clamp01(v); - return (v <= 0.04045) ? (v / 12.92) : pow((v + 0.055)/1.055, 2.4); -} -static inline double linear_to_srgb(double v) { - v = clamp01(v); - return (v <= 0.0031308) ? (v * 12.92) : (1.055*pow(v, 1.0/2.4) - 0.055); -} -static void lerp_color(const double c1[3], const double c2[3], double t, char out[8]) { - double lr = srgb_to_linear(c1[0]) + t*(srgb_to_linear(c2[0]) - srgb_to_linear(c1[0])); - double lg = srgb_to_linear(c1[1]) + t*(srgb_to_linear(c2[1]) - srgb_to_linear(c1[1])); - double lb = srgb_to_linear(c1[2]) + t*(srgb_to_linear(c2[2]) - srgb_to_linear(c1[2])); - unsigned r = (unsigned)lround(clamp01(linear_to_srgb(lr))*255.0); - unsigned g = (unsigned)lround(clamp01(linear_to_srgb(lg))*255.0); - unsigned b = (unsigned)lround(clamp01(linear_to_srgb(lb))*255.0); - snprintf(out, 8, "#%02x%02x%02x", r, g, b); -} -static double sys_load(void) { - double l[3] = {0,0,0}; - if (getloadavg(l, 1) == 1) return l[0]; - return 0.0; -} -static void play_once(const char *file) { - pid_t p = fork(); - if (p == 0) { // child - // Try PipeWire first, then Pulse - // execlp("pw-play", "pw-play", file, (char*)NULL); // TRIM: Pulse not installed - execlp("paplay", "paplay", file, (char*)NULL); - _exit(127); - } -} -static void sleep_ms(long ms) { - struct timespec req = { .tv_sec = ms/1000, .tv_nsec = (ms%1000)*1000000L }; - while (clock_nanosleep(CLOCK_MONOTONIC, 0, &req, &req) == EINTR) {} -} - -int main(void) { - // Don’t accumulate zombies if sound player exits - struct sigaction sa = {0}; - sa.sa_handler = SIG_IGN; sigaction(SIGCHLD, &sa, NULL); - - int fd = shm_open(SHM_NAME, O_CREAT|O_RDWR, 0666); - if (fd < 0) { perror("shm_open"); return 1; } - if (ftruncate(fd, sizeof(shm_color_t)) != 0) { perror("ftruncate"); return 1; } - - shm_color_t *blk = mmap(NULL, sizeof(shm_color_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); - if (blk == MAP_FAILED) { perror("mmap"); return 1; } - close(fd); - - // Initialize header - blk->magic = MAGIC; - blk->version = VERSION; - atomic_store(&blk->seq, 0); - memcpy(blk->color, "#9ab5ff", 8); - - size_t idx = 0; - double t = 0.0; - int stress = 0; - int last_stress = -1; - - for (;;) { - // mode & palette - double load = sys_load(); - stress = (load > STRESS_THRESHOLD); - - const double (*pal)[3] = stress ? stress_colors : default_colors; - size_t n = stress ? STRESS_COLORS : DEFAULT_COLORS; - - // sound on edge only - if (stress != last_stress) { - play_once(stress ? SOUND_FILE_STRESS : SOUND_FILE_NORMAL); - last_stress = stress; - } - - // color - char hex[8]; - const double *c1 = pal[idx]; - const double *c2 = pal[(idx+1)%n]; - lerp_color(c1, c2, t, hex); - - // seqlock write: odd while writing, even when stable - uint32_t s = atomic_load_explicit(&blk->seq, memory_order_relaxed); - atomic_store_explicit(&blk->seq, s+1, memory_order_release); // mark write begin - memcpy(blk->color, hex, 8); - atomic_store_explicit(&blk->seq, s+2, memory_order_release); // mark write end - - // step - t += STEP_T; - if (t >= 1.0) { t = 0.0; idx = (idx+1)%n; } - - sleep_ms(STEP_MS); - } - - // unreachable in simple daemon mode - // munmap(blk, sizeof(*blk)); shm_unlink(SHM_NAME); - // return 0; -} - diff --git a/oldresources/breathing-exo-daemon/v4-clean-shm/loadtest.c b/oldresources/breathing-exo-daemon/v4-clean-shm/loadtest.c deleted file mode 100644 index 8cb3162..0000000 --- a/oldresources/breathing-exo-daemon/v4-clean-shm/loadtest.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#define _GNU_SOURCE -int main() { - double l[3]; - if (getloadavg(l, 3) != -1) - printf("load: %.2f %.2f %.2f\n", l[0], l[1], l[2]); - return 0; -} - diff --git a/oldresources/breathing-exo-daemon/v4-clean-shm/test b/oldresources/breathing-exo-daemon/v4-clean-shm/test deleted file mode 100755 index 501cf97..0000000 Binary files a/oldresources/breathing-exo-daemon/v4-clean-shm/test and /dev/null differ -- cgit v1.2.3