diff options
| author | QMK Bot <hello@qmk.fm> | 2021-06-24 02:22:11 +0000 |
|---|---|---|
| committer | QMK Bot <hello@qmk.fm> | 2021-06-24 02:22:11 +0000 |
| commit | b69fa51ec39d2825067b11f065ff8e59e41d8dc9 (patch) | |
| tree | c36f3c63b8472a1f5b951cc9e2e5a03df1532fee /users/snowe/luna.c | |
| parent | 1ea01765e19bf84b9a09954443b7d64be2bec0c7 (diff) | |
| parent | 909d9c228fb03750170aa7ca49ea10d08a6e1113 (diff) | |
| download | qmk_firmware-b69fa51ec39d2825067b11f065ff8e59e41d8dc9.tar.gz qmk_firmware-b69fa51ec39d2825067b11f065ff8e59e41d8dc9.zip | |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'users/snowe/luna.c')
| -rw-r--r-- | users/snowe/luna.c | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/users/snowe/luna.c b/users/snowe/luna.c new file mode 100644 index 000000000..4653abfae --- /dev/null +++ b/users/snowe/luna.c | |||
| @@ -0,0 +1,229 @@ | |||
| 1 | /* | ||
| 2 | * Copyright 2021 QMK Community | ||
| 3 | * Copyright 2021 Tyler Thrailkill (@snowe/@snowe2010) <tyler.b.thrailkill@gmail.com> | ||
| 4 | * | ||
| 5 | * This program is free software: you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation, either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "quantum.h" | ||
| 20 | #include "luna.h" | ||
| 21 | |||
| 22 | // KEYBOARD PET START | ||
| 23 | |||
| 24 | // settings | ||
| 25 | #define MIN_WALK_SPEED 10 | ||
| 26 | #define MIN_RUN_SPEED 40 | ||
| 27 | |||
| 28 | // advanced settings | ||
| 29 | #define ANIM_FRAME_DURATION 200 // how long each frame lasts in ms | ||
| 30 | #define ANIM_SIZE 96 // number of bytes in array. If you change sprites, minimize for adequate firmware size. max is 1024 | ||
| 31 | |||
| 32 | bool isSneaking = false; | ||
| 33 | bool isJumping = false; | ||
| 34 | bool showedJump = true; | ||
| 35 | |||
| 36 | // status variables | ||
| 37 | int current_wpm = 0; | ||
| 38 | led_t led_usb_state = { | ||
| 39 | .num_lock = false, | ||
| 40 | .caps_lock = false, | ||
| 41 | .scroll_lock = false | ||
| 42 | }; | ||
| 43 | |||
| 44 | // current frame | ||
| 45 | uint8_t current_frame = 0; | ||
| 46 | |||
| 47 | // timers | ||
| 48 | uint32_t anim_timer = 0; | ||
| 49 | uint32_t anim_sleep = 0; | ||
| 50 | |||
| 51 | // logic | ||
| 52 | void render_luna(int LUNA_X, int LUNA_Y) { | ||
| 53 | |||
| 54 | // Sit | ||
| 55 | static const char PROGMEM sit[2][ANIM_SIZE] = { | ||
| 56 | // 'sit1', 32x22px | ||
| 57 | { | ||
| 58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1c, | ||
| 59 | 0x02, 0x05, 0x02, 0x24, 0x04, 0x04, 0x02, 0xa9, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x68, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00, | ||
| 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x82, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0c, 0x10, 0x10, 0x20, 0x20, 0x20, 0x28, | ||
| 63 | 0x3e, 0x1c, 0x20, 0x20, 0x3e, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 64 | }, | ||
| 65 | |||
| 66 | // 'sit2', 32x22px | ||
| 67 | { | ||
| 68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1c, | ||
| 69 | 0x02, 0x05, 0x02, 0x24, 0x04, 0x04, 0x02, 0xa9, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 70 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x90, 0x08, 0x18, 0x60, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00, | ||
| 71 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0e, 0x82, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 72 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0c, 0x10, 0x10, 0x20, 0x20, 0x20, 0x28, | ||
| 73 | 0x3e, 0x1c, 0x20, 0x20, 0x3e, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
| 74 | } | ||
| 75 | }; | ||
| 76 | |||
| 77 | // Walk | ||
| 78 | static const char PROGMEM walk[2][ANIM_SIZE] = { | ||
| 79 | // 'walk1', 32x22px | ||
| 80 | { | ||
| 81 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x90, 0x90, 0x90, 0xa0, 0xc0, 0x80, 0x80, | ||
| 82 | 0x80, 0x70, 0x08, 0x14, 0x08, 0x90, 0x10, 0x10, 0x08, 0xa4, 0x78, 0x80, 0x00, 0x00, 0x00, 0x00, | ||
| 83 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x08, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, | ||
| 84 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0xea, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, | ||
| 85 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x20, 0x20, 0x3c, 0x0f, 0x11, 0x1f, 0x03, | ||
| 86 | 0x06, 0x18, 0x20, 0x20, 0x3c, 0x0c, 0x12, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 87 | }, | ||
| 88 | |||
| 89 | // 'walk2', 32x22px | ||
| 90 | { | ||
| 91 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x20, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, | ||
| 92 | 0x00, 0xe0, 0x10, 0x28, 0x10, 0x20, 0x20, 0x20, 0x10, 0x48, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 93 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x20, 0xf8, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, | ||
| 94 | 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x30, 0xd5, 0x20, 0x1f, 0x00, 0x00, 0x00, 0x00, | ||
| 95 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x30, 0x0c, 0x02, 0x05, 0x09, 0x12, 0x1e, | ||
| 96 | 0x02, 0x1c, 0x14, 0x08, 0x10, 0x20, 0x2c, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 97 | } | ||
| 98 | }; | ||
| 99 | |||
| 100 | // Run | ||
| 101 | static const char PROGMEM run[2][ANIM_SIZE] = { | ||
| 102 | // 'run1', 32x22px | ||
| 103 | { | ||
| 104 | 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x08, 0xc8, 0xb0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, | ||
| 105 | 0x80, 0x40, 0x40, 0x3c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, | ||
| 106 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xc4, 0xa4, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, | ||
| 107 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc8, 0x58, 0x28, 0x2a, 0x10, 0x0f, 0x00, 0x00, | ||
| 108 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x09, 0x04, 0x04, 0x04, 0x04, 0x02, 0x03, 0x02, 0x01, 0x01, | ||
| 109 | 0x02, 0x02, 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 110 | }, | ||
| 111 | |||
| 112 | // 'run2', 32x22px | ||
| 113 | { | ||
| 114 | 0x00, 0x00, 0x00, 0xe0, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, | ||
| 115 | 0x80, 0x80, 0x78, 0x28, 0x08, 0x10, 0x20, 0x30, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, | ||
| 116 | 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, | ||
| 117 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0xb0, 0x50, 0x55, 0x20, 0x1f, 0x00, 0x00, | ||
| 118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, | ||
| 119 | 0x02, 0x1e, 0x20, 0x20, 0x18, 0x0c, 0x14, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 120 | } | ||
| 121 | }; | ||
| 122 | |||
| 123 | // Bark | ||
| 124 | static const char PROGMEM bark[2][ANIM_SIZE] = { | ||
| 125 | // 'bark1', 32x22px | ||
| 126 | { | ||
| 127 | 0x00, 0xc0, 0x20, 0x10, 0xd0, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, | ||
| 128 | 0x3c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 129 | 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, | ||
| 130 | 0x00, 0x00, 0x00, 0x00, 0x80, 0xc8, 0x48, 0x28, 0x2a, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 131 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, 0x02, 0x02, | ||
| 132 | 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 133 | }, | ||
| 134 | |||
| 135 | // 'bark2', 32x22px | ||
| 136 | { | ||
| 137 | 0x00, 0xe0, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, | ||
| 138 | 0x40, 0x2c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, | ||
| 139 | 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, | ||
| 140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x48, 0x28, 0x2a, 0x10, 0x0f, 0x20, 0x4a, 0x09, 0x10, | ||
| 141 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37, 0x02, 0x02, | ||
| 142 | 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 143 | } | ||
| 144 | }; | ||
| 145 | |||
| 146 | // Sneak | ||
| 147 | static const char PROGMEM sneak[2][ANIM_SIZE] = { | ||
| 148 | // 'sneak1', 32x22px | ||
| 149 | { | ||
| 150 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, | ||
| 151 | 0x00, 0x00, 0xc0, 0x40, 0x40, 0x80, 0x00, 0x80, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 152 | 0x00, 0x00, 0x00, 0x00, 0x1e, 0x21, 0xf0, 0x04, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x04, | ||
| 153 | 0x04, 0x04, 0x03, 0x01, 0x00, 0x00, 0x09, 0x01, 0x80, 0x80, 0xab, 0x04, 0xf8, 0x00, 0x00, 0x00, | ||
| 154 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x20, 0x20, 0x3c, 0x0f, 0x11, 0x1f, 0x02, 0x06, | ||
| 155 | 0x18, 0x20, 0x20, 0x38, 0x08, 0x10, 0x18, 0x04, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, | ||
| 156 | }, | ||
| 157 | |||
| 158 | // 'sneak2', 32x22px | ||
| 159 | { | ||
| 160 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 161 | 0x00, 0x00, 0xe0, 0xa0, 0x20, 0x40, 0x80, 0xc0, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 162 | 0x00, 0x00, 0x00, 0x00, 0x3e, 0x41, 0xf0, 0x04, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04, | ||
| 163 | 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x40, 0x55, 0x82, 0x7c, 0x00, 0x00, 0x00, | ||
| 164 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x30, 0x0c, 0x02, 0x05, 0x09, 0x12, 0x1e, 0x04, | ||
| 165 | 0x18, 0x10, 0x08, 0x10, 0x20, 0x28, 0x34, 0x06, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 166 | } | ||
| 167 | }; | ||
| 168 | |||
| 169 | // animation | ||
| 170 | void animation_phase(void) { | ||
| 171 | |||
| 172 | // jump | ||
| 173 | if (isJumping || !showedJump) { | ||
| 174 | |||
| 175 | // clear | ||
| 176 | oled_set_cursor(LUNA_X,LUNA_Y +2); | ||
| 177 | oled_write(" ", false); | ||
| 178 | |||
| 179 | oled_set_cursor(LUNA_X,LUNA_Y -1); | ||
| 180 | |||
| 181 | showedJump = true; | ||
| 182 | } else { | ||
| 183 | |||
| 184 | // clear | ||
| 185 | oled_set_cursor(LUNA_X,LUNA_Y -1); | ||
| 186 | oled_write(" ", false); | ||
| 187 | |||
| 188 | oled_set_cursor(LUNA_X,LUNA_Y); | ||
| 189 | } | ||
| 190 | |||
| 191 | // switch frame | ||
| 192 | current_frame = (current_frame + 1) % 2; | ||
| 193 | |||
| 194 | // current status | ||
| 195 | if(led_usb_state.caps_lock) { | ||
| 196 | oled_write_raw_P(bark[abs(1 - current_frame)], ANIM_SIZE); | ||
| 197 | |||
| 198 | } else if(isSneaking) { | ||
| 199 | oled_write_raw_P(sneak[abs(1 - current_frame)], ANIM_SIZE); | ||
| 200 | |||
| 201 | } else if(current_wpm <= MIN_WALK_SPEED) { | ||
| 202 | oled_write_raw_P(sit[abs(1 - current_frame)], ANIM_SIZE); | ||
| 203 | |||
| 204 | } else if(current_wpm <= MIN_RUN_SPEED) { | ||
| 205 | oled_write_raw_P(walk[abs(1 - current_frame)], ANIM_SIZE); | ||
| 206 | |||
| 207 | } else { | ||
| 208 | oled_write_raw_P(run[abs(1 - current_frame)], ANIM_SIZE); | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | // animation timer | ||
| 213 | if(timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) { | ||
| 214 | anim_timer = timer_read32(); | ||
| 215 | current_wpm = get_current_wpm(); | ||
| 216 | animation_phase(); | ||
| 217 | } | ||
| 218 | |||
| 219 | // this fixes the screen on and off bug | ||
| 220 | if (current_wpm > 0) { | ||
| 221 | oled_on(); | ||
| 222 | anim_sleep = timer_read32(); | ||
| 223 | } else if(timer_elapsed32(anim_sleep) > OLED_TIMEOUT) { | ||
| 224 | oled_off(); | ||
| 225 | } | ||
| 226 | |||
| 227 | } | ||
| 228 | |||
| 229 | // KEYBOARD PET END \ No newline at end of file | ||
