summaryrefslogtreecommitdiff
path: root/users/spidey3/layer_rgb.c
blob: d80eb20a3192c7d82f4f49ac8301a223bc574810 (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
#include QMK_KEYBOARD_H

#include "spidey3.h"
#include "velocikey.h"

uint32_t rgb_mode;
uint16_t rgb_hue;
uint8_t rgb_sat;
uint8_t rgb_val;
bool rgb_saved = 0;

void spidey_swirl(void) {
  dprint("SPIDEY3: Setting Spidey Swirl!\n");
  rgblight_enable();
  rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
  rgblight_sethsv(213, 255, 128);
#ifdef VELOCIKEY_ENABLE
  if (!velocikey_enabled())
	velocikey_toggle();
#endif
}

void eeconfig_init_user_rgb(void)
{
  spidey_swirl();
}

const rgblight_segment_t PROGMEM _capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS( {0, 2, HSV_AZURE}, {14, 2, HSV_AZURE} );
const rgblight_segment_t PROGMEM _layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS( {7, 1, HSV_PURPLE} );
const rgblight_segment_t PROGMEM _layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 2, HSV_GREEN} );

// Now define the array of layers. Later layers take precedence
const rgblight_segment_t* const PROGMEM _rgb_layers[] = RGBLIGHT_LAYERS_LIST( _capslock_layer, _layer1_layer, _layer2_layer );
const uint8_t PROGMEM _n_rgb_layers = sizeof(_rgb_layers) / sizeof(_rgb_layers[0]) - 1;

void do_rgb_layers(layer_state_t state, uint8_t start, uint8_t end) {
    dprint("SPIDEY3: do_rgb_layers()\n");
    for (uint8_t i=start; i<end; i++) { 
      bool is_on = layer_state_cmp(state, i);
      dprintf("         layer[%d]=%u\n", i, is_on);
      rgblight_set_layer_state(i, is_on);
    }
}

void keyboard_post_init_user_rgb(void) {
    do_rgb_layers(default_layer_state, 1u, RGB_LAYER_BASE_REGULAR);
    do_rgb_layers(layer_state, RGB_LAYER_BASE_REGULAR, _n_rgb_layers);
    // Enable the LED layers
    rgblight_layers = _rgb_layers;
}

layer_state_t default_layer_state_set_user_rgb(layer_state_t state) {
    dprint("SPIDEY3: default_layer_state_set_user_rgb()\n");
    do_rgb_layers(state, 1u, RGB_LAYER_BASE_REGULAR);
    return state;
}

layer_state_t layer_state_set_user_rgb(layer_state_t state) {
    dprint("SPIDEY3: layer_state_set_user_rgb()\n");
    do_rgb_layers(state, RGB_LAYER_BASE_REGULAR, _n_rgb_layers);
    return state;
}

bool led_update_user_rgb(led_t led_state) {
    dprintf("SPIDEY3: caps_lock=%u\n", led_state.caps_lock);
    rgblight_set_layer_state(0, led_state.caps_lock);
    return true;
}

bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) {

  switch (keycode) {
    case SPI_GLO:
      if (record->event.pressed) {
        spidey_swirl();
      }
      break;
  }

  return true;
}