Skip to content

Commit

Permalink
[Keyboard] Update Pachi RGB Rev2 VIA custom indicators (qmk#19788)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xelus22 authored Feb 10, 2023
1 parent 8c3e09b commit d0702b5
Show file tree
Hide file tree
Showing 3 changed files with 370 additions and 6 deletions.
10 changes: 6 additions & 4 deletions keyboards/xelus/pachi/rgb/rev2/config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2021 Harrison Chan (Xelus)
/* Copyright 2023 Harrison Chan (Xelus)
*
* 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
Expand Down Expand Up @@ -90,8 +90,9 @@
#define ENABLE_RGB_MATRIX_HUE_BREATHING
#define ENABLE_RGB_MATRIX_HUE_PENDULUM
#define ENABLE_RGB_MATRIX_HUE_WAVE
// #define ENABLE_RGB_MATRIX_PIXEL_FRACTAL
// #define ENABLE_RGB_MATRIX_PIXEL_RAIN
// #define ENABLE_RGB_MATRIX_PIXEL_FLOW
// #define ENABLE_RGB_MATRIX_PIXEL_FRACTAL

#define ENABLE_RGB_MATRIX_TYPING_HEATMAP
#define ENABLE_RGB_MATRIX_DIGITAL_RAIN
Expand All @@ -109,5 +110,6 @@
#define ENABLE_RGB_MATRIX_SOLID_SPLASH
#define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH


#define FORCE_NKRO
// VIA KB level
#define VIA_FIRMWARE_VERSION 1
#define VIA_EEPROM_CUSTOM_CONFIG_SIZE 17
310 changes: 309 additions & 1 deletion keyboards/xelus/pachi/rgb/rev2/rev2.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2021 Harrison Chan (Xelus)
/* Copyright 2023 Harrison Chan (Xelus)
*
* 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
Expand Down Expand Up @@ -242,4 +242,312 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
.set_color = IS31FL3741_set_color,
.set_color_all = IS31FL3741_set_color_all
};

#ifdef VIA_ENABLE
#include "quantum.h"
#include "eeprom.h"

indicator_settings_config g_config = {
.caps_lock_indicator = {0, 0, 128},
.num_lock_indicator = {60, 0, 128},
.scroll_lock_indicator = {120, 0, 128},
.layer_indicator = {180, 0, 128},
.caps_lock_key = 7,
.num_lock_key = 0,
.scroll_lock_key = 78,
.layer_indicator_key = 0,
.enable_caps_lock = true,
.enable_num_lock = false,
.enable_scroll_lock = true,
.enable_layer_indicator = false,
.caps_override_bl = true,
.num_override_bl = true,
.scroll_override_bl = true,
.layer_override_bl = true
};

void values_load(void)
{
eeprom_read_block( &g_config, ((void*)VIA_EEPROM_CUSTOM_CONFIG_ADDR), sizeof(g_config) );
}

void values_save(void)
{
eeprom_update_block( &g_config, ((void*)VIA_EEPROM_CUSTOM_CONFIG_ADDR), sizeof(g_config) );
}

void via_init_kb(void)
{
// If the EEPROM has the magic, the data is good.
// OK to load from EEPROM
if (via_eeprom_is_valid()) {
values_load();
} else {
values_save();
// DO NOT set EEPROM valid here, let caller do this
}
}

void via_custom_value_command_kb(uint8_t *data, uint8_t length) {
// data = [ command_id, channel_id, value_id, value_data ]
uint8_t *command_id = &(data[0]);
uint8_t *channel_id = &(data[1]);
uint8_t *value_id_and_data = &(data[2]);

if ( *channel_id == id_custom_channel ) {
switch ( *command_id )
{
case id_custom_set_value:
{
indicator_config_set_value(value_id_and_data);
break;
}
case id_custom_get_value:
{
indicator_config_get_value(value_id_and_data);
break;
}
case id_custom_save:
{
values_save();
break;
}
default:
{
// Unhandled message.
*command_id = id_unhandled;
break;
}
}
return;
}

// Return the unhandled state
*command_id = id_unhandled;

// DO NOT call raw_hid_send(data,length) here, let caller do this
}

void indicator_config_set_value( uint8_t *data )
{
// data = [ value_id, value_data ]
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);

switch ( *value_id )
{
case id_caps_lock_enable:
g_config.enable_caps_lock = *value_data;
break;
case id_num_lock_enable:
g_config.enable_num_lock = *value_data;
break;
case id_scroll_lock_enable:
g_config.enable_scroll_lock = *value_data;
break;
case id_layer_indicator_enable:
g_config.enable_layer_indicator = *value_data;
break;
case id_caps_lock_brightness:
g_config.caps_lock_indicator.v = *value_data;
break;
case id_num_lock_brightness:
g_config.num_lock_indicator.v = *value_data;
break;
case id_scroll_lock_brightness:
g_config.scroll_lock_indicator.v = *value_data;
break;
case id_layer_indicator_brightness:
g_config.layer_indicator.v = *value_data;
break;
case id_caps_lock_color:
_set_color( &(g_config.caps_lock_indicator), value_data );
break;
case id_num_lock_color:
_set_color( &(g_config.num_lock_indicator), value_data );
break;
case id_scroll_lock_color:
_set_color( &(g_config.scroll_lock_indicator), value_data );
break;
case id_layer_indicator_color:
_set_color( &(g_config.layer_indicator), value_data );
break;
case id_caps_lock_key:
g_config.caps_lock_key = *value_data;
break;
case id_num_lock_key:
g_config.num_lock_key = *value_data;
break;
case id_scroll_lock_key:
g_config.scroll_lock_key = *value_data;
break;
case id_layer_indicator_key:
g_config.layer_indicator_key = *value_data;
break;
case id_caps_lock_override:
g_config.caps_override_bl = *value_data;
break;
case id_num_lock_override:
g_config.num_override_bl = *value_data;
break;
case id_scroll_lock_override:
g_config.scroll_override_bl = *value_data;
break;
case id_layer_indicator_override:
g_config.layer_override_bl = *value_data;
break;
}
}

void indicator_config_get_value( uint8_t *data )
{
uint8_t *value_id = &(data[0]);
uint8_t *value_data = &(data[1]);

switch ( *value_id )
{
case id_caps_lock_enable:
*value_data = g_config.enable_caps_lock;
break;
case id_num_lock_enable:
*value_data = g_config.enable_num_lock;
break;
case id_scroll_lock_enable:
*value_data = g_config.enable_scroll_lock;
break;
case id_layer_indicator_enable:
*value_data = g_config.enable_layer_indicator;
break;
case id_caps_lock_brightness:
*value_data = g_config.caps_lock_indicator.v;
break;
case id_num_lock_brightness:
*value_data = g_config.num_lock_indicator.v;
break;
case id_layer_indicator_brightness:
*value_data = g_config.scroll_lock_indicator.v;
break;
case id_scroll_lock_brightness:
*value_data = g_config.layer_indicator.v;
break;
case id_caps_lock_color:
_get_color( &(g_config.caps_lock_indicator), value_data );
break;
case id_num_lock_color:
_get_color( &(g_config.num_lock_indicator), value_data );
break;
case id_scroll_lock_color:
_get_color( &(g_config.scroll_lock_indicator), value_data );
break;
case id_layer_indicator_color:
_get_color( &(g_config.layer_indicator), value_data );
break;
case id_caps_lock_key:
*value_data = g_config.caps_lock_key;
break;
case id_num_lock_key:
*value_data = g_config.num_lock_key;
break;
case id_scroll_lock_key:
*value_data = g_config.scroll_lock_key;
break;
case id_layer_indicator_key:
*value_data = g_config.layer_indicator_key;
break;
case id_caps_lock_override:
*value_data = g_config.caps_override_bl;
break;
case id_num_lock_override:
*value_data = g_config.num_override_bl;
break;
case id_scroll_lock_override:
*value_data = g_config.scroll_override_bl;
break;
case id_layer_indicator_override:
*value_data = g_config.layer_override_bl;
break;
}
}

// Some helpers for setting/getting HSV
void _set_color( HSV *color, uint8_t *data )
{
color->h = data[0];
color->s = data[1];
}

void _get_color( HSV *color, uint8_t *data )
{
data[0] = color->h;
data[1] = color->s;
}

// Set the indicators with RGB Matrix subsystem
bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
// caps lock cyan
if (g_config.enable_caps_lock) {
RGB rgb_caps = hsv_to_rgb( (HSV){ .h = g_config.caps_lock_indicator.h,
.s = g_config.caps_lock_indicator.s,
.v = g_config.caps_lock_indicator.v } );
if (host_keyboard_led_state().caps_lock) {
RGB_MATRIX_INDICATOR_SET_COLOR(g_config.caps_lock_key, rgb_caps.r, rgb_caps.g, rgb_caps.b);
} else {
if (g_config.caps_override_bl) {
RGB_MATRIX_INDICATOR_SET_COLOR(g_config.caps_lock_key, 0, 0, 0);
}
}
}

// num lock cyan
if (g_config.enable_num_lock) {
RGB rgb_num = hsv_to_rgb( (HSV){ .h = g_config.num_lock_indicator.h,
.s = g_config.num_lock_indicator.s,
.v = g_config.num_lock_indicator.v } );
if (host_keyboard_led_state().num_lock) {
RGB_MATRIX_INDICATOR_SET_COLOR(g_config.num_lock_key, rgb_num.r, rgb_num.g, rgb_num.b);
} else {
if (g_config.num_override_bl) {
RGB_MATRIX_INDICATOR_SET_COLOR(g_config.num_lock_key, 0, 0, 0);
}
}
}

// scroll lock cyan
if (g_config.enable_scroll_lock) {
RGB rgb_scroll = hsv_to_rgb( (HSV){ .h = g_config.scroll_lock_indicator.h,
.s = g_config.scroll_lock_indicator.s,
.v = g_config.scroll_lock_indicator.v } );
if (host_keyboard_led_state().scroll_lock) {
RGB_MATRIX_INDICATOR_SET_COLOR(g_config.scroll_lock_key, rgb_scroll.r, rgb_scroll.g, rgb_scroll.b);
} else {
if (g_config.scroll_override_bl) {
RGB_MATRIX_INDICATOR_SET_COLOR(g_config.scroll_lock_key, 0, 0, 0);
}
}
}

// layer state
if (g_config.enable_layer_indicator) {
RGB rgb_layer = hsv_to_rgb( (HSV){ .h = g_config.layer_indicator.h,
.s = g_config.layer_indicator.s,
.v = g_config.layer_indicator.v } );
switch (get_highest_layer(layer_state)) {
case 0:
if (g_config.layer_override_bl) {
RGB_MATRIX_INDICATOR_SET_COLOR(g_config.layer_indicator_key, 0, 0, 0);
}
break;
case 1:
RGB_MATRIX_INDICATOR_SET_COLOR(g_config.layer_indicator_key, rgb_layer.r, rgb_layer.g, rgb_layer.b);
break;
default:
// white
RGB_MATRIX_INDICATOR_SET_COLOR(24, 128, 128, 128);
break;
}
}
return false;
}

#endif
#endif
Loading

0 comments on commit d0702b5

Please sign in to comment.