You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
6.0 KiB

  1. /* Copyright 2020 jakobst1n
  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. #ifdef RGB_MATRIX_ENABLE
  18. #ifdef SLEEPMODE_ENABLE
  19. /* A bunch of vars to keep track of the rgb states
  20. before sleepmode is turned on */
  21. static bool sleepmode_on = false;
  22. static uint8_t sleepmode_before_mode = -1;
  23. static uint8_t sleepmode_before_brightness = -1;
  24. static uint8_t sleepmode_before_anim_speed = -1;
  25. static uint8_t halfmin_counter = 0;
  26. static uint16_t idle_timer = 0;
  27. #endif
  28. #endif
  29. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  30. /* ,-----------------------------------------------------------.
  31. * |ESC| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | + | ´ | BACK |
  32. * |-----------------------------------------------------------|
  33. * | TAB | Q | W | E | R | T | Y | U | I | O | P | Å | ¨ | RET |
  34. * |------------------------------------------------------\ |
  35. * | CAPS | A | S | D | F | G | H | J | K | L | Ø | Æ | @ | |
  36. * |-----------------------------------------------------------|
  37. * | ^ | < | Z | X | C | V | B | N | M | , | . | ^/- | U | - |
  38. * |-----------------------------------------------------------|
  39. * |ctrl| win| alt| |alt| fn| L | D | R |
  40. * `-----------------------------------------------------------' */
  41. [0] = LAYOUT(
  42. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
  43. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC,
  44. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_BSLS, KC_ENT,
  45. KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, MT(MOD_RSFT, KC_SLSH), KC_UP, KC_SLSH,
  46. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, OSL(1), KC_LEFT, KC_DOWN, KC_RGHT
  47. ),
  48. /* ,-----------------------------------------------------------.
  49. * |GRA| f1| f2| f3| f4| f5| f6| f7| f8| f9|f10|f11|f12| DEL |
  50. * |-----------------------------------------------------------|
  51. * | | R | R | R | R | R | R | R | R | | | | | |
  52. * |------------------------------------------------------\ |
  53. * | | | | | | | H |PGD|PGU| E | | | | |
  54. * |-----------------------------------------------------------|
  55. * | | | | | | | | | | | | |V_D|V_U|
  56. * |-----------------------------------------------------------|
  57. * | | | | | |PRE|PLA|NEX|
  58. * `-----------------------------------------------------------' */
  59. [1] = LAYOUT(
  60. KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL,
  61. _______, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, _______, _______, _______,
  62. _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END, _______, _______, _______, _______,
  63. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_VOLD, KC_VOLU,
  64. _______, _______, _______, _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT
  65. ),
  66. };
  67. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  68. #if defined(RGB_MATRIX_ENABLE) && defined(SLEEPMODE_ENABLE)
  69. if (record->event.pressed) {
  70. if (sleepmode_before_mode == -1) { sleepmode_before_mode = rgb_matrix_get_mode(); }
  71. if (sleepmode_before_brightness == -1) { sleepmode_before_brightness = rgb_matrix_get_val(); }
  72. if (sleepmode_before_anim_speed == -1) { sleepmode_before_anim_speed = rgb_matrix_get_speed(); }
  73. if (sleepmode_on == true) {
  74. // rgb_matrix_enable_noeeprom();
  75. rgb_matrix_mode_noeeprom(sleepmode_before_mode);
  76. rgb_matrix_set_speed_noeeprom(sleepmode_before_anim_speed);
  77. rgb_matrix_sethsv_noeeprom(rgb_matrix_get_hue(), rgb_matrix_get_sat(), sleepmode_before_brightness);
  78. sleepmode_on = false;
  79. }
  80. idle_timer = timer_read();
  81. halfmin_counter = 0;
  82. }
  83. #endif
  84. return true;
  85. }
  86. void matrix_scan_user(void) {
  87. #if defined(RGB_MATRIX_ENABLE) && defined(SLEEPMODE_ENABLE)
  88. /* idle_timer needs to be set one time */
  89. if (idle_timer == 0) idle_timer = timer_read();
  90. if ( !sleepmode_on && timer_elapsed(idle_timer) > 30000) {
  91. halfmin_counter++;
  92. idle_timer = timer_read();
  93. }
  94. if ( !sleepmode_on && halfmin_counter >= SLEEPMODE_TIMEOUT * 2) {// * 2) {
  95. layer_clear();
  96. sleepmode_before_anim_speed = rgb_matrix_get_speed();
  97. sleepmode_before_brightness = rgb_matrix_get_val();
  98. sleepmode_before_mode = rgb_matrix_get_mode();
  99. //rgb_matrix_disable_noeeprom();
  100. rgb_matrix_mode_noeeprom(SLEEPMODE_RGB_MODE);
  101. rgb_matrix_set_speed_noeeprom(SLEEPMODE_RGB_ANIMATION_SPEED);
  102. rgb_matrix_sethsv_noeeprom(rgb_matrix_get_hue(), rgb_matrix_get_sat(), SLEEPMODE_RGB_VAL);
  103. sleepmode_on = true;
  104. halfmin_counter = 0;
  105. }
  106. #endif
  107. }