qmk

QMK Firmware
git clone git://git.z3bra.org/qmk.git
Log | Files | Refs | Submodules | LICENSE

ortho75.c (1168B)


      1 
      2 #include "ortho75.h"
      3 
      4 #define MEDIA_KEY_DELAY 10
      5 
      6 uint8_t layer = 0;
      7 
      8 uint32_t layer_state_set_kb(uint32_t state) {
      9   state = layer_state_set_user(state);
     10   layer = biton32(state);
     11   return state;
     12 }
     13 
     14 void encoder_update_kb(uint8_t index, bool clockwise) {
     15   uint16_t mapped_code = 0;
     16   if (index == 0) {
     17     if (clockwise) {
     18         switch(layer){
     19             case 0:
     20             default:
     21                 mapped_code = KC_VOLU;
     22                 break;
     23             case 1:
     24                 mapped_code = KC_MEDIA_NEXT_TRACK;
     25                 break;
     26             case 2:
     27                 mapped_code = KC_PGDN;
     28                 break;
     29         }
     30     } else {
     31         switch(layer){
     32             case 0:
     33             default:
     34                 mapped_code = KC_VOLD;
     35                 break;
     36             case 1:
     37                 mapped_code = KC_MEDIA_PREV_TRACK;
     38                 break;
     39             case 2:
     40                 mapped_code = KC_PGUP;
     41                 break;
     42         }
     43     }
     44     uint16_t held_keycode_timer = timer_read();
     45     register_code(mapped_code);
     46     while (timer_elapsed(held_keycode_timer) < MEDIA_KEY_DELAY){ /* no-op */ }
     47     unregister_code(mapped_code);
     48   }
     49 }