Author Topic: TMK keyboard firmware  (Read 579391 times)

0 Members and 1 Guest are viewing this topic.

Offline Alectardy98

  • Posts: 15
  • Location: United States
  • Pre Dental
Re: TMK keyboard firmware
« Reply #2000 on: Tue, 05 January 2021, 17:30:31 »
I was able to make it work, but it might not be the cleanest. I am new to coding

Code: [Select]
bool my_led_status = 1;

hook_layer_change(uint32_t layer_state)
{
    if (my_led_status);

        if (layer_state & (1L<<1)) {
            // LED is off, so let's turn it on
            led_set(host_keyboard_leds() | (1<<USB_LED_NUM_LOCK));
            my_led_status = 1;
        } else {
            // LED is on, so let's turn it off
            led_set(host_keyboard_leds() & ~(1<<USB_LED_NUM_LOCK));
            my_led_status = 0;
           
     }
   
}


hook_keyboard_leds_change(uint8_t led_status)
{
    if (my_led_status)
            {
                // LED is off, so let's turn it on
                led_set(host_keyboard_leds() | (1<<USB_LED_NUM_LOCK));
                my_led_status = 1;
            }
            else
            {
                // LED is on, so let's turn it off
                led_set(host_keyboard_leds() & ~(1<<USB_LED_NUM_LOCK));
                my_led_status = 0;
            }
        }
   
hook_late_init(void)
{
if (my_led_status)

    {
        led_set(host_keyboard_leds() & ~(1<<USB_LED_NUM_LOCK));
        my_led_status = 0;
    }
}

Offline hasu

  • Thread Starter
  • Posts: 3188
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #2001 on: Tue, 05 January 2021, 21:04:04 »
Looks good enough.
I think you don't need 'hook_late_init'.

Code: [Select]
#include "host.h"
#include "led.h"
bool my_led_status = 0;

void hook_layer_change(uint32_t layer_state)
{
    if (layer_state & (1L<<1)) {
        // LED is off, so let's turn it on
        led_set(host_keyboard_leds() | (1<<USB_LED_NUM_LOCK));
        my_led_status = 1;
    } else {
        // LED is on, so let's turn it off
        led_set(host_keyboard_leds() & ~(1<<USB_LED_NUM_LOCK));
        my_led_status = 0;
    }
}


void hook_keyboard_leds_change(uint8_t led_status)
{
    if (my_led_status)
    {
        // LED is off, so let's turn it on
        led_set(host_keyboard_leds() | (1<<USB_LED_NUM_LOCK));
        my_led_status = 1;
    }
    else
    {
        // LED is on, so let's turn it off
        led_set(host_keyboard_leds() & ~(1<<USB_LED_NUM_LOCK));
        my_led_status = 0;
    }
}

If you care about initial state of indicators refer this issue.
https://github.com/tmk/tmk_keyboard/issues/665
TMK products:HHKB Alt  ⌨ConvertersAlps64FC660C AltFC980C Alt