mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-15 20:31:27 +00:00
Improvements to RGB keycodes
This commit is contained in:
parent
9140a6ba96
commit
ed27d389b7
@ -116,17 +116,24 @@ void matrix_scan_kb(void) {
|
|||||||
matrix_scan_user();
|
matrix_scan_user();
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uint8_t LEVELS[] = {
|
#define LEVEL(value) (uint8_t)(\
|
||||||
48,
|
((uint16_t)value) \
|
||||||
72,
|
* ((uint16_t)RGB_MATRIX_MAXIMUM_BRIGHTNESS) \
|
||||||
96,
|
/ ((uint16_t)255) \
|
||||||
144,
|
)
|
||||||
192,
|
|
||||||
255
|
|
||||||
};
|
|
||||||
static int LEVEL_I = 1;
|
|
||||||
|
|
||||||
void set_value_all_layers(uint8_t value) {
|
static const uint8_t levels[] = {
|
||||||
|
LEVEL(48),
|
||||||
|
LEVEL(72),
|
||||||
|
LEVEL(96),
|
||||||
|
LEVEL(144),
|
||||||
|
LEVEL(192),
|
||||||
|
LEVEL(255)
|
||||||
|
};
|
||||||
|
|
||||||
|
static uint8_t toggle_level = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
|
||||||
|
|
||||||
|
static void set_value_all_layers(uint8_t value) {
|
||||||
if (!system76_ec_is_unlocked()) {
|
if (!system76_ec_is_unlocked()) {
|
||||||
for (int8_t layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
|
for (int8_t layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
|
||||||
layer_rgb[layer].hsv.v = value;
|
layer_rgb[layer].hsv.v = value;
|
||||||
@ -144,25 +151,37 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
|||||||
return false;
|
return false;
|
||||||
case RGB_VAD:
|
case RGB_VAD:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
if (LEVEL_I > 0)
|
uint8_t level = rgb_matrix_config.hsv.v;
|
||||||
LEVEL_I -= 1;
|
for (int i = sizeof(levels) - 1; i >= 0; i--) {
|
||||||
set_value_all_layers(LEVELS[LEVEL_I]);
|
if (levels[i] < level) {
|
||||||
|
level = levels[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set_value_all_layers(level);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case RGB_VAI:
|
case RGB_VAI:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
if (LEVEL_I < sizeof(LEVELS) - 1)
|
uint8_t level = rgb_matrix_config.hsv.v;
|
||||||
LEVEL_I += 1;
|
for (int i = 0; i < sizeof(levels); i++) {
|
||||||
set_value_all_layers(LEVELS[LEVEL_I]);
|
if (levels[i] > level) {
|
||||||
|
level = levels[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set_value_all_layers(level);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case RGB_TOG:
|
case RGB_TOG:
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) {
|
||||||
|
uint8_t level = 0;
|
||||||
if (rgb_matrix_config.hsv.v == 0) {
|
if (rgb_matrix_config.hsv.v == 0) {
|
||||||
set_value_all_layers(LEVELS[LEVEL_I]);
|
level = toggle_level;
|
||||||
} else {
|
} else {
|
||||||
set_value_all_layers(0);
|
toggle_level = rgb_matrix_config.hsv.v;
|
||||||
}
|
}
|
||||||
|
set_value_all_layers(level);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user