Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename RGB/HSV structs: keyboard-level code #24476

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/features/rgb_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,18 @@ This example sets the modifiers to be a specific color based on the layer state.

```c
bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
HSV hsv = {0, 255, 255};
hsv_t hsv = {0, 255, 255};

if (layer_state_is(layer_state, 2)) {
hsv = (HSV){130, 255, 255};
hsv = (hsv_t){130, 255, 255};
} else {
hsv = (HSV){30, 255, 255};
hsv = (hsv_t){30, 255, 255};
}

if (hsv.v > rgb_matrix_get_val()) {
hsv.v = rgb_matrix_get_val();
}
RGB rgb = hsv_to_rgb(hsv);
rgb_t rgb = hsv_to_rgb(hsv);

for (uint8_t i = led_min; i < led_max; i++) {
if (HAS_FLAGS(g_led_config.flags[i], 0x01)) { // 0x01 == LED_FLAG_MODIFIER
Expand Down Expand Up @@ -873,13 +873,13 @@ Set the global effect hue, saturation, and value (brightness). New state is not

---

### `HSV rgb_matrix_get_hsv(void)` {#api-rgb-matrix-get-hsv}
### `hsv_t rgb_matrix_get_hsv(void)` {#api-rgb-matrix-get-hsv}

Get the current global effect hue, saturation, and value (brightness).

#### Return Value {#api-rgb-matrix-get-hsv-return}

The current effect HSV as an `HSV` struct.
The current effect HSV as an `hsv_t` struct.

---

Expand Down
4 changes: 2 additions & 2 deletions keyboards/1k/keymaps/default/rgblite.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ static inline void rgblite_init(void) {
ws2812_init();
}

static inline void rgblite_setrgb(RGB rgb) {
static inline void rgblite_setrgb(rgb_t rgb) {
ws2812_set_color_all(rgb.r, rgb.g, rgb.b);
ws2812_flush();
}

static void rgblite_increase_hue(void) {
static uint8_t state = 0;

HSV hsv = { 255, 255, 255 };
hsv_t hsv = { 255, 255, 255 };
hsv.h = state;
state = (state + 8) % 256;

Expand Down
4 changes: 2 additions & 2 deletions keyboards/bandominedoni/rgb_matrix_kb.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ RGB_MATRIX_EFFECT(my_party_rocks)

bool my_party_rocks(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = {rand() & 0xFF, rand() & 0xFF, rgb_matrix_config.hsv.v};
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
hsv_t hsv = {rand() & 0xFF, rand() & 0xFF, rgb_matrix_config.hsv.v};
rgb_t rgb = rgb_matrix_hsv_to_rgb(hsv);
// rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_set_color_all(rgb.r, rgb.g, rgb.b);
return rgb_matrix_check_finished_leds(led_max);
Expand Down
18 changes: 9 additions & 9 deletions keyboards/bastardkb/dilemma/3x5_3/3x5_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,36 @@ bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {

uint8_t layer = get_highest_layer(layer_state);
if (layer > 0) {
HSV hsv = rgb_matrix_get_hsv();
hsv_t hsv = rgb_matrix_get_hsv();
switch (get_highest_layer(layer_state)) {
case 1:
hsv = (HSV){HSV_BLUE};
hsv = (hsv_t){HSV_BLUE};
break;
case 2:
hsv = (HSV){HSV_AZURE};
hsv = (hsv_t){HSV_AZURE};
break;
case 3:
hsv = (HSV){HSV_ORANGE};
hsv = (hsv_t){HSV_ORANGE};
break;
case 4:
hsv = (HSV){HSV_GREEN};
hsv = (hsv_t){HSV_GREEN};
break;
case 5:
hsv = (HSV){HSV_TEAL};
hsv = (hsv_t){HSV_TEAL};
break;
case 6:
hsv = (HSV){HSV_PURPLE};
hsv = (hsv_t){HSV_PURPLE};
break;
case 7:
default:
hsv = (HSV){HSV_RED};
hsv = (hsv_t){HSV_RED};
break;
};

if (hsv.v > rgb_matrix_get_val()) {
hsv.v = MIN(rgb_matrix_get_val() + 22, 255);
}
RGB rgb = hsv_to_rgb(hsv);
rgb_t rgb = hsv_to_rgb(hsv);

for (uint8_t i = led_min; i < led_max; i++) {
if (HAS_FLAGS(g_led_config.flags[i], LED_FLAG_UNDERGLOW)) {
Expand Down
10 changes: 5 additions & 5 deletions keyboards/chromatonemini/rgb_matrix_kb.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RGB_MATRIX_EFFECT(my_party_rocks)

# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

static HSV my_solid_reactive_multiwide_col_math(HSV hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
static hsv_t my_solid_reactive_multiwide_col_math(hsv_t hsv, int16_t dx, int16_t dy, uint8_t dist, uint16_t tick) {
uint16_t effect = tick + dist;
dx = dx < 0 ? dx * -1 : dx;
dx = dx * 16 > 255 ? 255 : dx * 16;
Expand All @@ -27,7 +27,7 @@ bool my_solid_reactive_col(effect_params_t* params) {
uint16_t max_tick = 65535 / rgb_matrix_config.speed;
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
HSV hsv = rgb_matrix_config.hsv;
hsv_t hsv = rgb_matrix_config.hsv;
uint16_t tick = max_tick;
// Reverse search to find most recent key hit
for (int8_t j = g_last_hit_tracker.count - 1; j >= 0; j--) {
Expand All @@ -39,16 +39,16 @@ bool my_solid_reactive_col(effect_params_t* params) {

uint16_t offset = scale16by8(tick, rgb_matrix_config.speed);
hsv.h += qsub8(130, offset);
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_t rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
return led_max < RGB_MATRIX_LED_COUNT;
}

bool my_party_rocks(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = {rand() & 0xFF, rand() & 0xFF, rgb_matrix_config.hsv.v};
RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
hsv_t hsv = {rand() & 0xFF, rand() & 0xFF, rgb_matrix_config.hsv.v};
rgb_t rgb = rgb_matrix_hsv_to_rgb(hsv);
// rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
rgb_matrix_set_color_all(rgb.r, rgb.g, rgb.b);
return led_max < RGB_MATRIX_LED_COUNT;
Expand Down
12 changes: 6 additions & 6 deletions keyboards/cipulot/ec_980c/ec_980c.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ bool rgb_matrix_indicators_kb(void) {

if (eeprom_ec_config.num.enabled) {
// The rgb_matrix_set_color function needs an RGB code to work, so first the indicator color is cast to an HSV value and then translated to RGB
HSV hsv_num_indicator_color = {eeprom_ec_config.num.h, eeprom_ec_config.num.s, eeprom_ec_config.num.v};
RGB rgb_num_indicator_color = hsv_to_rgb(hsv_num_indicator_color);
hsv_t hsv_num_indicator_color = {eeprom_ec_config.num.h, eeprom_ec_config.num.s, eeprom_ec_config.num.v};
rgb_t rgb_num_indicator_color = hsv_to_rgb(hsv_num_indicator_color);
if (host_keyboard_led_state().num_lock)
rgb_matrix_set_color(NUM_INDICATOR_INDEX, rgb_num_indicator_color.r, rgb_num_indicator_color.g, rgb_num_indicator_color.b);
else
rgb_matrix_set_color(NUM_INDICATOR_INDEX, 0, 0, 0);
}
if (eeprom_ec_config.caps.enabled) {
HSV hsv_caps_indicator_color = {eeprom_ec_config.caps.h, eeprom_ec_config.caps.s, eeprom_ec_config.caps.v};
RGB rgb_caps_indicator_color = hsv_to_rgb(hsv_caps_indicator_color);
hsv_t hsv_caps_indicator_color = {eeprom_ec_config.caps.h, eeprom_ec_config.caps.s, eeprom_ec_config.caps.v};
rgb_t rgb_caps_indicator_color = hsv_to_rgb(hsv_caps_indicator_color);
if (host_keyboard_led_state().caps_lock)
rgb_matrix_set_color(CAPS_INDICATOR_INDEX, rgb_caps_indicator_color.r, rgb_caps_indicator_color.g, rgb_caps_indicator_color.b);
else
rgb_matrix_set_color(CAPS_INDICATOR_INDEX, 0, 0, 0);
}
if (eeprom_ec_config.scroll.enabled) {
HSV hsv_scroll_indicator_color = {eeprom_ec_config.scroll.h, eeprom_ec_config.scroll.s, eeprom_ec_config.scroll.v};
RGB rgb_scroll_indicator_color = hsv_to_rgb(hsv_scroll_indicator_color);
hsv_t hsv_scroll_indicator_color = {eeprom_ec_config.scroll.h, eeprom_ec_config.scroll.s, eeprom_ec_config.scroll.v};
rgb_t rgb_scroll_indicator_color = hsv_to_rgb(hsv_scroll_indicator_color);
if (host_keyboard_led_state().scroll_lock)
rgb_matrix_set_color(SCROLL_INDICATOR_INDEX, rgb_scroll_indicator_color.r, rgb_scroll_indicator_color.g, rgb_scroll_indicator_color.b);
else
Expand Down
4 changes: 2 additions & 2 deletions keyboards/gopolar/gg86/gg86.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ bool rgb_matrix_indicators_kb(void) {
return false;
}

HSV hsv = rgb_matrix_config.hsv;
hsv_t hsv = rgb_matrix_config.hsv;
uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
hsv.h = time;
RGB rgb = hsv_to_rgb(hsv);
rgb_t rgb = hsv_to_rgb(hsv);

if (host_keyboard_led_state().caps_lock) {
rgb_matrix_set_color(25, rgb.r, rgb.g, rgb.b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}

bool rgb_matrix_indicators_user(void) {
HSV hsv = rgb_matrix_config.hsv;
hsv_t hsv = rgb_matrix_config.hsv;
uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
hsv.h = time;
RGB rgb = hsv_to_rgb(hsv);
rgb_t rgb = hsv_to_rgb(hsv);

if ((rgb_matrix_get_flags() & LED_FLAG_KEYLIGHT)) {
if (host_keyboard_led_state().caps_lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ enum layer_names {
};

// For CUSTOM_GRADIENT
HSV gradient_0 = {205, 250, 255};
HSV gradient_100 = {140, 215, 125};
hsv_t gradient_0 = {205, 250, 255};
hsv_t gradient_100 = {140, 215, 125};
bool reflected_gradient = false;
uint8_t gp_i = 0;

typedef struct {
HSV gradient_0;
HSV gradient_1;
hsv_t gradient_0;
hsv_t gradient_1;
bool reflected;
} CUSTOM_PRESETS;

Expand Down Expand Up @@ -203,7 +203,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return false;
case G_FLIP:
if (record->event.pressed) {
HSV temp_color = gradient_0;
hsv_t temp_color = gradient_0;
gradient_0 = gradient_100;
gradient_100 = temp_color;
}
Expand Down Expand Up @@ -255,10 +255,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
bool rgb_matrix_indicators_user(void) {
uint8_t side_leds_left[3] = {17, 18, 19};
uint8_t side_leds_right[3] = { 4, 5, 6};
HSV hsv = rgb_matrix_config.hsv;
hsv_t hsv = rgb_matrix_config.hsv;
uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
hsv.h = time;
RGB rgb = hsv_to_rgb(hsv);
rgb_t rgb = hsv_to_rgb(hsv);

if ((rgb_matrix_get_flags() & LED_FLAG_ALL)) {
if (host_keyboard_led_state().caps_lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

static HSV COOL_DIAGONAL_math(HSV hsv, uint8_t i, uint8_t time) {
static hsv_t COOL_DIAGONAL_math(hsv_t hsv, uint8_t i, uint8_t time) {
hsv.h = (g_led_config.point[i].x / 4) - g_led_config.point[i].y - time;
return hsv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

extern HSV gradient_0;
extern HSV gradient_100;
extern hsv_t gradient_0;
extern hsv_t gradient_100;
extern bool reflected_gradient;

static HSV INTERPOLATE_HSV(float step, HSV gradient_0, HSV gradient_100) {
static hsv_t INTERPOLATE_HSV(float step, hsv_t gradient_0, hsv_t gradient_100) {
uint8_t cw, ccw;
HSV color;
hsv_t color;

cw = (gradient_0.h >= gradient_100.h) ? 255 + gradient_100.h - gradient_0.h : gradient_100.h - gradient_0.h; // Hue range is 0 to 255.
ccw = (gradient_0.h >= gradient_100.h) ? gradient_0.h - gradient_100.h : 255 + gradient_0.h - gradient_100.h;
Expand All @@ -39,7 +39,7 @@ static HSV INTERPOLATE_HSV(float step, HSV gradient_0, HSV gradient_100) {
return color;
}

static HSV CUSTOM_GRADIENT_math(uint8_t led_x, uint8_t min_x, uint8_t max_x) {
static hsv_t CUSTOM_GRADIENT_math(uint8_t led_x, uint8_t min_x, uint8_t max_x) {
float step = (float)led_x / (max_x - min_x);
float mid_gradient_pos = 0.5;

Expand All @@ -64,8 +64,8 @@ static bool CUSTOM_GRADIENT(effect_params_t* params) {
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();

HSV hsv_orig = CUSTOM_GRADIENT_math(g_led_config.point[i].x, min_x, max_x);
RGB rgb = hsv_to_rgb(hsv_orig);
hsv_t hsv_orig = CUSTOM_GRADIENT_math(g_led_config.point[i].x, min_x, max_x);
rgb_t rgb = hsv_to_rgb(hsv_orig);

rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "led/flower_blooming/flower_blooming.h"

static HSV FLOWER_BLOOMING_math(HSV hsv, uint8_t i, uint8_t time) {
static hsv_t FLOWER_BLOOMING_math(hsv_t hsv, uint8_t i, uint8_t time) {
if (g_led_config.point[i].y > k_rgb_matrix_center.y)
hsv.h = g_led_config.point[i].x * 3 - g_led_config.point[i].y * 3 + time;
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

typedef HSV (*flower_blooming_f)(HSV hsv, uint8_t i, uint8_t time);
typedef hsv_t (*flower_blooming_f)(hsv_t hsv, uint8_t i, uint8_t time);

bool effect_runner_bloom(effect_params_t* params, flower_blooming_f effect_func) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
Expand All @@ -9,10 +9,10 @@ bool effect_runner_bloom(effect_params_t* params, flower_blooming_f effect_func)
for (uint8_t i = led_min; i < led_max; i++) {
RGB_MATRIX_TEST_LED_FLAGS();
if (g_led_config.point[i].y > k_rgb_matrix_center.y) {
RGB bgr = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
rgb_t bgr = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
rgb_matrix_set_color(i, bgr.b, bgr.g, bgr.r);
} else {
RGB rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
rgb_t rgb = rgb_matrix_hsv_to_rgb(effect_func(rgb_matrix_config.hsv, i, time));
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static uint8_t time_to_led(uint8_t time, uint8_t led_behind) {
return led;
}

static HSV KITT_math(HSV hsv, uint8_t i, uint8_t time) {
static hsv_t KITT_math(hsv_t hsv, uint8_t i, uint8_t time) {

// reset base effect startup
if (i == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ static void doRandom_breath_rainbow(int i, effect_params_t* params) {
}

//float val = (((float)sin8(time + offset[i]) / 256)/2.1) + .05;
HSV hsv = {0, 255, 255};
hsv_t 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_t rgb = rgb_matrix_hsv_to_rgb(hsv);
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}

Expand Down
10 changes: 5 additions & 5 deletions keyboards/horrortroll/nyx/rev1/lib/startup_swirl_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static void traverse_matrix(void) {
}
}

static void swirl_set_color(HSV hsv) {
static void swirl_set_color(hsv_t hsv) {
uint8_t index = g_led_config.matrix_co[j][i];

if(index != NO_LED){
Expand All @@ -97,8 +97,8 @@ static void swirl_set_color(HSV hsv) {
else
v_values[v] = 0;
}
hsv.v = v_values[v];
RGB rgb = hsv_to_rgb(hsv);
hsv.v = v_values[v];
hsv_t rgb = hsv_to_rgb(hsv);
rgb_matrix_set_color(v, rgb.r, rgb.g, rgb.b);
}

Expand All @@ -112,10 +112,10 @@ static void swirl_set_color(HSV hsv) {
}

static bool STARTUP_SWIRL_ANIM(effect_params_t* params) {
HSV hsv = rgb_matrix_config.hsv;
hsv_t hsv = rgb_matrix_config.hsv;
uint8_t time = scale16by8(g_rgb_timer, qadd8(24, 1));
hsv.h = time;
RGB rgb = hsv_to_rgb(hsv);
rgb_t rgb = hsv_to_rgb(hsv);

if (traverse) {
swirl_set_color(hsv);
Expand Down
2 changes: 1 addition & 1 deletion keyboards/hs60/v1/v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void matrix_init_kb(void) {
// Clear the LED colors stored in EEPROM
for ( int row=0; row < MATRIX_ROWS; row++ )
{
HSV hsv;
hsv_t hsv;
for ( int column=0; column < MATRIX_COLS; column++ )
{
hsv.h = rand() & 0xFF;
Expand Down
2 changes: 1 addition & 1 deletion keyboards/inland/kb83/kb83.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static uint16_t scancode = 0;
static uint8_t alarm_cnt = 0;
static uint8_t RGB_HSV_level;

HSV hsv;
hsv_t hsv;

void led_test(uint8_t color);
void clear_eeprom(void);
Expand Down
Loading