keymap.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* Copyright 2021 Leon Anavi <leon@anavi.org>
  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. #define _MAIN 0
  18. #define _FN 1
  19. /*
  20. * This keymap contains the following shortcuts for Git. On the
  21. * first row from left to right:
  22. *
  23. * git status
  24. * git log
  25. * git pull
  26. * git push
  27. *
  28. * On the second row from left to right:
  29. *
  30. * git diff
  31. * git add
  32. * git commit
  33. * FN key to switch to the 2nd layout and control lights
  34. *
  35. */
  36. enum custom_keycodes {
  37. GITCOMMIT = SAFE_RANGE,
  38. GITPUSH,
  39. GITPULL,
  40. GITSTATUS,
  41. GITDIFF,
  42. GITLOG,
  43. GITADD
  44. };
  45. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  46. switch (keycode) {
  47. case GITCOMMIT:
  48. if (record->event.pressed) {
  49. SEND_STRING("git commit -s\n");
  50. }
  51. break;
  52. case GITPUSH:
  53. if (record->event.pressed) {
  54. SEND_STRING("git push\n");
  55. }
  56. break;
  57. case GITPULL:
  58. if (record->event.pressed) {
  59. SEND_STRING("git pull\n");
  60. }
  61. break;
  62. case GITSTATUS:
  63. if (record->event.pressed) {
  64. SEND_STRING("git status\n");
  65. }
  66. break;
  67. case GITDIFF:
  68. if (record->event.pressed) {
  69. SEND_STRING("git diff ");
  70. }
  71. break;
  72. case GITLOG:
  73. if (record->event.pressed) {
  74. SEND_STRING("git log\n");
  75. }
  76. break;
  77. case GITADD:
  78. if (record->event.pressed) {
  79. SEND_STRING("git add ");
  80. }
  81. break;
  82. }
  83. return true;
  84. };
  85. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  86. [_MAIN] = LAYOUT_ortho_2x4(
  87. GITSTATUS, GITLOG, GITPULL, GITPUSH,
  88. GITDIFF, GITADD, GITCOMMIT, MO(_FN)
  89. ),
  90. [_FN] = LAYOUT_ortho_2x4(
  91. RGB_TOG, RGB_MOD, RGB_M_R, RGB_M_SN,
  92. BL_TOGG, BL_STEP, BL_BRTG, _______
  93. )
  94. };
  95. #ifdef OLED_ENABLE
  96. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  97. return OLED_ROTATION_180; // flips the display 180 degrees if offhand
  98. }
  99. void oled_task_user(void) {
  100. // Host Keyboard Layer Status
  101. oled_write_ln_P(PSTR("ANAVI Macro Pad 8"), false);
  102. oled_write_P(PSTR("Active layer: "), false);
  103. switch (get_highest_layer(layer_state)) {
  104. case _MAIN:
  105. oled_write_ln_P(PSTR("Git"), false);
  106. break;
  107. case _FN:
  108. oled_write_ln_P(PSTR("FN"), false);
  109. break;
  110. default:
  111. // Or use the write_ln shortcut over adding '\n' to the end of your string
  112. oled_write_ln_P(PSTR("N/A"), false);
  113. }
  114. // Host Keyboard LED Status
  115. led_t led_state = host_keyboard_led_state();
  116. oled_write_P(PSTR("Num Lock: "), false);
  117. oled_write_ln_P(led_state.num_lock ? PSTR("On") : PSTR("Off"), false);
  118. oled_write_P(PSTR("Caps Lock: "), false);
  119. oled_write_ln_P(led_state.caps_lock ? PSTR("On") : PSTR("Off"), false);
  120. oled_write_P(PSTR("Scroll Lock: "), false);
  121. oled_write_ln_P(led_state.scroll_lock ? PSTR("On") : PSTR("Off"), false);
  122. oled_write_P(PSTR("Backlit: "), false);
  123. oled_write_ln_P(is_backlight_enabled() ? PSTR("On") : PSTR("Off"), false);
  124. #ifdef RGBLIGHT_ENABLE
  125. static char rgbStatusLine1[26] = {0};
  126. snprintf(rgbStatusLine1, sizeof(rgbStatusLine1), "RGB Mode: %d", rgblight_get_mode());
  127. oled_write_ln(rgbStatusLine1, false);
  128. static char rgbStatusLine2[26] = {0};
  129. snprintf(rgbStatusLine2, sizeof(rgbStatusLine2), "h:%d s:%d v:%d", rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val());
  130. oled_write_ln(rgbStatusLine2, false);
  131. #endif
  132. }
  133. #endif