update oleds + luna pet

This commit is contained in:
♥ Minnie ♥ 2023-04-13 11:48:44 +08:00
parent 850f470dd9
commit cfbf3da29e
4 changed files with 290 additions and 104 deletions

View file

@ -29,6 +29,11 @@
#define COMBO_TERM 50 #define COMBO_TERM 50
#define COMBO_ONLY_FROM_LAYER 0 #define COMBO_ONLY_FROM_LAYER 0
// Data Sync
#define SPLIT_LAYER_STATE_ENABLE
#define SPLIT_MODS_ENABLE
#define SPLIT_WPM_ENABLE
// RGB // RGB
#ifdef RGBLIGHT_ENABLE #ifdef RGBLIGHT_ENABLE
#define RGBLIGHT_SLEEP #define RGBLIGHT_SLEEP

View file

@ -1,25 +1,195 @@
#include QMK_KEYBOARD_H #include QMK_KEYBOARD_H
#include <stdio.h> #include "features/sentence_case.h"
#include "layers.h" #include "layers.h"
#include "oled.h"
#include <stdio.h>
/* KEYBOARD PET START */
static void render_luna(int LUNA_X, int LUNA_Y) {
/* Sit */
static const char PROGMEM sit[2][ANIM_SIZE] = {/* 'sit1', 32x22px */
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1c, 0x02, 0x05, 0x02, 0x24, 0x04, 0x04, 0x02, 0xa9, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x68, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x82, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0c, 0x10, 0x10, 0x20, 0x20, 0x20, 0x28, 0x3e, 0x1c, 0x20, 0x20, 0x3e, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* 'sit2', 32x22px */
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1c, 0x02, 0x05, 0x02, 0x24, 0x04, 0x04, 0x02, 0xa9, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x90, 0x08, 0x18, 0x60, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0e, 0x82, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0c, 0x10, 0x10, 0x20, 0x20, 0x20, 0x28, 0x3e, 0x1c, 0x20, 0x20, 0x3e, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
/* Walk */
static const char PROGMEM walk[2][ANIM_SIZE] = {/* 'walk1', 32x22px */
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x90, 0x90, 0x90, 0xa0, 0xc0, 0x80, 0x80, 0x80, 0x70, 0x08, 0x14, 0x08, 0x90, 0x10, 0x10, 0x08, 0xa4, 0x78, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x08, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0xea, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x20, 0x20, 0x3c, 0x0f, 0x11, 0x1f, 0x03, 0x06, 0x18, 0x20, 0x20, 0x3c, 0x0c, 0x12, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* 'walk2', 32x22px */
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x20, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x28, 0x10, 0x20, 0x20, 0x20, 0x10, 0x48, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x20, 0xf8, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x30, 0xd5, 0x20, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x30, 0x0c, 0x02, 0x05, 0x09, 0x12, 0x1e, 0x02, 0x1c, 0x14, 0x08, 0x10, 0x20, 0x2c, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}};
/* Run */
static const char PROGMEM run[2][ANIM_SIZE] = {/* 'run1', 32x22px */
{
0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x08, 0xc8, 0xb0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x40, 0x3c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xc4, 0xa4, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc8, 0x58, 0x28, 0x2a, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x09, 0x04, 0x04, 0x04, 0x04, 0x02, 0x03, 0x02, 0x01, 0x01, 0x02, 0x02, 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* 'run2', 32x22px */
{
0x00, 0x00, 0x00, 0xe0, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x78, 0x28, 0x08, 0x10, 0x20, 0x30, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0xb0, 0x50, 0x55, 0x20, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, 0x02, 0x1e, 0x20, 0x20, 0x18, 0x0c, 0x14, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}};
/* Bark */
static const char PROGMEM bark[2][ANIM_SIZE] = {/* 'bark1', 32x22px */
{
0x00, 0xc0, 0x20, 0x10, 0xd0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x3c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc8, 0x48, 0x28, 0x2a, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, 0x02, 0x02, 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* 'bark2', 32x22px */
{
0x00, 0xe0, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x40, 0x2c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x48, 0x28, 0x2a, 0x10, 0x0f, 0x20, 0x4a, 0x09, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, 0x02, 0x02, 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}};
/* Sneak */
static const char PROGMEM sneak[2][ANIM_SIZE] = {/* 'sneak1', 32x22px */
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x40, 0x40, 0x80, 0x00, 0x80, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x21, 0xf0, 0x04, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x04, 0x04, 0x04, 0x03, 0x01, 0x00, 0x00, 0x09, 0x01, 0x80, 0x80, 0xab, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x20, 0x20, 0x3c, 0x0f, 0x11, 0x1f, 0x02, 0x06, 0x18, 0x20, 0x20, 0x38, 0x08, 0x10, 0x18, 0x04, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00,
},
/* 'sneak2', 32x22px */
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xa0, 0x20, 0x40, 0x80, 0xc0, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x41, 0xf0, 0x04, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x40, 0x55, 0x82, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x30, 0x0c, 0x02, 0x05, 0x09, 0x12, 0x1e, 0x04, 0x18, 0x10, 0x08, 0x10, 0x20, 0x28, 0x34, 0x06, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
}};
/* animation */
void animate_luna(void) {
/* jump */
if (isJumping || !showedJump) {
/* clear */
oled_set_cursor(LUNA_X, LUNA_Y + 2);
oled_write(" ", false);
oled_set_cursor(LUNA_X, LUNA_Y - 1);
showedJump = true;
} else {
/* clear */
oled_set_cursor(LUNA_X, LUNA_Y - 1);
oled_write(" ", false);
oled_set_cursor(LUNA_X, LUNA_Y);
}
/* switch frame */
current_frame = (current_frame + 1) % 2;
/* current status */
if (led_usb_state.caps_lock | is_caps_word_on()) {
oled_write_raw_P(bark[current_frame], ANIM_SIZE);
} else if (isSneaking) {
oled_write_raw_P(sneak[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_WALK_SPEED) {
oled_write_raw_P(sit[current_frame], ANIM_SIZE);
} else if (current_wpm <= MIN_RUN_SPEED) {
oled_write_raw_P(walk[current_frame], ANIM_SIZE);
} else {
oled_write_raw_P(run[current_frame], ANIM_SIZE);
}
}
# if OLED_TIMEOUT > 0
/* the animation prevents the normal timeout from occuring */
if (last_input_activity_elapsed() > OLED_TIMEOUT && last_led_activity_elapsed() > OLED_TIMEOUT) {
oled_off();
return;
} else {
oled_on();
}
# endif
/* animation timer */
if (timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
anim_timer = timer_read32();
animate_luna();
}
}
/* KEYBOARD PET END */
oled_rotation_t oled_init_user(oled_rotation_t rotation) { oled_rotation_t oled_init_user(oled_rotation_t rotation) {
if (is_keyboard_master()) { if (is_keyboard_master()) {
return OLED_ROTATION_270; return OLED_ROTATION_270;
} else { } else {
return OLED_ROTATION_180; return OLED_ROTATION_270;
} }
return rotation; return rotation;
} }
void oled_render_master(void) { void oled_render_master(void) {
// Layer Status // Default layer
switch (get_highest_layer(layer_state)) { switch (get_highest_layer(default_layer_state)) {
case L_QWERTY: case L_QWERTY:
oled_write("QWRTY", false); oled_write("QWRTY", false);
break; break;
case L_CANARY: case L_CANARY:
oled_write("CANRY", false); oled_write("CANRY", false);
break; break;
default:
oled_write("UNDEF", false);
}
// Feature Status
oled_write("-----", false);
bool autoshift_enabled = get_autoshift_state();
if (autoshift_enabled) {
oled_write("as: *", false);
} else {
oled_write("as: .", false);
}
bool autocorrect_enabled = autocorrect_is_enabled();
if (autocorrect_enabled) {
oled_write("ac: *", false);
} else {
oled_write("ac: .", false);
}
bool combo_enabled = is_combo_enabled();
if (combo_enabled) {
oled_write("cm: *", false);
} else {
oled_write("cm: .", false);
}
bool sentence_case_enabled = is_sentence_case_on();
if (sentence_case_enabled) {
oled_write("sc: *", false);
} else {
oled_write("sc: .", false);
}
bool caps_word_enabled = is_caps_word_on();
if (caps_word_enabled) {
oled_write("cw: *", false);
} else {
oled_write("cw: .", false);
}
// Render Pet
render_luna(0, 13);
}
void oled_render_slave(void) {
// Layer Status
switch (get_highest_layer(layer_state)) {
case L_QWERTY:
case L_CANARY:
oled_write("DEFLT", false);
break;
case L_LOWER: case L_LOWER:
oled_write("LOWER", false); oled_write("LOWER", false);
break; break;
@ -32,8 +202,12 @@ void oled_render_master(void) {
case L_EXTEND: case L_EXTEND:
oled_write("EXTND", false); oled_write("EXTND", false);
break; break;
case L_GAMING:
case L_GAMEFN:
oled_write("GAMES", false);
break;
default: default:
oled_write_ln(" UND", false); oled_write("UNDEF", false);
} }
// Mod Status // Mod Status
@ -66,38 +240,6 @@ void oled_render_master(void) {
oled_write("ctl:.", false); oled_write("ctl:.", false);
} }
// Feature Status
oled_write("-----", false);
bool is_autoshift_enabled = get_autoshift_state();
if (is_autoshift_enabled) {
oled_write("as: *", false);
} else {
oled_write("as: .", false);
}
bool is_autocorrect_enabled = autocorrect_is_enabled();
if (is_autocorrect_enabled) {
oled_write("ac: *", false);
} else {
oled_write("ac: .", false);
}
if (is_combo_enabled()) {
oled_write("cm: *", false);
} else {
oled_write("cm: .", false);
}
// Caps Word
oled_write("-----", false);
if (is_caps_word_on()) {
oled_write("cap:*", false);
} else {
oled_write("cap:.", false);
}
// WPM Status // WPM Status
char wpm_str[4]; char wpm_str[4];
sprintf(wpm_str, "%03d", get_current_wpm()); sprintf(wpm_str, "%03d", get_current_wpm());
@ -106,16 +248,10 @@ void oled_render_master(void) {
oled_write(" wpm", false); oled_write(" wpm", false);
} }
void oled_render_slave(void) {
static const char PROGMEM crkbd_logo[] = {
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
0};
oled_write_P(crkbd_logo, false);
}
bool oled_task_user(void) { bool oled_task_user(void) {
current_wpm = get_current_wpm();
led_usb_state = host_keyboard_led_state();
if (is_keyboard_master()) { if (is_keyboard_master()) {
oled_render_master(); oled_render_master();
} else { } else {
@ -123,4 +259,3 @@ bool oled_task_user(void) {
} }
return false; return false;
} }

View file

@ -0,0 +1,25 @@
/* KEYBOARD PET START */
/* settings */
#define MIN_WALK_SPEED 10
#define MIN_RUN_SPEED 40
/* advanced settings */
#define ANIM_FRAME_DURATION 200 // how long each frame lasts in ms
#define ANIM_SIZE 96 // number of bytes in array. If you change sprites, minimize for adequate firmware size. max is 1024
/* timers */
uint32_t anim_timer;
/* current frame */
uint8_t current_frame;
/* status variables */
int current_wpm;
led_t led_usb_state;
bool isSneaking;
bool isJumping;
bool showedJump;
/* KEYBOARD PET END */

View file

@ -1,5 +1,6 @@
#include "process_record.h" #include "process_record.h"
#include "layers.h" #include "layers.h"
#include "oled.h"
#include "features/layer_lock.h" #include "features/layer_lock.h"
#include "features/sentence_case.h" #include "features/sentence_case.h"
@ -42,7 +43,27 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
} }
return false; return false;
/* KEYBOARD PET STATUS START */
case TABCTRL:
case KC_LCTL:
case KC_RCTL:
if (record->event.pressed) {
isSneaking = true;
} else {
isSneaking = false;
}
break;
case SPC_EXT:
case KC_SPC:
if (record->tap.count && record->event.pressed) {
isJumping = true;
showedJump = false;
} else {
isJumping = false;
}
break;
/* KEYBOARD PET STATUS END */
} }
return true; return true;
}; };