qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

knobs3.c (2081B)


      1 // Copyright 2022 Leon Anavi <leon@anavi.org>
      2 // SPDX-License-Identifier: GPL-2.0-or-later
      3 
      4 #include "quantum.h"
      5 #include <stdio.h>
      6 
      7 void keyboard_post_init_kb(void) {
      8     // Enable RGB LED
      9     gpio_set_pin_output(GP11);
     10     gpio_write_pin_high(GP11);
     11     rgblight_enable();
     12 
     13     // Offload to the user func
     14     keyboard_post_init_user();
     15 }
     16 
     17 #ifdef ENCODER_ENABLE
     18 bool encoder_update_kb(uint8_t index, bool clockwise) {
     19     if (!encoder_update_user(index, clockwise)) { return false; }
     20     if (0 == index) {
     21         if (clockwise) {
     22             tap_code(KC_VOLU);
     23         } else {
     24             tap_code(KC_VOLD);
     25         }
     26     } else if (1 == index) {
     27         if (clockwise) {
     28             tap_code(KC_UP);
     29         } else {
     30             tap_code(KC_DOWN);
     31         }
     32     } else if (2 == index) {
     33         if (clockwise) {
     34             tap_code(KC_LEFT);
     35         } else {
     36             tap_code(KC_RIGHT);
     37         }
     38     }
     39     return true;
     40 }
     41 #endif
     42 
     43 #ifdef OLED_ENABLE
     44 
     45 bool oled_task_kb(void) {
     46 
     47     if (!oled_task_user()) {
     48         return false;
     49     }
     50 
     51     // Host Keyboard Layer Status
     52     oled_write_ln_P(PSTR("ANAVI Knobs 3"), false);
     53     oled_write_ln_P(PSTR("Keymap: Default"), false);
     54 
     55     // Host Keyboard LED Status
     56     led_t led_state = host_keyboard_led_state();
     57     oled_write_P(PSTR("Num Lock: "), false);
     58     oled_write_ln_P(led_state.num_lock ? PSTR("On") : PSTR("Off"), false);
     59     oled_write_P(PSTR("Caps Lock: "), false);
     60     oled_write_ln_P(led_state.caps_lock ? PSTR("On") : PSTR("Off"), false);
     61     oled_write_P(PSTR("Scroll Lock: "), false);
     62     oled_write_ln_P(led_state.scroll_lock ? PSTR("On") : PSTR("Off"), false);
     63 #ifdef RGBLIGHT_ENABLE
     64     static char rgbStatusLine1[26] = {0};
     65     snprintf(rgbStatusLine1, sizeof(rgbStatusLine1), "RGB Mode: %d", rgblight_get_mode());
     66     oled_write_ln(rgbStatusLine1, false);
     67     static char rgbStatusLine2[26] = {0};
     68     snprintf(rgbStatusLine2, sizeof(rgbStatusLine2), "h:%d s:%d v:%d", rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val());
     69     oled_write_ln(rgbStatusLine2, false);
     70 #endif
     71     return false;
     72 }
     73 #endif