From 814821727e0107a2cf3247eb807ed1f3703b7327 Mon Sep 17 00:00:00 2001 From: HorrorTroll Date: Sat, 22 Jan 2022 12:31:27 +0700 Subject: [Keyboard] Move Handwired K552 into my folder name (#15973) --- .../keymaps/default/led/random_breath_rainbow.c | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 keyboards/horrortroll/handwired_k552/keymaps/default/led/random_breath_rainbow.c (limited to 'keyboards/horrortroll/handwired_k552/keymaps/default/led/random_breath_rainbow.c') diff --git a/keyboards/horrortroll/handwired_k552/keymaps/default/led/random_breath_rainbow.c b/keyboards/horrortroll/handwired_k552/keymaps/default/led/random_breath_rainbow.c new file mode 100644 index 0000000000..041417477b --- /dev/null +++ b/keyboards/horrortroll/handwired_k552/keymaps/default/led/random_breath_rainbow.c @@ -0,0 +1,55 @@ +/* Copyright 2021 HorrorTroll + * + * 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 2 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 . + */ + +static uint8_t offset[DRIVER_LED_TOTAL]; + +static void doRandom_breath_rainbow(int i, effect_params_t* params) { + if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) return; + uint16_t time = scale16by8(g_rgb_timer, rgb_matrix_config.speed / 6); + + if (rand() * 50 == 1) { + if (rand() * 2 == 1) { + offset[i]++; + } + else { + offset[i]--; + } + } + + //float val = (((float)sin8(time + offset[i]) / 256)/2.1) + .05; + HSV hsv = {0, 255, 255}; + hsv.h = scale16by8(g_rgb_timer + offset[i], rgb_matrix_config.speed / 4) + (offset[i]*2); + hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v); + RGB rgb = rgb_matrix_hsv_to_rgb(hsv); + rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b); +} + +bool RANDOM_BREATH_RAINBOW(effect_params_t* params) { + + if (!params->init) { + // Change one LED every tick, make sure speed is not 0 + doRandom_breath_rainbow(rand() % DRIVER_LED_TOTAL, params); + return false; + } + + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + for (uint8_t i = led_min; i < led_max; i++) { + doRandom_breath_rainbow(i, params); + } + + return led_max < DRIVER_LED_TOTAL; +} -- cgit v1.2.3