diff options
Diffstat (limited to 'keyboards/jagdpietr/drakon/drakon.c')
| -rw-r--r-- | keyboards/jagdpietr/drakon/drakon.c | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/keyboards/jagdpietr/drakon/drakon.c b/keyboards/jagdpietr/drakon/drakon.c new file mode 100644 index 000000000..ca25ac317 --- /dev/null +++ b/keyboards/jagdpietr/drakon/drakon.c | |||
| @@ -0,0 +1,225 @@ | |||
| 1 | /* Copyright 2020 jagdpietr | ||
| 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 | |||
| 17 | #include "drakon.h" | ||
| 18 | |||
| 19 | char wpm_str[10]; | ||
| 20 | |||
| 21 | __attribute__((weak)) | ||
| 22 | void encoder_update_user(uint8_t index, bool clockwise) { | ||
| 23 | if (clockwise) { | ||
| 24 | tap_code(KC_VOLU); | ||
| 25 | } else { | ||
| 26 | tap_code(KC_VOLD); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | #ifdef OLED_DRIVER_ENABLE | ||
| 31 | |||
| 32 | // Defines names for use in layer keycodes and the keymap | ||
| 33 | enum Layer_names { | ||
| 34 | _Base, | ||
| 35 | _FN, | ||
| 36 | _Lyr2 | ||
| 37 | }; | ||
| 38 | |||
| 39 | __attribute__((weak)) | ||
| 40 | oled_rotation_t oled_init_user(oled_rotation_t rotation) { | ||
| 41 | return OLED_ROTATION_90; // flips the display 90 degrees if offhand | ||
| 42 | |||
| 43 | } | ||
| 44 | |||
| 45 | static void render_status(void) { | ||
| 46 | //Host Keyboard Layer Status | ||
| 47 | oled_set_cursor(0,10); | ||
| 48 | oled_write_P(PSTR("Lyr: "), false); | ||
| 49 | |||
| 50 | switch (get_highest_layer(layer_state)) { | ||
| 51 | case _Base: | ||
| 52 | oled_write_P(PSTR("Base\n"), false); | ||
| 53 | break; | ||
| 54 | case _FN: | ||
| 55 | oled_write_P(PSTR("FN\n"), false); | ||
| 56 | break; | ||
| 57 | case _Lyr2: | ||
| 58 | oled_write_P(PSTR("Lyr2\n"), false); | ||
| 59 | break; | ||
| 60 | default: | ||
| 61 | // Or use the write_ln shortcut over adding '\n' to the end of your string | ||
| 62 | oled_write_ln_P(PSTR("Undefined"), false); | ||
| 63 | } | ||
| 64 | // Host Keyboard LED Status | ||
| 65 | led_t led_state = host_keyboard_led_state(); | ||
| 66 | oled_set_cursor(0,12); | ||
| 67 | oled_write_P(led_state.caps_lock ? PSTR("CAP ") : PSTR(" "), false); | ||
| 68 | |||
| 69 | } | ||
| 70 | |||
| 71 | // WPM-responsive animation stuff here | ||
| 72 | #define IDLE_FRAMES 5 | ||
| 73 | #define IDLE_SPEED 40 // below this wpm value your animation will idle | ||
| 74 | |||
| 75 | // #define PREP_FRAMES 1 // uncomment if >1 | ||
| 76 | |||
| 77 | #define TAP_FRAMES 2 | ||
| 78 | #define TAP_SPEED 60 // above this wpm value typing animation to triggere | ||
| 79 | |||
| 80 | #define ANIM_FRAME_DURATION 200 // how long each frame lasts in ms | ||
| 81 | // #define SLEEP_TIMER 60000 // should sleep after this period of 0 wpm, needs fixing | ||
| 82 | #define ANIM_SIZE 128 // number of bytes in array, minimize for adequate firmware size, max is 1024 | ||
| 83 | |||
| 84 | uint32_t anim_timer = 0; | ||
| 85 | uint32_t anim_sleep = 0; | ||
| 86 | uint8_t current_idle_frame = 0; | ||
| 87 | // uint8_t current_prep_frame = 0; // uncomment if PREP_FRAMES >1 | ||
| 88 | uint8_t current_tap_frame = 0; | ||
| 89 | |||
| 90 | // Images credit j-inc(/James Incandenza) and pixelbenny. Credit to obosob for initial animation approach. | ||
| 91 | static void render_anim(void) { | ||
| 92 | static const char PROGMEM idle[IDLE_FRAMES][ANIM_SIZE] = { | ||
| 93 | { | ||
| 94 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0x60, 0x30, 0x18, 0x60, | ||
| 95 | 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 96 | 0x00, 0x00, 0x00, 0xc0, 0x20, 0x10, 0x0c, 0x06, 0x03, 0x81, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, | ||
| 97 | 0x00, 0x00, 0x01, 0x01, 0x03, 0x06, 0x04, 0x0c, 0x18, 0x10, 0x18, 0x08, 0xf8, 0x00, 0x00, 0x00, | ||
| 98 | 0x00, 0x3e, 0x23, 0x20, 0x20, 0x20, 0x30, 0x10, 0x10, 0x10, 0x30, 0x21, 0x21, 0x63, 0x43, 0x42, | ||
| 99 | 0xc0, 0x80, 0x88, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x73, 0xc0, 0x00, 0x00, | ||
| 100 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 101 | 0x00, 0x00, 0x05, 0x08, 0x08, 0x08, 0x08, 0x04, 0x04, 0x06, 0x04, 0x0c, 0x08, 0x0b, 0x08, 0x00 | ||
| 102 | }, | ||
| 103 | { | ||
| 104 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, | ||
| 105 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 106 | 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x30, 0x10, 0x08, 0x04, 0x04, 0x06, 0x01, 0x01, 0x06, | ||
| 107 | 0x04, 0x0c, 0x08, 0x18, 0x10, 0x30, 0x20, 0x40, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xc0, 0x00, 0x00, | ||
| 108 | 0xe0, 0x98, 0x04, 0x03, 0x01, 0x80, 0x80, 0x80, 0x80, 0x84, 0x86, 0x80, 0x08, 0x18, 0x10, 0x00, | ||
| 109 | 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x78, 0x87, 0x00, 0x00, | ||
| 110 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, | ||
| 111 | 0x02, 0x02, 0x0e, 0x3e, 0x20, 0x20, 0x20, 0x10, 0x10, 0x18, 0x18, 0x10, 0x10, 0x33, 0x3e, 0x00 | ||
| 112 | }, | ||
| 113 | { | ||
| 114 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0x60, 0x30, 0x18, 0x60, | ||
| 115 | 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 116 | 0x00, 0x00, 0x00, 0xc0, 0x20, 0x10, 0x0c, 0x06, 0x03, 0x81, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, | ||
| 117 | 0x00, 0x00, 0x01, 0x01, 0x03, 0x06, 0x04, 0x0c, 0x18, 0x10, 0x18, 0x08, 0xf8, 0x00, 0x00, 0x00, | ||
| 118 | 0x00, 0x3e, 0x23, 0x20, 0x20, 0x20, 0x30, 0x10, 0x10, 0x10, 0x30, 0x21, 0x21, 0x63, 0x43, 0x42, | ||
| 119 | 0xc0, 0x80, 0x88, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x73, 0xc0, 0x00, 0x00, | ||
| 120 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 121 | 0x00, 0x00, 0x05, 0x08, 0x08, 0x08, 0x08, 0x04, 0x04, 0x06, 0x04, 0x0c, 0x08, 0x0b, 0x08, 0x00 | ||
| 122 | }, | ||
| 123 | { | ||
| 124 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, | ||
| 125 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 126 | 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x30, 0x10, 0x08, 0x04, 0x04, 0x06, 0x01, 0x01, 0x06, | ||
| 127 | 0x04, 0x0c, 0x08, 0x18, 0x10, 0x30, 0x20, 0x40, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xc0, 0x00, 0x00, | ||
| 128 | 0xe0, 0x98, 0x04, 0x03, 0x01, 0x80, 0x80, 0x80, 0x80, 0x84, 0x86, 0x80, 0x08, 0x18, 0x10, 0x00, | ||
| 129 | 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x78, 0x87, 0x00, 0x00, | ||
| 130 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, | ||
| 131 | 0x02, 0x02, 0x0e, 0x3e, 0x20, 0x20, 0x20, 0x10, 0x10, 0x18, 0x18, 0x10, 0x10, 0x33, 0x3e, 0x00 | ||
| 132 | }, | ||
| 133 | { | ||
| 134 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0x60, 0x30, 0x18, 0x60, | ||
| 135 | 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 136 | 0x00, 0x00, 0x00, 0xc0, 0x20, 0x10, 0x0c, 0x06, 0x03, 0x81, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, | ||
| 137 | 0x00, 0x00, 0x01, 0x01, 0x03, 0x06, 0x04, 0x0c, 0x18, 0x10, 0x18, 0x08, 0xf8, 0x00, 0x00, 0x00, | ||
| 138 | 0x00, 0x3e, 0x23, 0x20, 0x20, 0x20, 0x30, 0x10, 0x10, 0x10, 0x30, 0x21, 0x21, 0x63, 0x43, 0x42, | ||
| 139 | 0xc0, 0x80, 0x88, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x73, 0xc0, 0x00, 0x00, | ||
| 140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 141 | 0x00, 0x00, 0x05, 0x08, 0x08, 0x08, 0x08, 0x04, 0x04, 0x06, 0x04, 0x0c, 0x08, 0x0b, 0x08, 0x00 | ||
| 142 | } | ||
| 143 | }; | ||
| 144 | static const char PROGMEM prep[][ANIM_SIZE] = { | ||
| 145 | { | ||
| 146 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x40, 0x30, 0x18, 0x0c, 0x38, | ||
| 147 | 0x60, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 148 | 0x00, 0xf8, 0x18, 0x0c, 0x0c, 0x38, 0x0c, 0x06, 0x03, 0x01, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, | ||
| 149 | 0x00, 0x00, 0x00, 0x01, 0x03, 0x02, 0x06, 0x04, 0x08, 0x18, 0x30, 0x18, 0x18, 0xf8, 0x00, 0x00, | ||
| 150 | 0x00, 0x07, 0x0c, 0x18, 0x18, 0x10, 0x10, 0x10, 0x20, 0x60, 0x61, 0x41, 0x42, 0xc2, 0x86, 0x84, | ||
| 151 | 0x80, 0x00, 0x00, 0x18, 0x10, 0xfc, 0x02, 0x02, 0x04, 0x1c, 0x00, 0x00, 0x3e, 0xe1, 0x00, 0x00, | ||
| 152 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, | ||
| 153 | 0x01, 0x03, 0x03, 0x02, 0x06, 0x07, 0x06, 0x0c, 0x0c, 0x0c, 0x10, 0x10, 0x30, 0x20, 0x3f, 0x00 | ||
| 154 | } | ||
| 155 | }; | ||
| 156 | static const char PROGMEM tap[TAP_FRAMES][ANIM_SIZE] = { | ||
| 157 | { | ||
| 158 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0x40, 0x30, 0x18, 0x0c, 0x38, | ||
| 159 | 0x60, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 160 | 0xfe, 0xfe, 0x80, 0xc0, 0x60, 0x18, 0x0c, 0x02, 0x01, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 161 | 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x06, 0x04, 0x08, 0x10, 0x10, 0x18, 0x08, 0xfc, 0x00, 0x00, | ||
| 162 | 0xf9, 0xff, 0xe3, 0xe0, 0xc0, 0x40, 0x60, 0x20, 0x20, 0x60, 0x41, 0x40, 0xc3, 0x82, 0x86, 0x04, | ||
| 163 | 0x00, 0x00, 0x00, 0x18, 0x18, 0xfc, 0x06, 0x06, 0x04, 0x38, 0x00, 0x00, 0x1c, 0xe7, 0x00, 0x00, | ||
| 164 | 0xf0, 0xfc, 0x03, 0x00, 0x01, 0x07, 0x7c, 0x78, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, | ||
| 165 | 0x01, 0x03, 0x02, 0x02, 0x06, 0x07, 0x04, 0x0c, 0x08, 0x08, 0x18, 0x10, 0x30, 0x21, 0x3f, 0x38 | ||
| 166 | }, | ||
| 167 | { | ||
| 168 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, 0x60, 0x30, 0x18, 0x0c, 0x38, | ||
| 169 | 0x60, 0x40, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 170 | 0xe0, 0xf8, 0x04, 0x04, 0x0c, 0x3c, 0x06, 0x03, 0x01, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 171 | 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x02, 0x06, 0x0c, 0x18, 0x98, 0x08, 0x0c, 0xfc, 0x00, 0x00, | ||
| 172 | 0x03, 0x07, 0x04, 0x0c, 0x08, 0x08, 0x18, 0x10, 0x10, 0x30, 0x20, 0x20, 0x61, 0x43, 0x43, 0xc2, | ||
| 173 | 0x80, 0x80, 0x80, 0x8c, 0x80, 0x00, 0x00, 0xe0, 0xf8, 0x7e, 0x3f, 0x1f, 0x1f, 0x7d, 0x80, 0x00, | ||
| 174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf0, 0x70, | ||
| 175 | 0x30, 0x38, 0x19, 0x0f, 0x1e, 0x1c, 0x79, 0xf8, 0xe8, 0xc4, 0x84, 0x08, 0x08, 0x18, 0x1f, 0x1c | ||
| 176 | }, | ||
| 177 | }; | ||
| 178 | |||
| 179 | //assumes 1 frame prep stage | ||
| 180 | void animation_phase(void) { | ||
| 181 | if(get_current_wpm() <=IDLE_SPEED){ | ||
| 182 | current_idle_frame = (current_idle_frame + 1) % IDLE_FRAMES; | ||
| 183 | oled_write_raw_P(idle[abs((IDLE_FRAMES-1)-current_idle_frame)], ANIM_SIZE); | ||
| 184 | } | ||
| 185 | if(get_current_wpm() >IDLE_SPEED && get_current_wpm() <TAP_SPEED){ | ||
| 186 | // oled_write_raw_P(prep[abs((PREP_FRAMES-1)-current_prep_frame)], ANIM_SIZE); // uncomment if IDLE_FRAMES >1 | ||
| 187 | oled_write_raw_P(prep[0], ANIM_SIZE); // remove if IDLE_FRAMES >1 | ||
| 188 | } | ||
| 189 | if(get_current_wpm() >=TAP_SPEED){ | ||
| 190 | current_tap_frame = (current_tap_frame + 1) % TAP_FRAMES; | ||
| 191 | oled_write_raw_P(tap[abs((TAP_FRAMES-1)-current_tap_frame)], ANIM_SIZE); | ||
| 192 | } | ||
| 193 | } | ||
| 194 | if(get_current_wpm() != 000) { | ||
| 195 | oled_on(); // not essential but turns on animation OLED with any alpha keypress | ||
| 196 | if(timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) { | ||
| 197 | anim_timer = timer_read32(); | ||
| 198 | animation_phase(); | ||
| 199 | } | ||
| 200 | anim_sleep = timer_read32(); | ||
| 201 | } else { | ||
| 202 | if(timer_elapsed32(anim_sleep) > OLED_TIMEOUT) { | ||
| 203 | oled_off(); | ||
| 204 | } else { | ||
| 205 | if(timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) { | ||
| 206 | anim_timer = timer_read32(); | ||
| 207 | animation_phase(); | ||
| 208 | } | ||
| 209 | } | ||
| 210 | } | ||
| 211 | } | ||
| 212 | __attribute__((weak)) | ||
| 213 | void oled_task_user(void) { | ||
| 214 | |||
| 215 | render_anim(); | ||
| 216 | oled_set_cursor(0,6); | ||
| 217 | sprintf(wpm_str, " WPM: %03d", get_current_wpm()); | ||
| 218 | oled_set_cursor(0,5); | ||
| 219 | oled_write(wpm_str, false); | ||
| 220 | |||
| 221 | render_status(); | ||
| 222 | |||
| 223 | } | ||
| 224 | |||
| 225 | #endif | ||
