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.

115 lines
2.8 KiB

  1. /*
  2. Copyright 2021 gregorio
  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 "rubi.h"
  15. void change_encoder_mode(bool reverse) {
  16. if (reverse) {
  17. if (encoder_mode == 0) {
  18. encoder_mode = _NUM_ENCODER_MODES - 1;
  19. } else {
  20. encoder_mode = encoder_mode - 1;
  21. }
  22. } else {
  23. encoder_mode = (encoder_mode + 1) % _NUM_ENCODER_MODES;
  24. }
  25. }
  26. uint16_t handle_encoder_cw(void) {
  27. uint16_t mapped_code = 0;
  28. if (oled_mode == OLED_MODE_CALC) {
  29. layer_on(2);
  30. return mapped_code;
  31. }
  32. switch (encoder_mode) {
  33. default:
  34. case ENC_MODE_VOLUME:
  35. mapped_code = KC_VOLU;
  36. break;
  37. case ENC_MODE_MEDIA:
  38. mapped_code = KC_MEDIA_NEXT_TRACK;
  39. break;
  40. case ENC_MODE_BRIGHTNESS:
  41. mapped_code = KC_BRIGHTNESS_UP;
  42. break;
  43. }
  44. return mapped_code;
  45. }
  46. uint16_t handle_encoder_ccw(void) {
  47. uint16_t mapped_code = 0;
  48. if (oled_mode == OLED_MODE_CALC) {
  49. layer_off(2);
  50. return mapped_code;
  51. }
  52. switch (encoder_mode) {
  53. default:
  54. case ENC_MODE_VOLUME:
  55. mapped_code = KC_VOLD;
  56. break;
  57. case ENC_MODE_MEDIA:
  58. mapped_code = KC_MEDIA_PREV_TRACK;
  59. break;
  60. case ENC_MODE_BRIGHTNESS:
  61. mapped_code = KC_BRIGHTNESS_DOWN;
  62. break;
  63. }
  64. return mapped_code;
  65. }
  66. uint16_t handle_encoder_press(void) {
  67. uint16_t mapped_code = 0;
  68. if (get_highest_layer(layer_state) == 1) {
  69. if (oled_mode == OLED_MODE_CALC) {
  70. layer_on(3);
  71. }
  72. layer_off(1);
  73. return mapped_code;
  74. } else if (get_highest_layer(layer_state) == 2) {
  75. if (oled_mode == OLED_MODE_CALC) {
  76. layer_off(1);
  77. layer_on(3);
  78. } else {
  79. layer_on(1);
  80. }
  81. layer_off(2);
  82. return mapped_code;
  83. } else if (get_highest_layer(layer_state) == 3) {
  84. if (oled_mode == OLED_MODE_OFF) {
  85. layer_off(3);
  86. }
  87. return mapped_code;
  88. }
  89. switch (encoder_mode) {
  90. default:
  91. case ENC_MODE_VOLUME:
  92. mapped_code = KC_MUTE;
  93. break;
  94. case ENC_MODE_MEDIA:
  95. mapped_code = KC_MEDIA_PLAY_PAUSE;
  96. break;
  97. }
  98. return mapped_code;
  99. }