Skip to content

Commit

Permalink
jorne: add and use layer_status and bongocat
Browse files Browse the repository at this point in the history
  • Loading branch information
xkonni committed Oct 16, 2024
1 parent 3704792 commit cdd245d
Show file tree
Hide file tree
Showing 9 changed files with 901 additions and 70 deletions.
81 changes: 11 additions & 70 deletions keyboards/jorne/keymaps/xk_vial/keymap.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2021 Joric (@joric)
// SPDX-License-Identifier: GPL-2.0-or-later
#include QMK_KEYBOARD_H
// #include "lib/logo.h"
#include "lib/bongocat/bongocat.h"
#include "lib/layer_status/layer_status.h"

enum layers {
_QWERTY = 0,
Expand Down Expand Up @@ -73,78 +76,17 @@ layer_state_t layer_state_set_user(layer_state_t state) {
}

#ifdef OLED_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_270; }


// WPM-responsive animation stuff here
#define IDLE_FRAMES 2
#define IDLE_SPEED 40 // below this wpm value your animation will idle
#define IDLE_SLEEP 1 // below this wpm value the display turns off

#define ANIM_FRAME_DURATION 200 // how long each frame lasts in ms
// #define SLEEP_TIMER 60000 // should sleep after this period of 0 wpm, needs fixing
#define ANIM_SIZE 636 // number of bytes in array, minimize for adequate firmware size, max is 1024

uint32_t anim_timer = 0;
uint32_t anim_sleep = 0;
uint8_t current_idle_frame = 0;

// Credit to u/Pop-X- for the initial code. You can find his commit here https://github.com/qmk/qmk_firmware/pull/9264/files#diff-303f6e3a7a5ee54be0a9a13630842956R196-R333.
static void render_anim(void) {
static const char PROGMEM idle[IDLE_FRAMES][ANIM_SIZE] = {
{
0, 0,192,192,192,192,192,192,192,248,248, 30, 30,254,254,248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3,255,255,255,255,255,255,255,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,127,127,255,255,255,255,255,159,159,135,135,129,129,129, 97, 97, 25, 25, 7, 7, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 97, 97,127, 1, 1, 97, 97,127, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
},
{
0, 0,128,128,128,128,128,128,128,240,240, 60, 60,252,252,240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 7, 7, 7, 7, 7,255,255,254,254,255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255,255,255,255,255, 63, 63, 15, 15, 3, 3, 3,195,195, 51, 51, 15, 15, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 99, 99,127, 3, 3, 99, 99,127, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0
}
};

//assumes 1 frame prep stage
void animation_phase(void) {
current_idle_frame = (current_idle_frame + 1) % IDLE_FRAMES;
oled_write_raw_P(idle[abs((IDLE_FRAMES-1)-current_idle_frame)], ANIM_SIZE);
}

if(timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
anim_timer = timer_read32();
animation_phase();
bool oled_task_user(void) {
if (is_keyboard_left()) {
render_bongocat();
// oled_write_P(get_u8_str(get_current_wpm(), ' '), false);
}
}

bool oled_task_user(void) {
uint8_t current_wpm = get_current_wpm();
if (current_wpm <= IDLE_SLEEP) {
// in sleep mode => turn display off
oled_off();
return false;
}
render_anim();
oled_set_cursor(0,6);
if (is_keyboard_left()) {
oled_write_P(PSTR("-----\n"), false);
// Host Keyboard Layer Status
oled_write_P(PSTR("L "), false);
switch (get_highest_layer(layer_state)) {
case 0:
oled_write_P(PSTR("DEF\n"), false);
break;
case 1:
oled_write_P(PSTR("RSE\n"), false);
break;
case 2:
oled_write_P(PSTR("LWR\n"), false);
break;
case 3:
oled_write_P(PSTR("ADJ\n"), false);
break;
else {
render_layer_status();
// oled_write_P(get_u8_str(get_current_wpm(), ' '), false);
}
oled_write_P(PSTR("-----\n"), false);
oled_write_P(PSTR("W "), false);
oled_write_P(get_u8_str(current_wpm, ' '), false);
return true;
}
return false;
}
#endif

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
Expand All @@ -160,4 +102,3 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
return true;
}

4 changes: 4 additions & 0 deletions keyboards/jorne/keymaps/xk_vial/rules.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SRC += ./lib/logo.c
SRC += ./lib/layer_status/layer_status.c
SRC += ./lib/bongocat/bongocat.c

VIA_ENABLE = yes
VIAL_ENABLE = yes
LTO_ENABLE = yes # compile optimization, reduce size
Expand Down
Loading

0 comments on commit cdd245d

Please sign in to comment.