customLogic.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include QMK_KEYBOARD_H
  2. #include "customLogic.h"
  3. #include "keymap.h"
  4. #include "keyDefinitions.h"
  5. #include "relativity.h"
  6. #include "timer.h"
  7. static int16_t fnTimer = 0;
  8. uint32_t layer_state_set_user(uint32_t state)
  9. {
  10. switch (biton32(state))
  11. {
  12. case QWERTY:
  13. rgblight_mode(9);
  14. break;
  15. case NAV_CLUSTER:
  16. rgblight_mode(29);
  17. break;
  18. case GAMING:
  19. rgblight_mode(26);
  20. break;
  21. case SQLMACROS:
  22. rgblight_mode(1);
  23. break;
  24. case FN_LAYER:
  25. rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL+5);
  26. break;
  27. }
  28. return state;
  29. }
  30. bool printSqlVerbs(uint16_t keycode, keyrecord_t *record)
  31. {
  32. if (record->event.pressed)
  33. {
  34. switch (keycode)
  35. {
  36. case S_LFTJN:
  37. SEND_STRING("LEFT JOIN");
  38. activateRelativity();
  39. return false;
  40. case S_INRJN:
  41. SEND_STRING("INNER JOIN ");
  42. activateRelativity();
  43. return false;
  44. case S_SLCT:
  45. SEND_STRING("SELECT "); return
  46. false;
  47. case S_FROM:
  48. SEND_STRING("FROM "); return
  49. false;
  50. case S_DSNCT:
  51. SEND_STRING("DISTINCT "); return
  52. false;
  53. case S_ORDER:
  54. SEND_STRING("ORDER BY "); return
  55. false;
  56. case S_WHERE:
  57. SEND_STRING("WHERE "); return
  58. false;
  59. case S_ALTER:
  60. SEND_STRING("ALTER SESSION SET CURRENT_SCHEMA = SUPPLY;"); return false;
  61. case S_ASTRK:
  62. SEND_STRING("* "); return false;
  63. }
  64. }
  65. return true;
  66. }
  67. bool isFn = false;
  68. bool didFn = false;
  69. bool updateLayerState(uint16_t keycode, keyrecord_t *record)
  70. {
  71. if (record->event.pressed)
  72. {
  73. switch (keycode)
  74. {
  75. case FN_QT:
  76. fnTimer = timer_read();
  77. layer_on(FN_LAYER);
  78. isFn = true;
  79. return false;
  80. }
  81. if (isFn)
  82. {
  83. didFn = true;
  84. return true;
  85. }
  86. }
  87. else
  88. {
  89. switch(keycode)
  90. {
  91. case FN_QT:
  92. layer_off(FN_LAYER);
  93. if (!didFn)
  94. {
  95. #if fnTimeout
  96. if (TIMER_DIFF_16(timer_read(), fnTimer) <= fnTimeout)
  97. {
  98. activateRelativity();
  99. }
  100. else
  101. {
  102. deactivateRelativity();
  103. }
  104. #else
  105. activateRelativity();
  106. #endif
  107. }
  108. didFn = false;
  109. isFn = false;
  110. return false;
  111. }
  112. }
  113. return true;
  114. }
  115. bool process_record_user(uint16_t keycode, keyrecord_t *record)
  116. {
  117. return
  118. storeShiftState(keycode, record) &&
  119. printSqlVerbs(keycode, record) &&
  120. updateLayerState(keycode, record) &&
  121. handleSmartMacros(keycode, record);
  122. }