Author Topic: qmk fuction  (Read 5262 times)

0 Members and 1 Guest are viewing this topic.

Offline pixelpusher

  • * Elevated Elder
  • Thread Starter
  • Posts: 4180
  • Location: Tennessee - USA
qmk fuction
« on: Tue, 23 May 2017, 21:33:08 »
Anyone know if it is possible to turn backlight leds on when a specific layer is active and turn them off when not?  Been searching on qmk forums and I haven't seen much, but it seems like it should be possible.

Offline Tactile

  • Posts: 1434
  • Location: Portland, OR
Re: qmk fuction
« Reply #1 on: Tue, 23 May 2017, 22:04:53 »
My GH60 Rev C doesn't have full backlighting but does have a few lights - WASD group, the FN (split right shift) key, and some others. I use the lights as layer indicators. WASD light for FN, I have another toggled layer with lights under right shift, right control, - you know the arrow key setup like a Pok3r. Anyway, I'm using various lights as layer indicators with QMK. I've never used QMK with full backlighting, though.
REΛLFORCE

Offline lunas

  • Posts: 35
Re: qmk fuction
« Reply #2 on: Tue, 30 May 2017, 23:43:14 »
Layer indicators are so useful, I'm surprised it's not more readily documented. I had similar difficulty finding many discussions about it. There are various options to actually set the led on/off depending on your board's controller, but QMK has matrix_scan_user that loops constantly and a global variable layer_state that you can read and set led pins based on the value of layer_state.


matrix_scan runs continuously so it's overkill for checking layers, but you can just exit early if no change in layer is detected. TMK has other hook functions that run on more discrete events. QMK will probably add those at some point, but does not have them yet.



