qmk_firmware

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

gg86.c (3362B)


      1 /* Copyright 2023 Gopolar
      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 "quantum.h"
     18 
     19 // OLED animation
     20 #include "lib/logo.h"
     21 
     22 #ifdef RGB_MATRIX_ENABLE
     23 
     24 #include <string.h>
     25 #include <math.h>
     26 #include <lib/lib8tion/lib8tion.h>
     27 
     28 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
     29     switch (keycode) {
     30         case QK_RGB_MATRIX_TOGGLE:
     31             if (record->event.pressed) {
     32                 switch (rgb_matrix_get_flags()) {
     33                     case LED_FLAG_ALL: {
     34                         rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
     35                         rgb_matrix_set_color_all(0, 0, 0);
     36                     }
     37                     break;
     38                     case (LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR): {
     39                         rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
     40                         rgb_matrix_set_color_all(0, 0, 0);
     41                     }
     42                     break;
     43                     case (LED_FLAG_UNDERGLOW): {
     44                         rgb_matrix_set_flags(LED_FLAG_NONE);
     45                         rgb_matrix_set_color_all(0, 0, 0);
     46                     }
     47                     break;
     48                     default: {
     49                         rgb_matrix_set_flags(LED_FLAG_ALL);
     50                         rgb_matrix_enable_noeeprom();
     51                     }
     52                     break;
     53                 }
     54             }
     55             return false;
     56     }
     57     return process_record_user(keycode, record);
     58 }
     59 
     60 bool rgb_matrix_indicators_kb(void) {
     61     if (!rgb_matrix_indicators_user()) {
     62         return false;
     63     }
     64 
     65     hsv_t   hsv = rgb_matrix_config.hsv;
     66     uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
     67     hsv.h        = time;
     68     rgb_t   rgb = hsv_to_rgb(hsv);
     69 
     70     if (host_keyboard_led_state().caps_lock) {
     71         rgb_matrix_set_color(25, rgb.r, rgb.g, rgb.b);
     72     } else if (!(rgb_matrix_get_flags() & LED_FLAG_INDICATOR)) {
     73         rgb_matrix_set_color(25, 0, 0, 0);
     74     }
     75 
     76     if (host_keyboard_led_state().scroll_lock) {
     77         rgb_matrix_set_color(73, rgb.r, rgb.g, rgb.b);
     78     } else if (!(rgb_matrix_get_flags() & LED_FLAG_INDICATOR)) {
     79         rgb_matrix_set_color(73, 0, 0, 0);
     80     }
     81     return true;
     82 }
     83 #endif
     84 
     85 #ifdef OLED_ENABLE
     86     uint16_t startup_timer;
     87 
     88     oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
     89         startup_timer = timer_read();
     90 
     91         return rotation;
     92     }
     93 
     94     bool oled_task_kb(void) {
     95         static bool finished_logo = false;
     96 
     97         if ((timer_elapsed(startup_timer) < 5000) && !finished_logo) {
     98             render_logo();
     99         } else {
    100             finished_logo = true;
    101 
    102             if (!oled_task_user()) {
    103                 return false;
    104             }
    105         }
    106 
    107         return true;
    108     }
    109 #endif