diff options
Diffstat (limited to 'users/bcat/bcat_oled_pet_luna.c')
| -rw-r--r-- | users/bcat/bcat_oled_pet_luna.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/users/bcat/bcat_oled_pet_luna.c b/users/bcat/bcat_oled_pet_luna.c new file mode 100644 index 000000000..f0397c9c0 --- /dev/null +++ b/users/bcat/bcat_oled_pet_luna.c | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | /* Copyright 2021 HellSingCoder | ||
| 2 | * Copyright 2021 Jonathan Rascher | ||
| 3 | * | ||
| 4 | * This program is free software: you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation, either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* OLED pet "Luna" (animated doggo) originally by HellSingCoder | ||
| 19 | * (https://www.simonepellegrino.com/) and licensed under GPL v2.0, adapted to | ||
| 20 | * fit the OLED pet framework in bcat's userspace. | ||
| 21 | * | ||
| 22 | * The animation is 32x24 pixels (3 lines tall). | ||
| 23 | * | ||
| 24 | * Walks or runs in response to typing speed. Sneaks when Ctrl is pressed and | ||
| 25 | * barks when Caps Lock is on. Jumps when space is pressed. | ||
| 26 | * | ||
| 27 | * Original source: | ||
| 28 | * https://github.com/qmk/qmk_firmware/blob/6dfe915e26d7147e6c2bed495d3b01cf5b21e6ec/keyboards/sofle/keymaps/helltm/keymap.c | ||
| 29 | */ | ||
| 30 | |||
| 31 | #include "bcat_oled_pet.h" | ||
| 32 | |||
| 33 | #include <stdbool.h> | ||
| 34 | #include <stdint.h> | ||
| 35 | |||
| 36 | #include "bcat_oled.h" | ||
| 37 | #include "keycode.h" | ||
| 38 | #include "progmem.h" | ||
| 39 | |||
| 40 | enum image { | ||
| 41 | IMAGE_IDLE, | ||
| 42 | IMAGE_WALK, | ||
| 43 | IMAGE_RUN, | ||
| 44 | IMAGE_SNEAK, | ||
| 45 | IMAGE_BARK, | ||
| 46 | }; | ||
| 47 | |||
| 48 | typedef union { | ||
| 49 | oled_pet_state_t raw; | ||
| 50 | struct { | ||
| 51 | uint8_t image; | ||
| 52 | uint8_t frame; | ||
| 53 | }; | ||
| 54 | } luna_state_t; | ||
| 55 | |||
| 56 | #define NUM_FRAMES 2 | ||
| 57 | #define FRAME_BYTES 96 /* (32 pixel) * (24 pixel) / (8 pixel/byte) */ | ||
| 58 | |||
| 59 | uint16_t oled_pet_frame_bytes(void) { return FRAME_BYTES; } | ||
| 60 | uint8_t oled_pet_frame_lines(void) { return 3 /* (24 pixel) / (8 pixel/line) */; } | ||
| 61 | bool oled_pet_can_jump(void) { return true; } | ||
| 62 | |||
| 63 | uint16_t oled_pet_update_millis(const oled_keyboard_state_t *keyboard_state) { return 200; } | ||
| 64 | |||
| 65 | oled_pet_state_t oled_pet_next_state(oled_pet_state_t state, const oled_keyboard_state_t *keyboard_state) { | ||
| 66 | luna_state_t luna_state = {.raw = state}; | ||
| 67 | if (keyboard_state->leds.caps_lock) { | ||
| 68 | luna_state.image = IMAGE_BARK; | ||
| 69 | } else if (keyboard_state->mods & MOD_MASK_CTRL) { | ||
| 70 | luna_state.image = IMAGE_SNEAK; | ||
| 71 | } else if (keyboard_state->wpm >= 100) { | ||
| 72 | luna_state.image = IMAGE_RUN; | ||
| 73 | } else if (keyboard_state->wpm >= 25) { | ||
| 74 | luna_state.image = IMAGE_WALK; | ||
| 75 | } else { | ||
| 76 | luna_state.image = IMAGE_IDLE; | ||
| 77 | } | ||
| 78 | luna_state.frame = (luna_state.frame + 1) % NUM_FRAMES; | ||
| 79 | return luna_state.raw; | ||
| 80 | } | ||
| 81 | |||
| 82 | void oled_pet_post_render(uint8_t col, uint8_t line, const oled_keyboard_state_t *keyboard_state, bool redraw) {} | ||
| 83 | |||
| 84 | const char *oled_pet_frame(oled_pet_state_t state) { | ||
| 85 | static const char PROGMEM IDLE_FRAMES[NUM_FRAMES][FRAME_BYTES] = { | ||
| 86 | // clang-format off | ||
| 87 | { | ||
| 88 | 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, | ||
| 89 | 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, | ||
| 90 | 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, | ||
| 91 | }, | ||
| 92 | { | ||
| 93 | 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, | ||
| 94 | 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, | ||
| 95 | 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, | ||
| 96 | }, | ||
| 97 | // clang-format on | ||
| 98 | }; | ||
| 99 | static const char PROGMEM WALK_FRAMES[NUM_FRAMES][FRAME_BYTES] = { | ||
| 100 | // clang-format off | ||
| 101 | { | ||
| 102 | 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, | ||
| 103 | 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, | ||
| 104 | 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, | ||
| 105 | }, | ||
| 106 | { | ||
| 107 | 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, | ||
| 108 | 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, | ||
| 109 | 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, | ||
| 110 | }, | ||
| 111 | // clang-format on | ||
| 112 | }; | ||
| 113 | static const char PROGMEM RUN_FRAMES[NUM_FRAMES][FRAME_BYTES] = { | ||
| 114 | // clang-format off | ||
| 115 | { | ||
| 116 | 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, | ||
| 117 | 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, | ||
| 118 | 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, | ||
| 119 | }, | ||
| 120 | { | ||
| 121 | 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, | ||
| 122 | 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, | ||
| 123 | 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, | ||
| 124 | }, | ||
| 125 | // clang-format on | ||
| 126 | }; | ||
| 127 | static const char PROGMEM SNEAK_FRAMES[NUM_FRAMES][FRAME_BYTES] = { | ||
| 128 | // clang-format off | ||
| 129 | { | ||
| 130 | 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, | ||
| 131 | 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, | ||
| 132 | 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, | ||
| 133 | }, | ||
| 134 | { | ||
| 135 | 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, | ||
| 136 | 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, | ||
| 137 | 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, | ||
| 138 | }, | ||
| 139 | // clang-format on | ||
| 140 | }; | ||
| 141 | static const char PROGMEM BARK_FRAMES[NUM_FRAMES][FRAME_BYTES] = { | ||
| 142 | // clang-format off | ||
| 143 | { | ||
| 144 | 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, | ||
| 145 | 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, | ||
| 146 | 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, | ||
| 147 | }, | ||
| 148 | { | ||
| 149 | 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, | ||
| 150 | 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, | ||
| 151 | 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, | ||
| 152 | }, | ||
| 153 | // clang-format on | ||
| 154 | }; | ||
| 155 | luna_state_t luna_state = {.raw = state}; | ||
| 156 | switch (luna_state.image) { | ||
| 157 | case IMAGE_WALK: | ||
| 158 | return WALK_FRAMES[luna_state.frame]; | ||
| 159 | case IMAGE_RUN: | ||
| 160 | return RUN_FRAMES[luna_state.frame]; | ||
| 161 | case IMAGE_SNEAK: | ||
| 162 | return SNEAK_FRAMES[luna_state.frame]; | ||
| 163 | case IMAGE_BARK: | ||
| 164 | return BARK_FRAMES[luna_state.frame]; | ||
| 165 | default: | ||
| 166 | return IDLE_FRAMES[luna_state.frame]; | ||
| 167 | } | ||
| 168 | } | ||
