1
0

Change name of rgb mode and implement rgb step feature

This commit is contained in:
Kai Ryu 2015-01-02 23:49:00 +09:00
parent 2e4100428e
commit 3e10e0e9a6
4 changed files with 113 additions and 76 deletions

View File

@ -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 ), LCTL,LGUI,LALT, SPC, RALT,FN0, RGUI, RCTL,P0, P0, PDOT,PENT ),
/* Keymap 1: Fn Layer /* 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| | | | | | * | | *9|*10|*11| | | | | | | |*25|*26| | | | | |
* |-----------------------------------------------------------+---+---+---+---| * |-----------------------------------------------------------+---+---+---+---|
@ -45,8 +45,8 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
* `---------------------------------------------------------------------------' * `---------------------------------------------------------------------------'
*/ */
KEYMAP( KEYMAP(
FN4 ,FN5 ,FN6 ,FN7 ,FN8 ,FN21,FN22,FN23,FN24,TRNS,TRNS,TRNS,TRNS,TRNS,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,FN25,FN26, 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,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,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, \ 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_TOGGLE,
AF_RGB_INCREASE, AF_RGB_INCREASE,
AF_RGB_DECREASE, AF_RGB_DECREASE,
AF_RGB_STATIC, AF_RGB_FIXED,
AF_RGB_ANIMATE AF_RGB_VARIABLE,
AF_RGB_STEP
}; };
/* /*
@ -98,28 +99,30 @@ const uint16_t fn_actions[] PROGMEM = {
[2] = ACTION_BACKLIGHT_STEP(), [2] = ACTION_BACKLIGHT_STEP(),
[3] = ACTION_LAYER_TOGGLE(2), [3] = ACTION_LAYER_TOGGLE(2),
[4] = ACTION_FUNCTION(AF_RGB_TOGGLE), [4] = ACTION_FUNCTION(AF_RGB_TOGGLE),
[5] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED), [5] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED),
[6] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN), [6] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN),
[7] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE), [7] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE),
[8] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_WHITE), [8] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_WHITE),
[9] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED_1), [9] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED_1),
[10] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN_1), [10] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN_1),
[11] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE_1), [11] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE_1),
[12] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED_2), [12] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED_2),
[13] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN_2), [13] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN_2),
[14] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE_2), [14] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE_2),
[15] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED_3), [15] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED_3),
[16] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN_3), [16] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN_3),
[17] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE_3), [17] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE_3),
[18] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_RED_4), [18] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_RED_4),
[19] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_GREEN_4), [19] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_GREEN_4),
[20] = ACTION_FUNCTION_OPT(AF_RGB_STATIC, RGB_STATIC_BLUE_4), [20] = ACTION_FUNCTION_OPT(AF_RGB_FIXED, RGB_FIXED_BLUE_4),
[21] = ACTION_FUNCTION_OPT(AF_RGB_ANIMATE, RGB_ANIMATE_FLASH), [21] = ACTION_FUNCTION_OPT(AF_RGB_VARIABLE, RGB_VARIABLE_FLASH),
[22] = ACTION_FUNCTION_OPT(AF_RGB_ANIMATE, RGB_ANIMATE_STROBE), [22] = ACTION_FUNCTION_OPT(AF_RGB_VARIABLE, RGB_VARIABLE_STROBE),
[23] = ACTION_FUNCTION_OPT(AF_RGB_ANIMATE, RGB_ANIMATE_FADE), [23] = ACTION_FUNCTION_OPT(AF_RGB_VARIABLE, RGB_VARIABLE_FADE),
[24] = ACTION_FUNCTION_OPT(AF_RGB_ANIMATE, RGB_ANIMATE_SMOOTH), [24] = ACTION_FUNCTION_OPT(AF_RGB_VARIABLE, RGB_VARIABLE_SMOOTH),
[25] = ACTION_FUNCTION(AF_RGB_DECREASE), [25] = ACTION_FUNCTION_OPT(AF_RGB_STEP, RGB_FIXED),
[26] = ACTION_FUNCTION(AF_RGB_INCREASE) [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 #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: case AF_RGB_DECREASE:
rgb_decrease(); rgb_decrease();
break; break;
case AF_RGB_STATIC: case AF_RGB_FIXED:
rgb_set(RGB_STATIC, opt); rgb_set(RGB_FIXED, opt);
break; break;
case AF_RGB_ANIMATE: case AF_RGB_VARIABLE:
rgb_set(RGB_ANIMATE, opt); rgb_set(RGB_VARIABLE, opt);
break;
case AF_RGB_STEP:
rgb_step(opt);
break; break;
} }
} }

View File

@ -28,8 +28,8 @@ void rgb_init(void)
rgb_read_config(); rgb_read_config();
if (rgb_config.raw == RGB_UNCONFIGURED) { if (rgb_config.raw == RGB_UNCONFIGURED) {
rgb_config.enable = 0; rgb_config.enable = 0;
rgb_config.mode = RGB_STATIC; rgb_config.mode = RGB_FIXED;
rgb_config.id = RGB_STATIC_WHITE; rgb_config.id = RGB_FIXED_WHITE;
rgb_write_config(); rgb_write_config();
} }
yc059_send(rgb_config.enable ? YC059_ON : YC059_OFF); 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) uint8_t rgb_to_yc059(uint8_t mode, uint8_t id)
{ {
switch (mode) { switch (mode) {
case RGB_STATIC: case RGB_FIXED:
if (id == RGB_STATIC_WHITE) { if (id == RGB_FIXED_WHITE) {
return YC059_STATIC_WHITE; return YC059_FIXED_WHITE;
} }
else { else {
return YC059_STATIC_RED + (id / 3) * 4 + id % 3; id--;
return YC059_FIXED_RED + (id / 3) * 4 + id % 3;
} }
break; break;
case RGB_ANIMATE: case RGB_VARIABLE:
return YC059_FLASH + id * 4; return YC059_FLASH + id * 4;
break; break;
default: default:

View File

@ -22,34 +22,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h> #include <stdbool.h>
enum rgb_mode_id { enum rgb_mode_id {
RGB_STATIC, RGB_FIXED,
RGB_ANIMATE RGB_VARIABLE
}; };
enum rgb_static_id { enum rgb_static_id {
RGB_STATIC_RED, RGB_FIXED_WHITE,
RGB_STATIC_GREEN, RGB_FIXED_RED,
RGB_STATIC_BLUE, RGB_FIXED_GREEN,
RGB_STATIC_RED_1, RGB_FIXED_BLUE,
RGB_STATIC_GREEN_1, RGB_FIXED_RED_1,
RGB_STATIC_BLUE_1, RGB_FIXED_GREEN_1,
RGB_STATIC_RED_2, RGB_FIXED_BLUE_1,
RGB_STATIC_GREEN_2, RGB_FIXED_RED_2,
RGB_STATIC_BLUE_2, RGB_FIXED_GREEN_2,
RGB_STATIC_RED_3, RGB_FIXED_BLUE_2,
RGB_STATIC_GREEN_3, RGB_FIXED_RED_3,
RGB_STATIC_BLUE_3, RGB_FIXED_GREEN_3,
RGB_STATIC_RED_4, RGB_FIXED_BLUE_3,
RGB_STATIC_GREEN_4, RGB_FIXED_RED_4,
RGB_STATIC_BLUE_4, RGB_FIXED_GREEN_4,
RGB_STATIC_WHITE RGB_FIXED_BLUE_4,
RGB_FIXED_COUNT
}; };
enum rgb_animate_id { enum rgb_animate_id {
RGB_ANIMATE_FLASH, RGB_VARIABLE_FLASH,
RGB_ANIMATE_STROBE, RGB_VARIABLE_STROBE,
RGB_ANIMATE_FADE, RGB_VARIABLE_FADE,
RGB_ANIMATE_SMOOTH RGB_VARIABLE_SMOOTH,
RGB_VARIABLE_COUNT
}; };
typedef union { typedef union {
@ -74,6 +76,7 @@ void rgb_toggle(void);
void rgb_increase(void); void rgb_increase(void);
void rgb_decrease(void); void rgb_decrease(void);
void rgb_set(uint8_t mode, uint8_t id); 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); uint8_t rgb_to_yc059(uint8_t mode, uint8_t id);
#endif #endif

View File

@ -39,25 +39,25 @@ enum yc059_id {
YC059_DECREASE, YC059_DECREASE,
YC059_OFF, YC059_OFF,
YC059_ON, YC059_ON,
YC059_STATIC_RED, YC059_FIXED_RED,
YC059_STATIC_GREEN, YC059_FIXED_GREEN,
YC059_STATIC_BLUE, YC059_FIXED_BLUE,
YC059_STATIC_WHITE, YC059_FIXED_WHITE,
YC059_STATIC_RED_1, YC059_FIXED_RED_1,
YC059_STATIC_GREEN_1, YC059_FIXED_GREEN_1,
YC059_STATIC_BLUE_1, YC059_FIXED_BLUE_1,
YC059_FLASH, YC059_FLASH,
YC059_STATIC_RED_2, YC059_FIXED_RED_2,
YC059_STATIC_GREEN_2, YC059_FIXED_GREEN_2,
YC059_STATIC_BLUE_2, YC059_FIXED_BLUE_2,
YC059_STROBE, YC059_STROBE,
YC059_STATIC_RED_3, YC059_FIXED_RED_3,
YC059_STATIC_GREEN_3, YC059_FIXED_GREEN_3,
YC059_STATIC_BLUE_3, YC059_FIXED_BLUE_3,
YC059_FADE, YC059_FADE,
YC059_STATIC_RED_4, YC059_FIXED_RED_4,
YC059_STATIC_GREEN_4, YC059_FIXED_GREEN_4,
YC059_STATIC_BLUE_4, YC059_FIXED_BLUE_4,
YC059_SMOOTH YC059_SMOOTH
}; };