qmk_firmware

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

navpad_prefs.c (2536B)


      1 /* Copyright 2021 yushakobo
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 
     17 #include "navpad_prefs.h"
     18 #include "quantum.h"
     19 #include "action.h"
     20 #include "action_layer.h"
     21 #include "rgblight.h"
     22 #include "led.h"
     23 
     24 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
     25     if (!process_record_user(keycode, record)) { return false; }
     26     switch (keycode) {
     27   case TAP_00:
     28     if (record->event.pressed){
     29       tap_code(KC_P0);
     30       tap_code(KC_P0);
     31       }
     32     break;
     33 
     34   default:
     35     break;
     36   }
     37   return true;
     38 }
     39 
     40 #ifdef ENCODER_ENABLE
     41 bool encoder_update_kb(uint8_t index, bool clockwise) {
     42     if (!encoder_update_user(index, clockwise)) { return false; }
     43     if (index == 0) { /* Navpad side encoder */
     44       switch (get_highest_layer(layer_state|default_layer_state)) {
     45       case _BASE:
     46         if (clockwise) {
     47           tap_code16(KC_VOLU);
     48         } else {
     49           tap_code16(KC_VOLD);
     50         }
     51         break;
     52       
     53       case _FN1:
     54         if (clockwise) {
     55           rgblight_increase_hue();
     56         } else {
     57           rgblight_decrease_hue();
     58         }
     59         break;
     60       
     61       case _FN2:
     62         if (clockwise) {
     63           rgblight_increase_sat();
     64         } else {
     65           rgblight_decrease_sat();
     66         }
     67         break;
     68 
     69       default:
     70         break;
     71       }
     72     }
     73     if (index == 1) { /* Helix side encoder */
     74       switch (get_highest_layer(layer_state|default_layer_state)) {
     75       case _BASE:
     76         if (clockwise) {
     77           tap_code(KC_RBRC);
     78         } else {
     79           tap_code(KC_LBRC);
     80         }
     81         break;
     82       
     83       case _FN1:
     84         if (clockwise) {
     85           tap_code16(KC_RPRN);
     86         } else {
     87           tap_code16(KC_LPRN);
     88         }
     89         break;
     90       
     91       case _FN2:
     92         if (clockwise) {
     93           tap_code16(KC_RCBR);
     94         } else {
     95           tap_code16(KC_LCBR);
     96         }
     97         break;
     98 
     99       default:
    100         break;
    101       }
    102     }
    103     return false;
    104   }
    105 #endif