the-via / releases

GNU General Public License v3.0
2.04k stars 222 forks source link

Layer lighting #119

Open Hovc1 opened 3 years ago

Hovc1 commented 3 years ago

I am unable to change the layer lighting on my prime_e. I have 3 indicator lights on my keyboard for things like layer indication and caps lock.

This is the code bit I use for QMK, that I wish VIA had for controlling layer lights. (Sorry about the code format / lack of indentation, I do not know why github does this.

void matrix_init_user(void) { setPinOutput(B1); // Layer 1 writePinLow(B1); setPinOutput(B2); // Layer 2 writePinLow(B2); setPinOutput(B3); // Caps Lock ON writePinLow(B3); }

void matrix_scan_user(void) { }

// B1 is the top light, and B3 is the bottom light void led_set_user(uint8_t usb_led) { if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) { // turns the bottom white LED on for caps lock writePinHigh(B3); } else { writePinLow(B3); } }

// turns the top white LED on for layer 1 and the middle LED on for layer 2 uint32_t layer_state_set_user(uint32_t state){ switch(biton32(state)) { case _AA: writePinLow(B1); writePinLow(B2); break; case _BB: writePinHigh(B1); break; case _CC: writePinHigh(B2); break; } return state; }

metakirby5 commented 2 years ago

I'd also be very grateful for layer lighting support. At the moment, it's possible to hard code the layer lighting by modifying the via keymap source files. Configurability in the software layer would save a lot of time unscrewing and rescrewing.

For example, I modified .qmk/keyboards/gray_studio/think65/solder/keymaps/via:

Add config.h

#define RGBLIGHT_LAYERS
#define RGBLIGHT_LAYERS_RETAIN_VAL

Add lines to keymap.c

/*
* LED ranges for Think6.5v2 2U
* These values were derived from manual testing. Derived from keymaps/rys.
* ┌───────┬───────┬─────────────┬───────────────────────────────────────────┐
* │ 00 01 │ 02 03 │ 04 05 06 07 │ 08 09 10 11 12 13 14 15 16 17 18 19 20 21 │
* │ badge │ badge │    (?)      │              underglow (?)                │
* │  bar  │ icon  │             │                                           │
* └───────┴───────┴─────────────┴───────────────────────────────────────────┘
*/

// Define the LED ranges    start, count
#define T65_CAPS                0, 2
#define T65_BADGE               2, 2
#define T65_UNDERGLOW           4, 18
#define T65_ALL                 0, 22

const rgblight_segment_t PROGMEM mk5_rgb_caps[] = RGBLIGHT_LAYER_SEGMENTS(
    {T65_CAPS, HSV_WHITE}
);

const rgblight_segment_t PROGMEM mk5_rgb_layer1[] = RGBLIGHT_LAYER_SEGMENTS(
    {T65_BADGE, HSV_CYAN}
);

const rgblight_segment_t PROGMEM mk5_rgb_layer2[] = RGBLIGHT_LAYER_SEGMENTS(
    {T65_BADGE, HSV_CORAL}
);

const rgblight_segment_t PROGMEM mk5_rgb_layer3[] = RGBLIGHT_LAYER_SEGMENTS(
    {T65_BADGE, HSV_PURPLE}
);

const rgblight_segment_t* const PROGMEM mk5_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
    mk5_rgb_caps,
    mk5_rgb_layer1,
    mk5_rgb_layer2,
    mk5_rgb_layer3
);

void keyboard_post_init_user(void) {
    rgblight_layers = mk5_rgb_layers;
}

bool led_update_user(led_t led_state) {
    rgblight_set_layer_state(0, led_state.caps_lock);
    return true;
}

layer_state_t layer_state_set_user(layer_state_t state) {
    for (int i = 1; i <= 3; i++) {
        rgblight_set_layer_state(i, layer_state_cmp(state, i));
    }
    return state;
}

Results

metakirby5 commented 2 years ago

Configurability in the software layer would save a lot of time unscrewing and rescrewing.

I just realized that you can map Reset to a key to allow for re-flashing without hitting the PCB's reset pins, so it's a little less cumbersome, but still on the wish list 🙂