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.

288 lines
12 KiB

  1. /* Copyright 2020 Janos Daniel Reibl <janos.daniel.reibl@protonmail.com> @riblee
  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 "riblee.h"
  17. #include "raw_hid.h"
  18. #include <string.h>
  19. const uint8_t shift = MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT);
  20. // Tap Dance functions
  21. void dance_key_a (qk_tap_dance_state_t *state, void *user_data) {
  22. if (state->count == 1) {
  23. SEND_STRING("a");
  24. reset_tap_dance(state);
  25. } else if (state->count == 2) {
  26. if (!(keyboard_report->mods & shift)) {
  27. send_unicode_string("á");
  28. } else {
  29. send_unicode_string("Á");
  30. }
  31. reset_tap_dance(state);
  32. }
  33. }
  34. void dance_key_e (qk_tap_dance_state_t *state, void *user_data) {
  35. if (state->count == 1) {
  36. SEND_STRING("e");
  37. reset_tap_dance(state);
  38. } else if (state->count == 2) {
  39. if (!(keyboard_report->mods & shift)) {
  40. send_unicode_string("é");
  41. } else {
  42. send_unicode_string("É");
  43. }
  44. reset_tap_dance(state);
  45. }
  46. }
  47. void dance_key_i (qk_tap_dance_state_t *state, void *user_data) {
  48. if (state->count == 1) {
  49. SEND_STRING("i");
  50. reset_tap_dance(state);
  51. } else if (state->count == 2) {
  52. if (!(keyboard_report->mods & shift)) {
  53. send_unicode_string("í");
  54. } else {
  55. send_unicode_string("Í");
  56. }
  57. reset_tap_dance(state);
  58. }
  59. }
  60. void dance_key_o (qk_tap_dance_state_t *state, void *user_data) {
  61. if (state->count == 1) {
  62. SEND_STRING("o");
  63. reset_tap_dance(state);
  64. } else if (state->count == 2) {
  65. if (!(keyboard_report->mods & shift)) {
  66. send_unicode_string("ó");
  67. } else {
  68. send_unicode_string("Ó");
  69. }
  70. reset_tap_dance(state);
  71. } else if (state->count == 3) {
  72. if (!(keyboard_report->mods & shift)) {
  73. send_unicode_string("ö");
  74. } else {
  75. send_unicode_string("Ö");
  76. }
  77. reset_tap_dance(state);
  78. } else if (state->count == 4) {
  79. if (!(keyboard_report->mods & shift)) {
  80. send_unicode_string("ő");
  81. } else {
  82. send_unicode_string("Ő");
  83. }
  84. reset_tap_dance(state);
  85. }
  86. }
  87. void dance_key_u (qk_tap_dance_state_t *state, void *user_data) {
  88. if (state->count == 1) {
  89. SEND_STRING("u");
  90. reset_tap_dance(state);
  91. } else if (state->count == 2) {
  92. if (!(keyboard_report->mods & shift)) {
  93. send_unicode_string("ú");
  94. } else {
  95. send_unicode_string("Ú");
  96. }
  97. reset_tap_dance(state);
  98. } else if (state->count == 3) {
  99. if (!(keyboard_report->mods & shift)) {
  100. send_unicode_string("ü");
  101. } else {
  102. send_unicode_string("Ü");
  103. }
  104. reset_tap_dance(state);
  105. } else if (state->count == 4) {
  106. if (!(keyboard_report->mods & shift)) {
  107. send_unicode_string("ű");
  108. } else {
  109. send_unicode_string("Ű");
  110. }
  111. reset_tap_dance(state);
  112. }
  113. }
  114. layer_state_t layer_state_set_user(layer_state_t state) {
  115. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  116. }
  117. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  118. switch (keycode) {
  119. case QWERTY:
  120. if (record->event.pressed) {
  121. set_single_persistent_default_layer(_QWERTY);
  122. }
  123. return false;
  124. break;
  125. case COLEMAK:
  126. if (record->event.pressed) {
  127. set_single_persistent_default_layer(_COLEMAK);
  128. }
  129. return false;
  130. break;
  131. case DVORAK:
  132. if (record->event.pressed) {
  133. set_single_persistent_default_layer(_DVORAK);
  134. }
  135. return false;
  136. break;
  137. case WORKMAN:
  138. if (record->event.pressed) {
  139. set_single_persistent_default_layer(_WORKMAN);
  140. }
  141. return false;
  142. break;
  143. case HUNGARIAN:
  144. if (record->event.pressed) {
  145. set_single_persistent_default_layer(_HUNGARIAN);
  146. }
  147. return false;
  148. break;
  149. case BACKLIT:
  150. if (record->event.pressed) {
  151. register_code(keycode_config(KC_LGUI));
  152. #ifdef BACKLIGHT_ENABLE
  153. backlight_step();
  154. #endif
  155. } else {
  156. unregister_code(keycode_config(KC_LGUI));
  157. }
  158. return false;
  159. break;
  160. case CG_NORM:
  161. set_unicode_input_mode(UC_MAC);
  162. break;
  163. case CG_SWAP:
  164. set_unicode_input_mode(UC_LNX);
  165. break;
  166. }
  167. return true;
  168. };
  169. #ifdef OLED_ENABLE
  170. static char receive_buffer[128] = {};
  171. static uint8_t receive_buffer_length = 0;
  172. uint16_t startup_timer;
  173. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  174. startup_timer = timer_read();
  175. return rotation;
  176. }
  177. static void render_logo(void) {
  178. static const char PROGMEM raw_logo[] = {
  179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  181. 0, 0, 0, 0, 0, 96, 96, 96,240,248,255, 63, 56,255,255,248, 63, 63,248,255,255, 56, 63,255,248,240, 96, 96, 96, 0, 0, 0, 0, 0,252,254, 38, 54, 60, 8,240,152,152,248,240, 24,248,224,248,120,224,240,120, 96,248,248,248,248, 32,248,248, 24, 24,240,248,248,248,240,240,248,152,152,254,254, 0, 0, 0,254,254,152,248,240, 24,248,224,240,120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  182. 0, 0, 0, 0, 0,219,219,219,255,255,255,240,192,143,159, 63, 0, 0, 63,159,143,192,240,255,255,255,219,219,219, 0, 0, 0, 0, 0,192,225,112, 48, 48, 48,112,225,129, 1,240,240,240,193, 1, 0, 1,193,240,240,241, 1, 1,241,240,193,225,112, 48, 0, 1, 1, 1, 1,240,241, 49, 49, 49, 0,240,240, 0,129,193,129,193,192, 0,196,135,193,192,128,128,192,192,128, 0, 0,192,128, 0,128,192,128, 0, 0,192,192,128,128,192,192,192,128, 0,128,192,128,192,192, 0,128,192,192,192,128, 0, 0, 0, 0, 0, 0,
  183. 0, 0, 0, 0, 0, 6, 6, 6, 15, 31,255,255, 31,255,255, 31,252,252, 31,255,255, 31,255,255, 31, 15, 6, 6, 6, 0, 0, 0, 0, 0, 15, 31, 56, 48, 48, 48, 60,127,103, 96, 63, 63, 0, 7, 63, 56, 31, 7, 0, 63, 63, 0, 0, 63, 63, 7, 30, 60, 48, 0, 0, 0, 0, 0, 63, 31, 3, 3, 3, 0, 63, 63, 0, 31, 63, 1, 0, 0, 0, 63, 31, 0, 1, 63, 63, 0, 0, 63, 63, 0, 7, 63, 60, 63, 7, 31, 60, 63, 15, 0, 28, 60, 54, 54, 63, 63, 0, 63, 63, 1, 0, 0, 31, 63, 54, 54, 55, 55, 2, 0, 0, 0, 0, 0,
  184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,128,128,128,128,128,128, 0, 0,192,192,192, 0,192,192,192, 0, 0, 0, 0, 0, 0,192,192,192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255,255,255, 29,127,255,247,224, 0,254,254,254, 0,255,255,255,198,254,254,254, 0, 0,255,255,255,124,254,254,214,214,222,222, 92,124,254,254,214,214,222,222, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  187. };
  188. oled_write_raw_P(raw_logo, sizeof(raw_logo));
  189. }
  190. static void render_info(void) {
  191. // Keyboard Layer Status
  192. oled_write_P(PSTR("Layer: "), false);
  193. switch (get_highest_layer(layer_state)) {
  194. case _QWERTY:
  195. if (layer_state_cmp(default_layer_state, _QWERTY)) {
  196. oled_write_P(PSTR("Qwerty\n"), false);
  197. } else if (layer_state_cmp(default_layer_state, _COLEMAK)) {
  198. oled_write_P(PSTR("Colmak\n"), false);
  199. } else if (layer_state_cmp(default_layer_state, _DVORAK)) {
  200. oled_write_P(PSTR("Dvorak\n"), false);
  201. } else if (layer_state_cmp(default_layer_state, _WORKMAN)) {
  202. oled_write_P(PSTR("Workman\n"), false);
  203. } else if (layer_state_cmp(default_layer_state, _HUNGARIAN)) {
  204. oled_write_P(PSTR("HUN Qwerty\n"), false);
  205. } else {
  206. oled_write_P(PSTR("Undefined\n"), false);
  207. }
  208. break;
  209. case _LOWER:
  210. oled_write_P(PSTR("Lower\n"), false);
  211. break;
  212. case _RAISE:
  213. oled_write_P(PSTR("Raise\n"), false);
  214. break;
  215. case _ADJUST:
  216. oled_write_P(PSTR("Adjust\n"), false);
  217. break;
  218. default:
  219. oled_write_P(PSTR("Undefined\n"), false);
  220. }
  221. // Print string received via HID RAW
  222. oled_write_ln(receive_buffer, false);
  223. }
  224. void oled_task_user(void) {
  225. static bool finished_timer = false;
  226. if (!finished_timer && (timer_elapsed(startup_timer) < 1000)) {
  227. render_logo();
  228. } else {
  229. if (!finished_timer) {
  230. oled_clear();
  231. finished_timer = true;
  232. }
  233. render_info();
  234. }
  235. }
  236. #ifdef RAW_ENABLE
  237. void raw_hid_receive(uint8_t *data, uint8_t length) {
  238. // Append data to receive_buffer, without the first byte
  239. memcpy(receive_buffer + receive_buffer_length, data + 1, length - 1);
  240. receive_buffer_length += (length - 1);
  241. // First byte indicate if we will recive more package for the current string
  242. // If it's 1 then this was the last package and we can reset the offset
  243. if (data[0] == 1) {
  244. // Reset the offset for memcpy to the begining of our buffer
  245. receive_buffer_length = 0;
  246. }
  247. // Reset the offset to prevent overwriting memory outside of the buffer
  248. if (receive_buffer_length + 32 >= 128) {
  249. receive_buffer_length = 0;
  250. }
  251. }
  252. #endif
  253. #endif