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.

248 lines
7.2 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. }
  161. return true;
  162. };
  163. #ifdef OLED_ENABLE
  164. static char receive_buffer[128] = {};
  165. static uint8_t receive_buffer_length = 0;
  166. void oled_task_user(void) {
  167. // Keyboard Layer Status
  168. oled_write_P(PSTR("Layer: "), false);
  169. switch (get_highest_layer(layer_state)) {
  170. case _QWERTY:
  171. if (layer_state_cmp(default_layer_state, _QWERTY)) {
  172. oled_write_P(PSTR("Qwerty\n"), false);
  173. } else if (layer_state_cmp(default_layer_state, _COLEMAK)) {
  174. oled_write_P(PSTR("Colmak\n"), false);
  175. } else if (layer_state_cmp(default_layer_state, _DVORAK)) {
  176. oled_write_P(PSTR("Dvorak\n"), false);
  177. } else if (layer_state_cmp(default_layer_state, _WORKMAN)) {
  178. oled_write_P(PSTR("Workman\n"), false);
  179. } else if (layer_state_cmp(default_layer_state, _HUNGARIAN)) {
  180. oled_write_P(PSTR("HUN Qwerty\n"), false);
  181. } else {
  182. oled_write_P(PSTR("Undefined\n"), false);
  183. }
  184. break;
  185. case _LOWER:
  186. oled_write_P(PSTR("Lower\n"), false);
  187. break;
  188. case _RAISE:
  189. oled_write_P(PSTR("Raise\n"), false);
  190. break;
  191. case _ADJUST:
  192. oled_write_P(PSTR("Adjust\n"), false);
  193. break;
  194. default:
  195. oled_write_P(PSTR("Undefined\n"), false);
  196. }
  197. // Print string received via HID RAW
  198. oled_write_ln(receive_buffer, false);
  199. }
  200. #ifdef RAW_ENABLE
  201. void raw_hid_receive(uint8_t *data, uint8_t length) {
  202. // Append data to receive_buffer, without the first byte
  203. memcpy(receive_buffer + receive_buffer_length, data + 1, length - 1);
  204. receive_buffer_length += (length - 1);
  205. // First byte indicate if we will recive more package for the current string
  206. // If it's 1 then this was the last package and we can reset the offset
  207. if (data[0] == 1) {
  208. // Reset the offset for memcpy to the begining of our buffer
  209. receive_buffer_length = 0;
  210. }
  211. // Reset the offset to prevent overwriting memory outside of the buffer
  212. if (receive_buffer_length + 32 >= 128) {
  213. receive_buffer_length = 0;
  214. }
  215. }
  216. #endif
  217. #endif