keymap.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 "../../bigseries.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. KEYMAP(
  47. KC_A),
  48. };
  49. void reset_rgb(void);
  50. bool initialized = 0;
  51. uint32_t lastTime = 0;
  52. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
  53. return MACRO_NONE ;
  54. }
  55. void matrix_init_user(void) {
  56. if (!initialized){
  57. dprintf("Initializing in matrix_scan_user");
  58. rgblight_enable();
  59. reset_rgb();
  60. initialized = 1;
  61. }
  62. }
  63. void matrix_scan_user(void) {
  64. if (lastTime > 0 && timer_elapsed32(lastTime) > ANSWER_TIMEOUT) {
  65. lastTime = 0;
  66. reset_rgb();
  67. }
  68. }
  69. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  70. switch (keycode) {
  71. case KC_A:
  72. if (record->event.pressed) {
  73. uint8_t num = rand() / (RAND_MAX / NUM_ANSWERS + 1);
  74. rgblight_mode(1);
  75. if (num < UNCERTAIN_BREAK) {
  76. rgblight_setrgb_green();
  77. } else if (num < NO_BREAK) {
  78. rgblight_setrgb_yellow();
  79. } else {
  80. rgblight_setrgb_red();
  81. }
  82. send_string(ANSWERS[num]);
  83. lastTime = timer_read32();
  84. return false;
  85. }
  86. }
  87. return true;
  88. }
  89. void led_set_user(uint8_t usb_led) {
  90. if (usb_led & (1 << USB_LED_NUM_LOCK)) {
  91. } else {
  92. }
  93. if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
  94. } else {
  95. }
  96. if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
  97. } else {
  98. }
  99. if (usb_led & (1 << USB_LED_COMPOSE)) {
  100. } else {
  101. }
  102. if (usb_led & (1 << USB_LED_KANA)) {
  103. } else {
  104. }
  105. }
  106. void reset_rgb(void) {
  107. // This gets called on init and after the timeout for the answer color
  108. // If you want to change the default color/mode, do it here
  109. rgblight_sethsv_blue();
  110. rgblight_mode(7);
  111. }