keymap.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. [0] = LAYOUT(
  33. UNO
  34. )
  35. };
  36. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  37. switch (keycode) {
  38. case UNO:
  39. if (record->event.pressed) {
  40. pressTimer = timer_read();
  41. } else {
  42. uint16_t timeElapsed = timer_elapsed(pressTimer);
  43. switch (presetCounter) {
  44. case 0:
  45. SEND_STRING(SS_LCMD("n"));
  46. break;
  47. case 1:
  48. SEND_STRING("Hello!");
  49. break;
  50. case 2:
  51. SEND_STRING(SS_TAP(X_ENTER)SS_TAP(X_ENTER)"I am uno!");
  52. break;
  53. case 3:
  54. SEND_STRING(SS_TAP(X_ENTER)SS_TAP(X_ENTER)"I can do all sorts of useless things!");
  55. break;
  56. case 4:
  57. SEND_STRING(SS_TAP(X_ENTER)SS_TAP(X_ENTER)"And I have a built-in RGB LED!"SS_TAP(X_ENTER)SS_TAP(X_ENTER)SS_TAP(X_ENTER));
  58. rgblight_sethsv_noeeprom(255, 255, 255);
  59. rgblight_mode_noeeprom(RGBLIGHT_MODE_RAINBOW_MOOD);
  60. break;
  61. default:
  62. if (timeElapsed < CUSTOM_LONGPRESS) {
  63. // Normal press. We're going to send the current letter and increment the counter.
  64. SEND_STRING(SS_TAP(X_BSPACE));
  65. send_string(stringToSend);
  66. stringToSend[0]++;
  67. if (stringToSend[0] > maxLetter) {
  68. stringToSend[0] = 'a';
  69. }
  70. } else if (timeElapsed < CUSTOM_LONGERPRESS) {
  71. // Long press, confirm the current letter, reset counter
  72. stringToSend[0] = 'a';
  73. send_string(stringToSend);
  74. } else if (timeElapsed < RESET_LENGTH) {
  75. // Longer press, display macro.
  76. SEND_STRING(CUSTOM_STRING);
  77. } else {
  78. reset_keyboard();
  79. }
  80. presetCounter--;
  81. break;
  82. }
  83. presetCounter++;
  84. }
  85. break;
  86. }
  87. return false;
  88. }
  89. void keyboard_post_init_user(void) {
  90. rgblight_enable_noeeprom();
  91. rgblight_sethsv_noeeprom(0, 0, 0);
  92. rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
  93. }