summaryrefslogtreecommitdiff
path: root/keyboards/teleport/native/rgb_matrix_kb.inc
blob: 5df5312a42c6d0f3cc702a6d70f31bdd8f1575a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
RGB_MATRIX_EFFECT(SINGLE_COLOR_RAINDROPS)
RGB_MATRIX_EFFECT(STATIC_GAME_MODE)
#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS

/* This effect has been partially derived from quantum/rgb_matrix/animations/pixel_rain_anim.h and raindrops_anim.h 
It sets random LEDs to matrix color (with very slight hue variation) but random intensity */
static bool SINGLE_COLOR_RAINDROPS(effect_params_t* params) {
    static uint32_t wait_timer = 0;

    // interval function and timing in general taken from pixel rain animation
    inline uint32_t interval(void) {
        return 500 / scale16by8(qadd8(rgb_matrix_config.speed, 16), 16);
    }

    void single_color_raindrops_set_color(uint8_t i, effect_params_t * params) {
        if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) {
            return;
        }
        
        // Take matrix color, add between -5 and +5 to hue, random brightness between 0 and val, set to 0 if val between 0 and 5, then write to LED
        HSV hsv = rgb_matrix_get_hsv();
        hsv.h = rgb_matrix_get_hue() - 2 + random8() % 5;
        hsv.v = random8() % rgb_matrix_get_val();
        if (hsv.v < 5) { 
            hsv.v = 0;
        }
        RGB rgb = rgb_matrix_hsv_to_rgb(hsv);
        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
        wait_timer = g_rgb_timer + interval();
    }

    RGB_MATRIX_USE_LIMITS(led_min, led_max);
    if (!params->init) {
        if (g_rgb_timer > wait_timer) {
            single_color_raindrops_set_color(mod8(random8(), RGB_MATRIX_LED_COUNT), params);
        }
    } else {
        for (int i = led_min; i < led_max; i++) {
            single_color_raindrops_set_color(i, params);
        }
    }
    return rgb_matrix_check_finished_leds(led_max);
}

/* This "effect" is a workaround to fix long matrix scan pauses caused by i2c communication.
When enabled, it writes all relevant LEDs once to static colors, then halts LED refreshes until a different animation is selcted. */
bool STATIC_GAME_MODE(effect_params_t* params) {

    void game_mode_set_color(int i, effect_params_t* params) {
        if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) {
            return;
        }

        HSV hsv = rgb_matrix_get_hsv();

        switch (i) {
            case W_LED_INDEX:
            case A_LED_INDEX:
            case S_LED_INDEX:
            case D_LED_INDEX:

            case M_LED_INDEX:
            case K_LED_INDEX:
            case O_LED_INDEX:
            case P_LED_INDEX:
            case NUM_0_LED_INDEX:
            case SLSH_LED_INDEX:
                break;

            case SCLN_LED_INDEX:
            case ANV_A_LED_INDEX:
            case ANV_N_LED_INDEX:
            case ANV_V_LED_INDEX:
            case ANV_I_LED_INDEX:
            case ANV_L_LED_INDEX:
                hsv.s = 255;
                hsv.h = rgb_matrix_get_hue()+30;
                break;

            case NUM_1_LED_INDEX:
            case NUM_2_LED_INDEX:
            case NUM_3_LED_INDEX:
            case NUM_4_LED_INDEX:
            case NUM_5_LED_INDEX:
                hsv.s = 255;
                hsv.h = rgb_matrix_get_hue()+30;
                hsv.v = rgb_matrix_get_val()*2/3;
                break;

            default:
                hsv.v = 0;
                break;
        }

        RGB rgb = hsv_to_rgb(hsv);
        rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
    }

    RGB_MATRIX_USE_LIMITS(led_min, led_max);
    if (!params->init) {
        // Do not update LEDs after initial blanking
    } else {
        for (int i = led_min; i < led_max; i++) {
            game_mode_set_color(i, params);
        }
    }
    return rgb_matrix_check_finished_leds(led_max);
}

#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS