Pikatea GB4 RGB buttons
Using custom keycodes in QMK as colorsannamaniacs
c_cpp
3 years ago
4.1 kB
37
Indexable
/*
New file: rgb_profiles.h
*/
#pragma once
#define NUMBER_OF_RGB_LAYERS 8
const rgblight_segment_t PROGMEM layer_green[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 5, HSV_GREEN}
);
const rgblight_segment_t PROGMEM layer_red[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 5, HSV_RED}
);
const rgblight_segment_t PROGMEM layer_blue[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 5, HSV_BLUE}
);
const rgblight_segment_t PROGMEM layer_white[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 5, HSV_WHITE}
);
const rgblight_segment_t PROGMEM layer_yellow[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 5, HSV_YELLOW}
);
const rgblight_segment_t PROGMEM layer_orange[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 5, HSV_ORANGE}
);
const rgblight_segment_t PROGMEM layer_cyan[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 5, HSV_CYAN}
);
const rgblight_segment_t PROGMEM layer_purple[] = RGBLIGHT_LAYER_SEGMENTS(
{0, 5, HSV_PURPLE}
);
// rgb colors, redefine RGBLIGHT_MAX_LAYERS if using >8
const rgblight_segment_t* const PROGMEM default_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
layer_green,
layer_red,
layer_blue,
layer_white,
layer_yellow,
layer_orange,
layer_cyan,
layer_purple
);
/*
Existing file: config.h
*/
# define RGBLIGHT_LAYERS
/*
Existing file: vial.json
Add one custom keycode per desired color/button.
more info: https://get.vial.today/manual/custom_keycode.html
*/
"customKeycodes": [
{"name": "Green",
"title": "Green",
"shortName": "RGB_USER_GREEN"
},
{"name": "Red",
"title": "Red",
"shortName": "RGB_USER_RED"
},
{"name": "Blue",
"title": "Blue",
"shortName": "RGB_USER_BLUE"
},
{"name": "White",
"title": "White",
"shortName": "RGB_USER_WHITE"
},
{"name": "Yellow",
"title": "Yellow",
"shortName": "RGB_USER_YELLOW"
},
{"name": "Orange",
"title": "Orange",
"shortName": "RGB_USER_ORANGE"
},
{"name": "Cyan",
"title": "Cyan",
"shortName": "RGB_USER_CYAN"
},
{"name": "Purple",
"title": "Purple",
"shortName": "RGB_USER_PURPLE"
}
],
/*
Existing file: keymap.c
*/
#include "rgb_profiles.h"
// use the names from vial.json
enum blender_keycode {
RGB_USER_GREEN = USER00,
RGB_USER_RED,
RGB_USER_BLUE,
RGB_USER_WHITE,
RGB_USER_YELLOW,
RGB_USER_ORANGE,
RGB_USER_CYAN,
RGB_USER_PURPLE
};
void keyboard_post_init_user(void) {
// Enable the LED layers
rgblight_layers = default_rgb_layers;
}
void update_rgb_layer(uint8_t layer_code) {
// basic limit checking
if (layer_code >= NUMBER_OF_RGB_LAYERS) {
return;
}
// higher rgblight layers take precedence, so disable them
for (int i=layer_code+1; i < NUMBER_OF_RGB_LAYERS; i++) {
rgblight_set_layer_state(i, false);
}
// enable the desired rgblight layer
rgblight_set_layer_state(layer_code, true);
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case RGB_USER_GREEN:
if (record->event.pressed) {
update_rgb_layer(0);
return 0;
}
case RGB_USER_RED:
if (record->event.pressed) {
update_rgb_layer(1);
return 0;
}
case RGB_USER_BLUE:
if (record->event.pressed) {
update_rgb_layer(2);
return 0;
}
case RGB_USER_WHITE:
if (record->event.pressed) {
update_rgb_layer(3);
return 0;
}
case RGB_USER_YELLOW:
if (record->event.pressed) {
update_rgb_layer(4);
return 0;
}
case RGB_USER_ORANGE:
if (record->event.pressed) {
update_rgb_layer(5);
return 0;
}
case RGB_USER_CYAN:
if (record->event.pressed) {
update_rgb_layer(6);
return 0;
}
case RGB_USER_PURPLE:
if (record->event.pressed) {
update_rgb_layer(7);
return 0;
}
default:
return true;
}
return true;
}Editor is loading...