qmk_firmware

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

zima.c (3872B)


      1 /* Copyright 2019 Thomas Baart
      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 #include "quantum.h"
     17 #include <stdio.h>
     18 
     19 #ifdef HAPTIC_ENABLE
     20 #    include "haptic.h"
     21 extern haptic_config_t haptic_config;
     22 #endif
     23 
     24 #ifdef OLED_ENABLE
     25 static bool is_asleep = false;
     26 static uint32_t oled_timer;
     27 
     28 void suspend_power_down_kb(void) {
     29     is_asleep = true;
     30     suspend_power_down_user();
     31 }
     32 
     33 void suspend_wakeup_init_kb(void) {
     34     is_asleep = false;
     35     suspend_wakeup_init_user();
     36 }
     37 
     38 oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
     39     return OLED_ROTATION_180;
     40 }
     41 
     42 bool oled_task_kb(void) {
     43     if (!oled_task_user()) {
     44         return false;
     45     }
     46     if (is_asleep) {
     47         oled_off();
     48         return false;
     49     }
     50 
     51     if (timer_elapsed32(oled_timer) < 30000) {
     52         oled_on();
     53         oled_scroll_off();
     54         oled_write_P(PSTR("SplitKB's Zima"), false);
     55         char layer[2] = {0};
     56         snprintf(layer, sizeof(layer), "%d", get_highest_layer(layer_state));
     57         oled_write_P(PSTR("   L:"), false);
     58         oled_write_ln(layer, false);
     59         oled_write_ln_P(PSTR("--------------"), false);
     60         if (rgblight_is_enabled()) {
     61             oled_write_P(PSTR("HSV: "), false);
     62             char rgbs[14];
     63             snprintf(rgbs, sizeof(rgbs), "%3d, %3d, %3d", rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val());
     64             oled_write_ln(rgbs, false);
     65         } else {
     66             oled_write_ln_P(PSTR("RGB LIGHT DISABLED"), false);
     67         }
     68 #    ifdef AUDIO_ENABLE
     69         oled_write_P(PSTR("Audio:"), false);
     70         is_audio_on() ? oled_write_P(PSTR(" on"), false) : oled_write_P(PSTR("off"), false);
     71 #        ifdef AUDIO_CLICKY
     72         oled_write_P(PSTR(" Clicky:"), false);
     73         (is_clicky_on() && is_audio_on()) ? oled_write_P(PSTR(" on"), false) : oled_write_P(PSTR("off"), false);
     74 #        endif
     75 #    endif
     76     } else {
     77         if (timer_elapsed32(oled_timer) < 120000) {
     78             oled_on();
     79             // clang-format off
     80             static const char PROGMEM qmk_logo[] = {
     81                 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
     82                 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
     83                 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
     84             // clang-format on
     85             oled_write_ln_P(qmk_logo, false);
     86             oled_scroll_right();
     87         } else {
     88             oled_off();
     89         }
     90     }
     91     return false;
     92 }
     93 
     94 bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
     95     oled_timer = timer_read32();
     96 
     97     return process_record_user(keycode, record);
     98 }
     99 #endif
    100 
    101 #ifdef ENCODER_ENABLE
    102 bool encoder_update_kb(uint8_t index, bool clockwise) {
    103 #    ifdef OLED_ENABLE
    104     oled_timer = timer_read32();
    105 #    endif
    106 #    if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
    107     if (is_audio_on() && is_clicky_on()) clicky_play();
    108 #    endif
    109 #    ifdef HAPTIC_ENABLE
    110     if (haptic_config.enable) haptic_play();
    111 #    endif
    112     if (!encoder_update_user(index, clockwise)) return false;
    113     if (clockwise) {
    114         tap_code16(KC_VOLU);
    115     } else {
    116         tap_code16(KC_VOLD);
    117     }
    118     return true;
    119 }
    120 #endif