Skip to content

Commit

Permalink
Move RGB query guff out of process_record
Browse files Browse the repository at this point in the history
  • Loading branch information
plodah committed Oct 31, 2024
1 parent fa2e6be commit 196a0c1
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 39 deletions.
34 changes: 4 additions & 30 deletions users/plodah/functions/process_record_user.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "functions/rgb.c"

bool process_record_user(uint16_t keycode, keyrecord_t *record) {

Expand Down Expand Up @@ -86,36 +87,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
#if defined(PLODAH_QRGB_KC)
case PL_QRGB:
if (record->event.pressed) {
#ifdef RGB_MATRIX_ENABLE
send_string_with_delay ( "\\ RGB_MATRIX:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_mode(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " H:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_hue(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " S:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_sat(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " V:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_val(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " SP:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_speed(),'0'), TAP_CODE_DELAY );
tap_code (KC_ENT);
#endif // RGB_MATRIX_ENABLE
#ifdef RGBLIGHT_ENABLE
send_string_with_delay ( "\\ RGBLIGHT:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_mode(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " H:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_hue(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " S:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_sat(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " V:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_val(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " SP:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_speed(),'0'), TAP_CODE_DELAY );
tap_code (KC_ENT);
#endif // RGBLIGHT_ENABLE
#if ( ! defined RGB_MATRIX_ENABLE ) && ( ! defined RGBLIGHT_ENABLE )
send_string_with_delay ( "\\ No RGB", TAP_CODE_DELAY );
tap_code (KC_ENT);
#endif // NO RGB_MATRIX_ENABLE OR RGBLIGHT_ENABLE
// send_string_with_delay(rgbQuery(), TAP_CODE_DELAY);
// send_string_with_delay(rgbQuerySmert(), TAP_CODE_DELAY);
rgbQuerySs();
}
return false;
#endif // defined(PLODAH_QRGB_KC)
Expand Down
105 changes: 96 additions & 9 deletions users/plodah/functions/rgb.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,99 @@
#pragma once

HSV plodah_rgblimit(HSV currenthsv, HSV targethsv, uint8_t minval){
HSV output = targethsv;
if(minval > currenthsv.v){
output.v = minval;
}
else if(targethsv.v > currenthsv.v ){
output.v = currenthsv.v;
}
return output;
#ifdef RGB_MATRIX_ENABLE
HSV plodah_rgblimit(HSV currenthsv, HSV targethsv, uint8_t minval){
HSV output = targethsv;
if(minval > currenthsv.v){
output.v = minval;
}
else if(targethsv.v > currenthsv.v ){
output.v = currenthsv.v;
}
return output;
}
#endif // RGB_MATRIX_ENABLE

char* rgbQuery(void){
//may take 80 bytes more than sending string directly
char * str;
str = malloc(sizeof(char)*50);
#ifdef RGB_MATRIX_ENABLE
strcpy (str, "\\ RGB_MATRIX:");
strcat (str, get_u8_str(rgb_matrix_get_mode(), '0'));
strcat (str, " H:");
strcat (str, get_u8_str(rgb_matrix_get_hue(), '0'));
strcat (str, " S:");
strcat (str, get_u8_str(rgb_matrix_get_sat(), '0'));
strcat (str, " V:");
strcat (str, get_u8_str(rgb_matrix_get_val(), '0'));
strcat (str, " SP:");
strcat (str, get_u8_str(rgb_matrix_get_speed(), '0'));
strcat (str, " \n");
#endif // RGB_MATRIX_ENABLE
#ifdef RGBLIGHT_ENABLE
strcpy (str, "\\ RGBLIGHT:");
strcat (str, get_u8_str(rgblight_get_mode(), '0'));
strcat (str, " H:");
strcat (str, get_u8_str(rgblight_get_hue(), '0'));
strcat (str, " S:");
strcat (str, get_u8_str(rgblight_get_sat(), '0'));
strcat (str, " V:");
strcat (str, get_u8_str(rgblight_get_val(), '0'));
strcat (str, " SP:");
strcat (str, get_u8_str(rgblight_get_speed(), '0'));
strcat (str, " \n");
#endif // RGBLIGHT_ENABLE
#if ( ! (defined RGB_MATRIX_ENABLE ) || ( defined RGBLIGHT_ENABLE ) )
strcpy (str, "\\ No RGB! \n");
#endif // NO RGB_MATRIX_ENABLE OR RGBLIGHT_ENABLE
return str;
}

char * rgbQuerySmert(void)
{
char * str;
str = malloc(sizeof(char)*50);
#ifdef RGB_MATRIX_ENABLE
snprintf (str, 50, "\\ RGB_MATRIX:%d H:%d S:%d V:%d SP:%d \n", rgb_matrix_get_mode(), rgb_matrix_get_hue(), rgb_matrix_get_sat(), rgb_matrix_get_val(), rgb_matrix_get_speed());
#endif // RGB_MATRIX_ENABLE
#ifdef RGBLIGHT_ENABLE
snprintf (str, 50, "\\ RGBLIGHT:%d H:%d S:%d V:%d SP:%d \n", rgblight_get_mode(), rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val(), rgblight_get_speed());
#endif // RGBLIGHT_ENABLE
#if ( ! (defined RGB_MATRIX_ENABLE ) || ( defined RGBLIGHT_ENABLE ) )
strcpy (str, "\\ No RGB! \n");
#endif // NO RGB_MATRIX_ENABLE OR RGBLIGHT_ENABLE
return str;
}

void rgbQuerySs(void)
{
#ifdef RGB_MATRIX_ENABLE
send_string_with_delay ( "\\ RGB_MATRIX:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_mode(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " H:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_hue(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " S:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_sat(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " V:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_val(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " SP:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgb_matrix_get_speed(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " \n", TAP_CODE_DELAY );
#endif // RGB_MATRIX_ENABLE
#ifdef RGBLIGHT_ENABLE
send_string_with_delay ( "\\ RGBLIGHT:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_mode(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " H:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_hue(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " S:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_sat(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " V:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_val(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " SP:", TAP_CODE_DELAY );
send_string_with_delay ( get_u8_str(rgblight_get_speed(),'0'), TAP_CODE_DELAY );
send_string_with_delay ( " \n", TAP_CODE_DELAY );
#endif // RGBLIGHT_ENABLE
#if ( ! (defined RGB_MATRIX_ENABLE ) || ( defined RGBLIGHT_ENABLE ) )
send_string_with_delay ( "\\ No RGB! \n", TAP_CODE_DELAY );
#endif // NO RGB_MATRIX_ENABLE OR RGBLIGHT_ENABLE
}

0 comments on commit 196a0c1

Please sign in to comment.