graphics.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /* Copyright 2021 Flare576 <flare576@gmail.com>
  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. #include QMK_KEYBOARD_H
  17. #include "enums.h"
  18. #include "logos.h"
  19. int current_wpm = -1; // Enable screen-on at startup
  20. bool isJumping = false;
  21. bool showedJump = true;
  22. #ifdef OLED_DRIVER_ENABLE
  23. #ifdef MAIN_BOARD
  24. static void render_logos(void){}
  25. void luna_jump(bool newJump){
  26. isJumping = newJump;
  27. if (newJump) {
  28. showedJump = false;
  29. }
  30. }
  31. // START Luna vars
  32. #define MIN_WALK_SPEED 10
  33. #define MIN_RUN_SPEED 40
  34. #define ANIM_FRAME_DURATION 200 // how long each frame lasts in ms
  35. #define ANIM_SIZE 96 // number of bytes in array, minimize for adequate firmware size, max is 1024
  36. uint32_t anim_timer = 0;
  37. uint8_t current_frame = 0;
  38. bool isSneaking = false;
  39. static void render_luna(int LUNA_X, int LUNA_Y) {
  40. static const char PROGMEM sit[2][ANIM_SIZE] = {
  41. // 'sit1', 32x22px
  42. {
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1c,
  44. 0x02, 0x05, 0x02, 0x24, 0x04, 0x04, 0x02, 0xa9, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x68, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00,
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x82, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0c, 0x10, 0x10, 0x20, 0x20, 0x20, 0x28,
  48. 0x3e, 0x1c, 0x20, 0x20, 0x3e, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  49. },
  50. // 'sit2', 32x22px
  51. {
  52. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1c,
  53. 0x02, 0x05, 0x02, 0x24, 0x04, 0x04, 0x02, 0xa9, 0x1e, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x90, 0x08, 0x18, 0x60, 0x10, 0x08, 0x04, 0x03, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x0e, 0x82, 0x7c, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0c, 0x10, 0x10, 0x20, 0x20, 0x20, 0x28,
  57. 0x3e, 0x1c, 0x20, 0x20, 0x3e, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  58. }
  59. };
  60. static const char PROGMEM walk[2][ANIM_SIZE] = {
  61. // 'walk1', 32x22px
  62. {
  63. 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x90, 0x90, 0x90, 0xa0, 0xc0, 0x80, 0x80,
  64. 0x80, 0x70, 0x08, 0x14, 0x08, 0x90, 0x10, 0x10, 0x08, 0xa4, 0x78, 0x80, 0x00, 0x00, 0x00, 0x00,
  65. 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x08, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
  66. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0xea, 0x10, 0x0f, 0x00, 0x00, 0x00, 0x00,
  67. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x20, 0x20, 0x3c, 0x0f, 0x11, 0x1f, 0x03,
  68. 0x06, 0x18, 0x20, 0x20, 0x3c, 0x0c, 0x12, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  69. },
  70. // 'walk2', 32x22px
  71. {
  72. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x20, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00,
  73. 0x00, 0xe0, 0x10, 0x28, 0x10, 0x20, 0x20, 0x20, 0x10, 0x48, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  74. 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x20, 0xf8, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  75. 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x30, 0xd5, 0x20, 0x1f, 0x00, 0x00, 0x00, 0x00,
  76. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x30, 0x0c, 0x02, 0x05, 0x09, 0x12, 0x1e,
  77. 0x02, 0x1c, 0x14, 0x08, 0x10, 0x20, 0x2c, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  78. }
  79. };
  80. static const char PROGMEM run[2][ANIM_SIZE] = {
  81. // 'run1', 32x22px
  82. {
  83. 0x00, 0x00, 0x00, 0x00, 0xe0, 0x10, 0x08, 0x08, 0xc8, 0xb0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
  84. 0x80, 0x40, 0x40, 0x3c, 0x14, 0x04, 0x08, 0x90, 0x18, 0x04, 0x08, 0xb0, 0x40, 0x80, 0x00, 0x00,
  85. 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xc4, 0xa4, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
  86. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc8, 0x58, 0x28, 0x2a, 0x10, 0x0f, 0x00, 0x00,
  87. 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x09, 0x04, 0x04, 0x04, 0x04, 0x02, 0x03, 0x02, 0x01, 0x01,
  88. 0x02, 0x02, 0x04, 0x08, 0x10, 0x26, 0x2b, 0x32, 0x04, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
  89. },
  90. // 'run2', 32x22px
  91. {
  92. 0x00, 0x00, 0x00, 0xe0, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
  93. 0x80, 0x80, 0x78, 0x28, 0x08, 0x10, 0x20, 0x30, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00,
  94. 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x10, 0x11, 0xf9, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
  95. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0xb0, 0x50, 0x55, 0x20, 0x1f, 0x00, 0x00,
  96. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x0c, 0x10, 0x20, 0x28, 0x37,
  97. 0x02, 0x1e, 0x20, 0x20, 0x18, 0x0c, 0x14, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  98. }
  99. };
  100. static const char PROGMEM sneak[2][ANIM_SIZE] = {
  101. // 'sneak1', 32x22px
  102. {
  103. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00,
  104. 0x00, 0x00, 0xc0, 0x40, 0x40, 0x80, 0x00, 0x80, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  105. 0x00, 0x00, 0x00, 0x00, 0x1e, 0x21, 0xf0, 0x04, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x04,
  106. 0x04, 0x04, 0x03, 0x01, 0x00, 0x00, 0x09, 0x01, 0x80, 0x80, 0xab, 0x04, 0xf8, 0x00, 0x00, 0x00,
  107. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1c, 0x20, 0x20, 0x3c, 0x0f, 0x11, 0x1f, 0x02, 0x06,
  108. 0x18, 0x20, 0x20, 0x38, 0x08, 0x10, 0x18, 0x04, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00,
  109. },
  110. // 'sneak2', 32x22px
  111. {
  112. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  113. 0x00, 0x00, 0xe0, 0xa0, 0x20, 0x40, 0x80, 0xc0, 0x20, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
  114. 0x00, 0x00, 0x00, 0x00, 0x3e, 0x41, 0xf0, 0x04, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, 0x02, 0x04,
  115. 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x40, 0x55, 0x82, 0x7c, 0x00, 0x00, 0x00,
  116. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x20, 0x30, 0x0c, 0x02, 0x05, 0x09, 0x12, 0x1e, 0x04,
  117. 0x18, 0x10, 0x08, 0x10, 0x20, 0x28, 0x34, 0x06, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  118. }
  119. };
  120. // animation state
  121. void animation_phase(void) {
  122. if (isJumping || !showedJump) {
  123. // clear
  124. oled_set_cursor(LUNA_X,LUNA_Y +2);
  125. oled_write(" ", false);
  126. oled_set_cursor(LUNA_X,LUNA_Y -1);
  127. showedJump = true;
  128. } else {
  129. // clear
  130. oled_set_cursor(LUNA_X,LUNA_Y -1);
  131. oled_write(" ", false);
  132. oled_set_cursor(LUNA_X,LUNA_Y);
  133. }
  134. current_frame = (current_frame + 1) % 2;
  135. if(isSneaking) {
  136. oled_write_raw_P(sneak[current_frame], ANIM_SIZE);
  137. } else if(current_wpm <= MIN_WALK_SPEED) {
  138. oled_write_raw_P(sit[current_frame], ANIM_SIZE);
  139. } else if(current_wpm <= MIN_RUN_SPEED) {
  140. oled_write_raw_P(walk[current_frame], ANIM_SIZE);
  141. } else {
  142. oled_write_raw_P(run[current_frame], ANIM_SIZE);
  143. }
  144. }
  145. // animation timer
  146. if(timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
  147. anim_timer = timer_read32();
  148. animation_phase();
  149. }
  150. }
  151. // END Luna vars
  152. static void main_board(void) {
  153. int layer = get_highest_layer(layer_state);
  154. isSneaking = false;
  155. // Print current mode
  156. oled_write_ln_P(PSTR("Flare"), false);
  157. oled_write_ln_P(PSTR("Sofle"), false);
  158. if (layer == _FF14) {
  159. oled_write_raw_P(ffxiv, 16*8);
  160. } else if (keymap_config.swap_lalt_lgui) {
  161. oled_write_raw_P(windows, 16*8);
  162. } else {
  163. oled_write_raw_P(apple, 16*8);
  164. }
  165. oled_set_cursor(0, 9);
  166. switch (layer) {
  167. case _BASE:
  168. oled_write_ln_P(PSTR("ALL"), false);
  169. oled_write_P(PSTR(" YOUR"), false);
  170. oled_write_ln_P(PSTR("BASE"), false);
  171. break;
  172. case _MOUS:
  173. isSneaking = true;
  174. oled_write_ln_P(PSTR("Mouse"), false);
  175. break;
  176. case _SYMS:
  177. oled_write_ln_P(PSTR("@$*&#"), false);
  178. break;
  179. case _FF14:
  180. oled_write_ln_P(PSTR("FFXIV"), false);
  181. break;
  182. case _ESDF:
  183. oled_write_ln_P(PSTR("ESDF "), false);
  184. break;
  185. default:
  186. oled_write_ln_P(PSTR("Undef"), false);
  187. }
  188. if (layer != _BASE) {
  189. oled_write_P(PSTR("\n"), false);
  190. }
  191. // Don't re-write if not in use
  192. if (current_wpm > 0) {
  193. render_luna(0,13);
  194. }
  195. }
  196. // End "MAIN_BOARD"
  197. #else
  198. static void main_board(void){}
  199. static void luna_jump(bool newJump){}
  200. #define MARQUEE_FRAME_DURATION 200 // how long each frame lasts in ms
  201. #define LOGO_BYTES 128
  202. #define LOGO_COUNT 7
  203. static const char *const secondary_logos[] = { js, apple, docker, python, qmk, brew, windows };
  204. #define MARQUEE_FRAMES (LOGO_COUNT * 4)
  205. #define MARQUEE_SIZE ( LOGO_COUNT * LOGO_BYTES)
  206. #define MARQUEE_SCROLL_UP true
  207. uint32_t marquee_timer = 0;
  208. uint32_t marquee_frame = 0;
  209. static void render_logos(void) {
  210. void marquee_phase(void) {
  211. marquee_frame = (marquee_frame + 1) % MARQUEE_FRAMES;
  212. int marquee_start = MARQUEE_SIZE - (marquee_frame * 32);
  213. static char output[MARQUEE_SIZE];
  214. for (int i = 0; i < LOGO_COUNT; i++) {
  215. for (int j = 0; j < LOGO_BYTES; j++) {
  216. int pos = ( i * LOGO_BYTES + j + marquee_start ) % MARQUEE_SIZE;
  217. output[pos] = pgm_read_byte_near(secondary_logos[i] + j);
  218. }
  219. }
  220. oled_write_raw(output, MARQUEE_SIZE);
  221. }
  222. // animation timer
  223. if(timer_elapsed32(marquee_timer) > MARQUEE_FRAME_DURATION) {
  224. marquee_timer = timer_read32();
  225. marquee_phase();
  226. }
  227. }
  228. // End "MAIN_BOARD" false
  229. #endif
  230. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  231. return OLED_ROTATION_270;
  232. }
  233. void oled_task_user(void) {
  234. // Prevent blank screen on startup
  235. if (current_wpm == -1) {
  236. set_current_wpm(10);
  237. }
  238. current_wpm = get_current_wpm();
  239. if (is_keyboard_master()) {
  240. // can't gate main_board on wpm; won't get mode changes that don't trigger wpm
  241. main_board();
  242. } else if (current_wpm > 0) {
  243. render_logos();
  244. }
  245. }
  246. // End "OLED_DRIVER_ENABLE"
  247. #else
  248. static void luna_jump(bool newJump){}
  249. // End "OLED_DRIVER_ENABLE" false
  250. #endif