You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
9.9 KiB

  1. // Copyright 2021 Nicolas Druoton (druotoni)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include QMK_KEYBOARD_H
  4. #include "keymap_french.h"
  5. #include "transactions.h"
  6. // global
  7. #include "gui_state.h"
  8. #include "boot.h"
  9. #include "navi_logo.h"
  10. #include "draw_helper.h"
  11. #include "fast_random.h"
  12. // left side
  13. #include "layer_frame.h"
  14. #include "burst.h"
  15. // right side
  16. #include "ring.h"
  17. // clang-format off
  18. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  19. /* QWERTY
  20. * ,-----------------------------------------. ,-----------------------------------------.
  21. * | ESC | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | DEL |
  22. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  23. * | Tab | Q | W | E | R | T | | Y | U | I | O | P | ^ |
  24. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  25. * |LShift| A | S | D | F | G |-------. ,-------| H | J | K | L | ; |RShift|
  26. * |------+------+------+------+------+------| " | | ) |------+------+------+------+------+------|
  27. * |LCTRL | Z | X | C | V | B |-------| |-------| N | M | , | . | / | $ |
  28. * `-----------------------------------------/ / \ \-----------------------------------------'
  29. * | LAlt | SPE | Space| / NAV / \Enter \ |BackSP| ] | RGUI |
  30. * | | | |/ / \ \ | | | |
  31. * `----------------------------' '------''--------------------'
  32. */
  33. [_QWERTY] = LAYOUT(
  34. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DELETE,
  35. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, FR_CIRC,
  36. KC_LSFT, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_RSFT,
  37. KC_LCTRL, KC_Z, KC_X, KC_C, KC_V, KC_B, S(KC_Z), FR_RPRN, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_QUOT,
  38. KC_LALT, TT(_RAISE), KC_SPC, TT(_LOWER), KC_ENT, KC_BSPC, KC_RBRC, KC_RGUI
  39. ),
  40. /* LOWER
  41. * ,---------------------------------------------. ,------------------------------------------------.
  42. * | ESC | F1 | F2 | F3 | F4 | F5 | | F6 | F7 | F8 | F9 | F10 | DEL |
  43. * |------+-------+-------+------+-------+-------| |--------+--------+--------+-------+------+------|
  44. * | RST | F11 | F12 | DEL | paste | copy | | home | pg up | print | redo | w | |
  45. * |------+-------+-------+------+-------+-------| |--------+--------+--------+-------+------+------|
  46. * | | all | | SAV | undo | BackSP|-------. ,-------| left | down | up | right | | |
  47. * |------+-------+-------+------+-------+-------| enter| | |--------+--------+--------+-------+------+------|
  48. * | F9 | F11 | F10 | F5 | TAB | cut |-------| |-------| end | pg dw | | | | |
  49. * `---------------------------------------------/ / \ \-----------------------------------------------'
  50. * | | SPE | | / / \ \ | | MENU | |
  51. * | | | |/ / \ \ | | | |
  52. * `--------------------------------' '-------''--------------------'
  53. */
  54. [_LOWER] = LAYOUT(
  55. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_DELETE,
  56. RESET, KC_F11, KC_F12, KC_DELETE, RCTL(FR_V), RCTL(FR_C), KC_HOME, KC_PGUP, KC_PSCR, RCTL(FR_Y), RCTL(KC_RIGHT), _______,
  57. _______,RCTL(FR_A), _______,RCTL(FR_S), RCTL(FR_Z), KC_BSPC, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, _______, _______,
  58. KC_F9, KC_F11, KC_F10, KC_F5, LALT(KC_TAB), RCTL(FR_X), KC_ENT, _______, KC_END, KC_PGDN, _______, _______, _______, _______,
  59. _______,TT(_RAISE), _______, _______, _______, _______, KC_APP, _______),
  60. /* RAISE
  61. * ,-----------------------------------------. ,-------------------------------------------.
  62. * | | | | | | | | | | / | * | - | RGB TOG|
  63. * |------+------+------+------+------+------| |------+------+------+------+-----+--------|
  64. * | ` | [ | ] | | | | | ^ | 7 | 8 | 9 | + | RGB HUI|
  65. * |------+------+------+------+------+------| |------+------+------+------+-----+--------|
  66. * | | @ | | | & | | # |-------. ,-------| $ | 4 | 5 | 6 | | |
  67. * |------+------+------+------+------+------| | | |------+------+------+------+-----+--------|
  68. * | F7 | F8 | F9 | F10 | # | F12 |-------| |-------| | 1 | 2 | 3 | | |
  69. * `-----------------------------------------/ / \ \------------------------------------------'
  70. * | | | | / / \ \ | | 0 | . |
  71. * | | | |/ / \ \ | | | |
  72. * `----------------------------' '------''---------------------'
  73. */
  74. [_RAISE] = LAYOUT(
  75. _______, _______, _______, _______, _______, _______, _______, _______, KC_PSLS, KC_PAST, KC_PMNS, RGB_TOG,
  76. KC_GRV, FR_LBRC, FR_RBRC, _______, _______, _______, FR_EQL, KC_KP_7, KC_KP_8, KC_KP_9, KC_PPLS, RGB_HUI,
  77. _______, FR_AT, FR_PIPE, ALGR(KC_1), FR_EURO, FR_HASH, S(FR_EQL), KC_KP_4, KC_KP_5, KC_KP_6, _______, _______,
  78. KC_F7, KC_F8, KC_F9, KC_F10, FR_HASH, KC_F12, _______, _______, _______, KC_KP_1, KC_KP_2, KC_KP_3, _______, _______,
  79. _______, _______, _______, _______, _______, _______, KC_KP_0, KC_KP_DOT)
  80. };
  81. // clang-format on
  82. // sync transport
  83. typedef struct _sync_keycode_t {
  84. uint16_t keycode;
  85. } sync_keycode_t;
  86. // force rigth side to update
  87. bool b_sync_need_send = false;
  88. // last keycode typed
  89. sync_keycode_t last_keycode;
  90. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  91. // vertical orientation
  92. return OLED_ROTATION_270;
  93. }
  94. void render(gui_state_t t) {
  95. // logo
  96. render_logo(t);
  97. #if IS_LEFT
  98. // left side
  99. render_layer_frame(t);
  100. render_gears();
  101. decay_scope();
  102. render_scope(t);
  103. #endif
  104. #if IS_RIGHT
  105. // right side
  106. render_circle(t);
  107. #endif
  108. }
  109. void update(uint16_t keycode) {
  110. #if IS_LEFT
  111. update_scope();
  112. #endif
  113. #if IS_RIGHT
  114. update_circle(keycode);
  115. #endif
  116. }
  117. void reset(void) {
  118. #if IS_LEFT
  119. reset_scope();
  120. #endif
  121. #if IS_RIGHT
  122. reset_ring();
  123. #endif
  124. }
  125. void set_wackingup_mode_clean(void) {
  126. oled_clear();
  127. reset();
  128. }
  129. bool oled_task_user(void) {
  130. gui_state_t t = get_gui_state();
  131. // in sleep mode => turn display off
  132. if (t == _SLEEP) {
  133. oled_off();
  134. return false;
  135. }
  136. // not in sleep mode => screen is on
  137. oled_on();
  138. #ifdef WITH_BOOT
  139. // in booting mode => display booting animation
  140. if (t == _BOOTING) {
  141. bool boot_finished = render_boot();
  142. if (boot_finished) {
  143. // end of the boot : wacking up
  144. set_wackingup_mode_clean();
  145. update_gui_state();
  146. }
  147. return false;
  148. }
  149. #endif
  150. // in halting mode => display booting animation
  151. if (t == _HALTING) {
  152. render_halt();
  153. return false;
  154. }
  155. render(t);
  156. return false;
  157. }
  158. void process_key(uint16_t keycode) {
  159. // update screen with the new key
  160. update(keycode);
  161. gui_state_t t = get_gui_state();
  162. if (t == _IDLE) {
  163. // wake up animation
  164. reset();
  165. }
  166. if (t == _BOOTING || t == _HALTING) {
  167. // cancel booting or halting : waking_up
  168. set_wackingup_mode_clean();
  169. }
  170. if (t == _SLEEP) {
  171. // boot sequence
  172. set_wackingup_mode_clean();
  173. reset_boot();
  174. }
  175. update_gui_state();
  176. }
  177. void user_sync_a_slave_handler(uint8_t in_buflen, const void* in_data, uint8_t out_buflen, void* out_data) {
  178. const sync_keycode_t* m2s = (const sync_keycode_t*)in_data;
  179. // get the last char typed on left side and update the right side
  180. process_key(m2s->keycode);
  181. }
  182. void keyboard_post_init_user(void) {
  183. // callback for tranport sync data
  184. transaction_register_rpc(USER_SYNC_A, user_sync_a_slave_handler);
  185. }
  186. void housekeeping_task_user(void) {
  187. // only for master side
  188. if (!is_keyboard_master()) return;
  189. // only if a new char was typed
  190. if (!b_sync_need_send) return;
  191. // send the char to the slave side : sync is done
  192. if (transaction_rpc_send(USER_SYNC_A, sizeof(last_keycode), &last_keycode)) {
  193. b_sync_need_send = false;
  194. }
  195. }
  196. bool process_record_user(uint16_t keycode, keyrecord_t* record) {
  197. if (record->event.pressed) {
  198. // master : store keycode to sent to the other side to be process_key
  199. last_keycode.keycode = keycode;
  200. b_sync_need_send = true;
  201. // gui process the input
  202. process_key(keycode);
  203. }
  204. return true;
  205. }
  206. #if IS_LEFT
  207. layer_state_t layer_state_set_user(layer_state_t state) {
  208. // update the frame with the layer name
  209. update_layer_frame(state);
  210. return state;
  211. }
  212. #endif