Something generally like this in your keymap:
Code: [Select]
void matrix_scan_user (void) {
...
  if (local_layer_state != layer_state) {
    active_layer = biton32(layer_state); //returns highest significant bit
    //set led code
   ...


Tactile - how did you set up your layer indicators?
Pok3r Whitefox

Offline pixelpusher

  • * Elevated Elder
  • Thread Starter
  • Posts: 4180
  • Location: Tennessee - USA
Re: qmk fuction
« Reply #3 on: Wed, 31 May 2017, 00:00:40 »
Layer indicators are so useful, I'm surprised it's not more readily documented. I had similar difficulty finding many discussions about it. There are various options to actually set the led on/off depending on your board's controller, but QMK has matrix_scan_user that loops constantly and a global variable layer_state that you can read and set led pins based on the value of layer_state.


matrix_scan runs continuously so it's overkill for checking layers, but you can just exit early if no change in layer is detected. TMK has other hook functions that run on more discrete events. QMK will probably add those at some point, but does not have them yet.



Something generally like this in your keymap:
Code: [Select]
void matrix_scan_user (void) {
...
  if (local_layer_state != layer_state) {
    active_layer = biton32(layer_state); //returns highest significant bit
    //set led code
   ...


Tactile - how did you set up your layer indicators?

I'll look into this.  I'm running QMK on this one, so I'll try to see what I can do.  Thanks.  :thumb:

Offline Tactile

  • Posts: 1434
  • Location: Portland, OR
Re: qmk fuction
« Reply #4 on: Wed, 31 May 2017, 00:16:59 »
Tactile - how did you set up your layer indicators?

My setup is very simple. The FN layer lights WASD and the light under the FN key (split right shift). Another key toggles an "arrow key" layer and lights the ESC and the "Pok3r LEDs", Right shift, right control, right alt & right WIN . My "arrow keys" just stay lit so I remember I've toggled that layer.
Code: [Select]
void matrix_scan_user(void) {

    //Layer LED indicators

    uint32_t layer = layer_state;

    if (layer & (1<<1)) {
        gh60_wasd_leds_on();
        gh60_fn_led_on();
    } else {
        gh60_wasd_leds_off();
        gh60_fn_led_off();
    }

    if (layer & (1<<2)) {
        gh60_poker_leds_on();
        gh60_esc_led_on();
    } else {
        gh60_poker_leds_off();
        gh60_esc_led_off();
}
« Last Edit: Wed, 31 May 2017, 00:21:27 by Tactile »
REΛLFORCE

Offline lunas

  • Posts: 35
Re: qmk fuction
« Reply #5 on: Wed, 31 May 2017, 16:31:37 »

My setup is very simple. The FN layer lights WASD and the light under the FN key (split right shift). Another key toggles an "arrow key" layer and lights the ESC and the "Pok3r LEDs", Right shift, right control, right alt & right WIN . My "arrow keys" just stay lit so I remember I've toggled that layer.

Mine is basically the same. Different details, but generally use matrix_scan for layer changes and process if so. Just asking to see what other approaches are out there. Thanks.
Pok3r Whitefox

Offline pixelpusher

  • * Elevated Elder
  • Thread Starter
  • Posts: 4180
  • Location: Tennessee - USA
Re: qmk fuction
« Reply #6 on: Mon, 18 September 2017, 16:49:22 »
Okay, it's been a long time and I still have yet to tackle this one.

I'm trying to get this working on a s60x-RGB board.  It doesn't have led indicators, but I have put in switch leds on the cluster I want illuminated.  I need to trigger the BL_ON function when Layer 1 is active and BL_OFF when not.

void matrix_scan_user(void) {
     uint32_t layer = layer_state;
   
    if (layer & (1<<1)) {
        BL_ON
    } else {
        BL_OFF
    }

Can I use those codes directly or do I have to write a function?

Offline Tactile

  • Posts: 1434
  • Location: Portland, OR
Re: qmk fuction
« Reply #7 on: Mon, 18 September 2017, 17:45:57 »
Okay, it's been a long time and I still have yet to tackle this one.

I'm trying to get this working on a s60x-RGB board.  It doesn't have led indicators, but I have put in switch leds on the cluster I want illuminated.  I need to trigger the BL_ON function when Layer 1 is active and BL_OFF when not.

void matrix_scan_user(void) {
     uint32_t layer = layer_state;
   
    if (layer & (1<<1)) {
        BL_ON
    } else {
        BL_OFF
    }

Can I use those codes directly or do I have to write a function?

You should find existing functions in qmk_firmware/tmk_core/common/

In particular check out the files backlight.c backlight.h and see the function "keyboard_set_leds" in the file keyboard.c

I know this is an incomplete answer but I'm hoping this will help steer you in the right direction.
REΛLFORCE

Offline pixelpusher

  • * Elevated Elder
  • Thread Starter
  • Posts: 4180
  • Location: Tennessee - USA
Re: qmk fuction
« Reply #8 on: Mon, 18 September 2017, 23:20:45 »
Okay, I think I see it.  backlight_level()

And my max lvl is 7

I'll give it a go and report back.

Thanks

Offline pixelpusher

  • * Elevated Elder
  • Thread Starter
  • Posts: 4180
  • Location: Tennessee - USA
Re: qmk fuction
« Reply #9 on: Tue, 19 September 2017, 00:15:13 »
when I try to use

void matrix_scan_user(void) {
 uint32_t layer = layer_state;
   
    if (layer & (1<<1)) {
       backlight_set(7)
    } else {
        backlight_set(0)
    }
}

in the kbfirmware app (online app http://kbfirmware.com/), it gives an error.  Do you think it's wrong or just not supported in that application?

Offline Tactile

  • Posts: 1434
  • Location: Portland, OR
Re: qmk fuction
« Reply #10 on: Tue, 19 September 2017, 00:31:46 »
when I try to use

void matrix_scan_user(void) {
 uint32_t layer = layer_state;
   
    if (layer & (1<<1)) {
       backlight_set(7)
    } else {
        backlight_set(0)
    }
}

in the kbfirmware app (online app http://kbfirmware.com/), it gives an error.  Do you think it's wrong or just not supported in that application?

I've never heard of that tool. Maybe someone else can help.
REΛLFORCE

Offline pixelpusher

  • * Elevated Elder
  • Thread Starter
  • Posts: 4180
  • Location: Tennessee - USA
Re: qmk fuction
« Reply #11 on: Tue, 19 September 2017, 00:51:17 »
IT WORKED!

I was just missing a semicolon.  Awesome.  Thanks for your help!

Offline pixelpusher

  • * Elevated Elder
  • Thread Starter
  • Posts: 4180
  • Location: Tennessee - USA
Re: qmk fuction
« Reply #12 on: Tue, 19 September 2017, 11:06:54 »
void matrix_scan_user(void) {
 uint32_t layer = layer_state;
   
    if (layer & (1<<2)) {
       backlight_set(7);
    } else {
        backlight_set(0);
    }
}

Totally worked.  With this, I have a lock switch on my split right shift that enables the 2nd function layer.  And now, thanks to you guys, it turns on the led cluster I have underneath the bottom for a nav cluster!  Thanks, again. 

Offline Tactile

  • Posts: 1434
  • Location: Portland, OR
Re: qmk fuction
« Reply #13 on: Tue, 19 September 2017, 11:11:22 »
 :thumb:
REΛLFORCE