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.

129 lines
4.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /* Copyright 2018 Jack Humbert <jack.humb@gmail.com>
  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 "rev6.h"
  17. #include "qwiic.h"
  18. #include "action_layer.h"
  19. #include "matrix.h"
  20. #ifdef QWIIC_MICRO_OLED_ENABLE
  21. static uint8_t layer;
  22. static bool queue_for_send = false;
  23. static uint8_t encoder_value = 32;
  24. void draw_ui(void) {
  25. clear_buffer();
  26. draw_string(0, 2, "LAYER", PIXEL_ON, NORM, 0);
  27. draw_rect_filled_soft(32, 0, 11, 11, PIXEL_ON, NORM);
  28. draw_char(35, 2, layer + 0x30, PIXEL_ON, XOR, 0);
  29. #define MATRIX_DISPLAY_X 46
  30. #define MATRIX_DISPLAY_Y 1
  31. for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
  32. for (uint8_t y = 0; y < MATRIX_COLS; y++) {
  33. if (x < 4)
  34. draw_pixel(MATRIX_DISPLAY_X + 2 + y, MATRIX_DISPLAY_Y + 2 + x, (matrix_get_row(x) & (1 << y)) > 0, NORM);
  35. else
  36. draw_pixel(MATRIX_DISPLAY_X + 8 + y, MATRIX_DISPLAY_Y - 2 + x, (matrix_get_row(x) & (1 << y)) > 0, NORM);
  37. }
  38. }
  39. draw_rect_soft(MATRIX_DISPLAY_X, MATRIX_DISPLAY_Y, 16, 8, PIXEL_ON, NORM);
  40. draw_rect_soft(0, 13, 64, 6, PIXEL_ON, NORM);
  41. draw_line_vert(encoder_value, 13, 6, PIXEL_ON, NORM);
  42. #define MOD_DISPLAY_X 0
  43. #define MOD_DISPLAY_Y 22
  44. uint8_t mods = get_mods();
  45. if (mods & MOD_LSFT) {
  46. draw_rect_filled_soft(MOD_DISPLAY_X + 0, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  47. draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_OFF, NORM, 0);
  48. } else {
  49. draw_string(MOD_DISPLAY_X + 3, MOD_DISPLAY_Y + 2, "S", PIXEL_ON, NORM, 0);
  50. }
  51. if (mods & MOD_LCTL) {
  52. draw_rect_filled_soft(MOD_DISPLAY_X + 10, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  53. draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_OFF, NORM, 0);
  54. } else {
  55. draw_string(MOD_DISPLAY_X + 13, MOD_DISPLAY_Y + 2, "C", PIXEL_ON, NORM, 0);
  56. }
  57. if (mods & MOD_LALT) {
  58. draw_rect_filled_soft(MOD_DISPLAY_X + 20, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  59. draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_OFF, NORM, 0);
  60. } else {
  61. draw_string(MOD_DISPLAY_X + 23, MOD_DISPLAY_Y + 2, "A", PIXEL_ON, NORM, 0);
  62. }
  63. if (mods & MOD_LGUI) {
  64. draw_rect_filled_soft(MOD_DISPLAY_X + 30, MOD_DISPLAY_Y, 5 + (1 * 6), 11, PIXEL_ON, NORM);
  65. draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_OFF, NORM, 0);
  66. } else {
  67. draw_string(MOD_DISPLAY_X + 33, MOD_DISPLAY_Y + 2, "G", PIXEL_ON, NORM, 0);
  68. }
  69. send_buffer();
  70. }
  71. uint32_t layer_state_set_kb(uint32_t state) {
  72. state = layer_state_set_user(state);
  73. layer = biton32(state);
  74. queue_for_send = true;
  75. return state;
  76. }
  77. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  78. queue_for_send = true;
  79. return process_record_user(keycode, record);
  80. }
  81. void encoder_update_kb(uint8_t index, bool clockwise) {
  82. encoder_value = (encoder_value + (clockwise ? 1 : -1)) % 64;
  83. queue_for_send = true;
  84. }
  85. #endif
  86. void matrix_init_kb(void) {
  87. #ifdef QWIIC_MICRO_OLED_ENABLE
  88. queue_for_send = true;
  89. #endif
  90. matrix_init_user();
  91. }
  92. void matrix_scan_kb(void) {
  93. #ifdef QWIIC_MICRO_OLED_ENABLE
  94. if (queue_for_send) {
  95. draw_ui();
  96. queue_for_send = false;
  97. }
  98. #endif
  99. matrix_scan_user();
  100. }
  101. #ifdef QWIIC_JOYSTIIC_ENABLE
  102. void joystiic_trigger_kb(uint8_t trigger, bool active) {
  103. switch (trigger) {
  104. case JOYSTIIC_LEFT: active ? register_code(KC_L) : unregister_code(KC_L); break;
  105. case JOYSTIIC_RIGHT: active ? register_code(KC_R) : unregister_code(KC_R); break;
  106. case JOYSTIIC_UP: active ? register_code(KC_U) : unregister_code(KC_U); break;
  107. case JOYSTIIC_DOWN: active ? register_code(KC_D) : unregister_code(KC_D); break;
  108. case JOYSTIIC_PRESS: active ? register_code(KC_P) : unregister_code(KC_P); break;
  109. }
  110. }
  111. #endif