From 3e10e0e9a6c6ac7cb4b3407f201798b22c199ff6 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 2 Jan 2015 23:49:00 +0900 Subject: [PATCH] Change name of rgb mode and implement rgb step feature --- keyboard/RedScarfIII/keymap_default.c | 68 +++++++++++++++------------ keyboard/RedScarfIII/rgb.c | 42 ++++++++++++++--- keyboard/RedScarfIII/rgb.h | 47 +++++++++--------- keyboard/RedScarfIII/yc059.h | 32 ++++++------- 4 files changed, 113 insertions(+), 76 deletions(-) diff --git a/keyboard/RedScarfIII/keymap_default.c b/keyboard/RedScarfIII/keymap_default.c index 869d4229..1008a742 100644 --- a/keyboard/RedScarfIII/keymap_default.c +++ b/keyboard/RedScarfIII/keymap_default.c @@ -31,7 +31,7 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { LCTL,LGUI,LALT, SPC, RALT,FN0, RGUI, RCTL,P0, P0, PDOT,PENT ), /* Keymap 1: Fn Layer * ,---------------------------------------------------------------------------. - * | *4| *5| *6| *7| *8|*21|*22|*23|*24| | | | | | | | | | | + * | *4| *5| *6| *7| *8|*21|*22|*23|*24|*25|*26| | | | | | | | | * |-----------------------------------------------------------+---+---+---+---| * | | *9|*10|*11| | | | | | | |*25|*26| | | | | | * |-----------------------------------------------------------+---+---+---+---| @@ -45,8 +45,8 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { * `---------------------------------------------------------------------------' */ KEYMAP( - FN4 ,FN5 ,FN6 ,FN7 ,FN8 ,FN21,FN22,FN23,FN24,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ - TRNS,FN9 ,FN10,FN11,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,FN25,FN26, TRNS,TRNS,TRNS,TRNS,TRNS, \ + FN4 ,FN5 ,FN6 ,FN7 ,FN8 ,FN21,FN22,FN23,FN24,FN25,FN26,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ + TRNS,FN9 ,FN10,FN11,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,FN27,FN28, TRNS,TRNS,TRNS,TRNS,TRNS, \ TRNS,FN12,FN13,FN14,TRNS,TRNS,CALC,TRNS,INS, TRNS,PSCR,SLCK,PAUS, TRNS,TRNS,TRNS,TRNS,TRNS, \ TRNS,FN15,FN16,FN17,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,HOME,PGUP,TRNS, TRNS,TRNS,TRNS,TRNS,TRNS, \ TRNS,TRNS,FN18,FN19,FN20,FN1, FN2, VOLD,VOLU,MUTE,END, PGDN, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ @@ -81,8 +81,9 @@ enum function_id { AF_RGB_TOGGLE, AF_RGB_INCREASE, AF_RGB_DECREASE, - AF_RGB_STATIC, - AF_RGB_ANIMATE + AF_RGB_FIXED, + AF_RGB_VARIABLE, + AF_RGB_STEP }; /* @@ -98,28 +99,30 @@ const uint16_t fn_actions[] PROGMEM = { [2] = ACTION_BACKLIGHT_STEP(), [3] = ACTION_LAYER_TOGGLE(2), [4] = ACTION_FUNCTION(AF_RGB_TOGGLE), - [5] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED), - [6] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN), - [7] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE), - [8] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_WHITE), - [9] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED_1), - [10] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN_1), - [11] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE_1), - [12] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED_2), - [13] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN_2), - [14] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE_2), - [15] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED_3), - [16] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN_3), - [17] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE_3), - [18] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED_4), - [19] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN_4), - [20] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE_4), - [21] = ACTION_FUNCTION_OPT(AF_RGB_ANIMATE, RGB_ANIMATE_FLASH), - [22] = ACTION_FUNCTION_OPT(AF_RGB_ANIMATE, RGB_ANIMATE_STROBE), - [23] = ACTION_FUNCTION_OPT(AF_RGB_ANIMATE, RGB_ANIMATE_FADE), - [24] = ACTION_FUNCTION_OPT(AF_RGB_ANIMATE, RGB_ANIMATE_SMOOTH), - [25] = ACTION_FUNCTION(AF_RGB_DECREASE), - [26] = ACTION_FUNCTION(AF_RGB_INCREASE) + [5] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED), + [6] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN), + [7] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE), + [8] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_WHITE), + [9] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED_1), + [10] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN_1), + [11] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE_1), + [12] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED_2), + [13] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN_2), + [14] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE_2), + [15] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED_3), + [16] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN_3), + [17] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE_3), + [18] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED_4), + [19] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN_4), + [20] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE_4), + [21] = ACTION_FUNCTION_OPT(AF_RGB_VARIABLE, RGB_VARIABLE_FLASH), + [22] = ACTION_FUNCTION_OPT(AF_RGB_VARIABLE, RGB_VARIABLE_STROBE), + [23] = ACTION_FUNCTION_OPT(AF_RGB_VARIABLE, RGB_VARIABLE_FADE), + [24] = ACTION_FUNCTION_OPT(AF_RGB_VARIABLE, RGB_VARIABLE_SMOOTH), + [25] = ACTION_FUNCTION_OPT(AF_RGB_STEP, RGB_FIXED), + [26] = ACTION_FUNCTION_OPT(AF_RGB_STEP, RGB_VARIABLE), + [27] = ACTION_FUNCTION(AF_RGB_DECREASE), + [28] = ACTION_FUNCTION(AF_RGB_INCREASE) }; #ifdef KEYMAP_IN_EEPROM_ENABLE @@ -151,11 +154,14 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) case AF_RGB_DECREASE: rgb_decrease(); break; - case AF_RGB_STATIC: - rgb_set(RGB_STATIC, opt); + case AF_RGB_FIXED: + rgb_set(RGB_FIXED, opt); break; - case AF_RGB_ANIMATE: - rgb_set(RGB_ANIMATE, opt); + case AF_RGB_VARIABLE: + rgb_set(RGB_VARIABLE, opt); + break; + case AF_RGB_STEP: + rgb_step(opt); break; } } diff --git a/keyboard/RedScarfIII/rgb.c b/keyboard/RedScarfIII/rgb.c index 1f7f7d47..0750e206 100644 --- a/keyboard/RedScarfIII/rgb.c +++ b/keyboard/RedScarfIII/rgb.c @@ -28,8 +28,8 @@ void rgb_init(void) rgb_read_config(); if (rgb_config.raw == RGB_UNCONFIGURED) { rgb_config.enable = 0; - rgb_config.mode = RGB_STATIC; - rgb_config.id = RGB_STATIC_WHITE; + rgb_config.mode = RGB_FIXED; + rgb_config.id = RGB_FIXED_WHITE; rgb_write_config(); } yc059_send(rgb_config.enable ? YC059_ON : YC059_OFF); @@ -99,18 +99,46 @@ void rgb_set(uint8_t mode, uint8_t id) } } +void rgb_step(uint8_t mode) +{ + if (rgb_config.enable) { + if (rgb_config.mode != mode) { + rgb_config.mode = mode; + rgb_config.id = 0; + } + else { + uint8_t count; + switch (mode) { + case RGB_FIXED: + count = RGB_FIXED_COUNT; + break; + case RGB_VARIABLE: + count = RGB_VARIABLE_COUNT; + break; + default: + count = 1; + break; + } + rgb_config.id = (rgb_config.id + 1) % count; + } + rgb_resume(); + rgb_write_config(); + } +} + uint8_t rgb_to_yc059(uint8_t mode, uint8_t id) { switch (mode) { - case RGB_STATIC: - if (id == RGB_STATIC_WHITE) { - return YC059_STATIC_WHITE; + case RGB_FIXED: + if (id == RGB_FIXED_WHITE) { + return YC059_FIXED_WHITE; } else { - return YC059_STATIC_RED + (id / 3) * 4 + id % 3; + id--; + return YC059_FIXED_RED + (id / 3) * 4 + id % 3; } break; - case RGB_ANIMATE: + case RGB_VARIABLE: return YC059_FLASH + id * 4; break; default: diff --git a/keyboard/RedScarfIII/rgb.h b/keyboard/RedScarfIII/rgb.h index f99a258f..aa3b7e37 100644 --- a/keyboard/RedScarfIII/rgb.h +++ b/keyboard/RedScarfIII/rgb.h @@ -22,34 +22,36 @@ along with this program. If not, see . #include enum rgb_mode_id { - RGB_STATIC, - RGB_ANIMATE + RGB_FIXED, + RGB_VARIABLE }; enum rgb_static_id { - RGB_STATIC_RED, - RGB_STATIC_GREEN, - RGB_STATIC_BLUE, - RGB_STATIC_RED_1, - RGB_STATIC_GREEN_1, - RGB_STATIC_BLUE_1, - RGB_STATIC_RED_2, - RGB_STATIC_GREEN_2, - RGB_STATIC_BLUE_2, - RGB_STATIC_RED_3, - RGB_STATIC_GREEN_3, - RGB_STATIC_BLUE_3, - RGB_STATIC_RED_4, - RGB_STATIC_GREEN_4, - RGB_STATIC_BLUE_4, - RGB_STATIC_WHITE + RGB_FIXED_WHITE, + RGB_FIXED_RED, + RGB_FIXED_GREEN, + RGB_FIXED_BLUE, + RGB_FIXED_RED_1, + RGB_FIXED_GREEN_1, + RGB_FIXED_BLUE_1, + RGB_FIXED_RED_2, + RGB_FIXED_GREEN_2, + RGB_FIXED_BLUE_2, + RGB_FIXED_RED_3, + RGB_FIXED_GREEN_3, + RGB_FIXED_BLUE_3, + RGB_FIXED_RED_4, + RGB_FIXED_GREEN_4, + RGB_FIXED_BLUE_4, + RGB_FIXED_COUNT }; enum rgb_animate_id { - RGB_ANIMATE_FLASH, - RGB_ANIMATE_STROBE, - RGB_ANIMATE_FADE, - RGB_ANIMATE_SMOOTH + RGB_VARIABLE_FLASH, + RGB_VARIABLE_STROBE, + RGB_VARIABLE_FADE, + RGB_VARIABLE_SMOOTH, + RGB_VARIABLE_COUNT }; typedef union { @@ -74,6 +76,7 @@ void rgb_toggle(void); void rgb_increase(void); void rgb_decrease(void); void rgb_set(uint8_t mode, uint8_t id); +void rgb_step(uint8_t mode); uint8_t rgb_to_yc059(uint8_t mode, uint8_t id); #endif diff --git a/keyboard/RedScarfIII/yc059.h b/keyboard/RedScarfIII/yc059.h index 4ade9a66..d1d8bc4f 100644 --- a/keyboard/RedScarfIII/yc059.h +++ b/keyboard/RedScarfIII/yc059.h @@ -39,25 +39,25 @@ enum yc059_id { YC059_DECREASE, YC059_OFF, YC059_ON, - YC059_STATIC_RED, - YC059_STATIC_GREEN, - YC059_STATIC_BLUE, - YC059_STATIC_WHITE, - YC059_STATIC_RED_1, - YC059_STATIC_GREEN_1, - YC059_STATIC_BLUE_1, + YC059_FIXED_RED, + YC059_FIXED_GREEN, + YC059_FIXED_BLUE, + YC059_FIXED_WHITE, + YC059_FIXED_RED_1, + YC059_FIXED_GREEN_1, + YC059_FIXED_BLUE_1, YC059_FLASH, - YC059_STATIC_RED_2, - YC059_STATIC_GREEN_2, - YC059_STATIC_BLUE_2, + YC059_FIXED_RED_2, + YC059_FIXED_GREEN_2, + YC059_FIXED_BLUE_2, YC059_STROBE, - YC059_STATIC_RED_3, - YC059_STATIC_GREEN_3, - YC059_STATIC_BLUE_3, + YC059_FIXED_RED_3, + YC059_FIXED_GREEN_3, + YC059_FIXED_BLUE_3, YC059_FADE, - YC059_STATIC_RED_4, - YC059_STATIC_GREEN_4, - YC059_STATIC_BLUE_4, + YC059_FIXED_RED_4, + YC059_FIXED_GREEN_4, + YC059_FIXED_BLUE_4, YC059_SMOOTH };