logo

qmk_firmware

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

keymap.c (2575B)


  1. /*
  2. Copyright 2018 Cole Markham
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include QMK_KEYBOARD_H
  15. static const char * const ANSWERS[] = {
  16. // "Yes" answers
  17. "It is certain\n",
  18. "It is decidedly so\n",
  19. "Without a doubt\n",
  20. "Yes definitely\n",
  21. "You may rely on it\n",
  22. "As I see it, yes\n",
  23. "Most likely\n",
  24. "Outlook good\n",
  25. "Yes\n",
  26. "Signs point to yes\n",
  27. // Uncertain answers, index 10
  28. "Reply hazy try again\n",
  29. "Ask again later\n",
  30. "Better not tell you now\n",
  31. "Cannot predict now\n",
  32. "Concentrate and ask again\n",
  33. // "No" answers, index 15
  34. "Don't count on it\n",
  35. "My reply is no\n",
  36. "My sources say no\n",
  37. "Outlook not so good\n",
  38. "Very doubtful\n"
  39. };
  40. #define UNCERTAIN_BREAK 10
  41. #define NO_BREAK 15
  42. #define NUM_ANSWERS 20
  43. // Timeout of answer color in ms
  44. #define ANSWER_TIMEOUT 3000
  45. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  46. LAYOUT(
  47. KC_A),
  48. };
  49. void reset_rgb(void);
  50. bool initialized = 0;
  51. uint32_t lastTime = 0;
  52. void matrix_init_user(void) {
  53. if (!initialized){
  54. dprintf("Initializing in matrix_scan_user");
  55. rgblight_enable();
  56. reset_rgb();
  57. initialized = 1;
  58. }
  59. }
  60. void matrix_scan_user(void) {
  61. if (lastTime > 0 && timer_elapsed32(lastTime) > ANSWER_TIMEOUT) {
  62. lastTime = 0;
  63. reset_rgb();
  64. }
  65. }
  66. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  67. switch (keycode) {
  68. case KC_A:
  69. if (record->event.pressed) {
  70. uint8_t num = rand() / (RAND_MAX / NUM_ANSWERS + 1);
  71. rgblight_mode(1);
  72. if (num < UNCERTAIN_BREAK) {
  73. rgblight_setrgb(RGB_GREEN);
  74. } else if (num < NO_BREAK) {
  75. rgblight_setrgb(RGB_YELLOW);
  76. } else {
  77. rgblight_setrgb(RGB_RED);
  78. }
  79. send_string(ANSWERS[num]);
  80. lastTime = timer_read32();
  81. return false;
  82. }
  83. }
  84. return true;
  85. }
  86. void reset_rgb(void) {
  87. // This gets called on init and after the timeout for the answer color
  88. // If you want to change the default color/mode, do it here
  89. rgblight_sethsv(HSV_BLUE);
  90. rgblight_mode(7);
  91. }