logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keymap.c (4191B)


  1. /* Copyright 2020 Snipeye
  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. enum uno_keycode
  18. {
  19. UNO = SAFE_RANGE
  20. };
  21. static uint16_t pressTimer = 0xFFFF;
  22. #define CUSTOM_LONGPRESS 150
  23. #define CUSTOM_LONGERPRESS 750
  24. #define CUSTOM_STRING "I can put a whole buncha text in here and type it all with a single keypress."
  25. #define RESET_LENGTH 3000
  26. const uint8_t PROGMEM RGBLED_RAINBOW_MOOD_INTERVALS[] = { 10, 25, 50 };
  27. char stringToSend[2] = "a";
  28. char maxLetter = 'z';
  29. uint8_t presetCounter = 0;
  30. #define COUNTER X_A
  31. enum encoder_names {
  32. _ENCODER,
  33. };
  34. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  35. [0] = LAYOUT(
  36. UNO
  37. )
  38. };
  39. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  40. switch (keycode) {
  41. case UNO:
  42. if (record->event.pressed) {
  43. pressTimer = timer_read();
  44. } else {
  45. uint16_t timeElapsed = timer_elapsed(pressTimer);
  46. switch (presetCounter) {
  47. case 0:
  48. SEND_STRING(SS_LCMD("n"));
  49. break;
  50. case 1:
  51. SEND_STRING("Hello!");
  52. break;
  53. case 2:
  54. SEND_STRING("\n\nI am uno!");
  55. break;
  56. case 3:
  57. SEND_STRING("\n\nI can do all sorts of useless things!");
  58. break;
  59. case 4:
  60. SEND_STRING("\n\nAnd I have a built-in RGB LED!\n\n\n");
  61. rgblight_sethsv_noeeprom(255, 255, 255);
  62. rgblight_mode_noeeprom(RGBLIGHT_MODE_RAINBOW_MOOD);
  63. break;
  64. default:
  65. if (timeElapsed < CUSTOM_LONGPRESS) {
  66. // Normal press. We're going to send the current letter and increment the counter.
  67. SEND_STRING(SS_TAP(X_BACKSPACE));
  68. send_string(stringToSend);
  69. stringToSend[0]++;
  70. if (stringToSend[0] > maxLetter) {
  71. stringToSend[0] = 'a';
  72. }
  73. } else if (timeElapsed < CUSTOM_LONGERPRESS) {
  74. // Long press, confirm the current letter, reset counter
  75. stringToSend[0] = 'a';
  76. send_string(stringToSend);
  77. } else if (timeElapsed < RESET_LENGTH) {
  78. // Longer press, display macro.
  79. SEND_STRING(CUSTOM_STRING);
  80. } else {
  81. reset_keyboard();
  82. }
  83. presetCounter--;
  84. break;
  85. }
  86. presetCounter++;
  87. }
  88. break;
  89. }
  90. return false;
  91. }
  92. void keyboard_post_init_user(void) {
  93. rgblight_enable_noeeprom();
  94. rgblight_sethsv_noeeprom(0, 0, 0);
  95. rgblight_mode(1);
  96. // Uncomment to enable rainbow mode when plugged in.
  97. // Otherwise, the LED will be revealed after a few keypresses.
  98. //rgblight_sethsv_noeeprom(255, 255, 255);
  99. //rgblight_mode_noeeprom(RGBLIGHT_MODE_RAINBOW_MOOD);
  100. }
  101. bool encoder_update_user(uint8_t index, bool clockwise) {
  102. if (index == _ENCODER) { /* First encoder */
  103. if (clockwise) {
  104. tap_code(KC_A);
  105. } else {
  106. tap_code(KC_B);
  107. }
  108. return false;
  109. }
  110. return true;
  111. }