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.

100 lines
3.6 KiB

  1. /*
  2. * ----------------------------------------------------------------------------
  3. * "THE BEER-WARE LICENSE" (Revision 42):
  4. * <https://github.com/Legonut> wrote this file. As long as you retain this
  5. * notice you can do whatever you want with this stuff. If we meet some day, and
  6. * you think this stuff is worth it, you can buy me a beer in return. David Rauseo
  7. * ----------------------------------------------------------------------------
  8. */
  9. #include "common_oled.h"
  10. #include "oled_driver.h"
  11. #include "rgb_matrix.h"
  12. // for memcpy
  13. #include <string.h>
  14. #include <transactions.h>
  15. typedef struct {
  16. bool selecting;
  17. uint8_t selection;
  18. } kb_menu_status_t;
  19. static kb_menu_status_t rgb_menu = { false, 4 };
  20. static bool rgb_menu_changed = false;
  21. void render_logo(void) {
  22. static const char PROGMEM font_logo[] = {
  23. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  24. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  25. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  26. oled_write_P(font_logo, false);
  27. }
  28. void render_icon(void) {
  29. static const char PROGMEM font_icon[] = {
  30. 0x9b,0x9c,0x9d,0x9e,0x9f,
  31. 0xbb,0xbc,0xbd,0xbe,0xbf,
  32. 0xdb,0xdc,0xdd,0xde,0xdf,0
  33. };
  34. oled_write_P(font_icon, false);
  35. }
  36. #define RGB_FUNCTION_COUNT 6
  37. typedef void (*rgb_matrix_f)(void);
  38. const rgb_matrix_f rgb_matrix_functions[RGB_FUNCTION_COUNT][2] = {
  39. { rgb_matrix_increase_hue, rgb_matrix_decrease_hue },
  40. { rgb_matrix_increase_sat, rgb_matrix_decrease_sat },
  41. { rgb_matrix_increase_val, rgb_matrix_decrease_val },
  42. { rgb_matrix_increase_speed, rgb_matrix_decrease_speed },
  43. { rgb_matrix_step, rgb_matrix_step_reverse },
  44. { rgb_matrix_toggle, rgb_matrix_toggle }
  45. };
  46. void render_rgb_menu(void) {
  47. static char buffer[63] = {0};
  48. snprintf(buffer, sizeof(buffer), "Hue %3dSatrn %3dValue %3dSpeed %3dMode %3dEnbld %3d",
  49. rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, rgb_matrix_config.speed, rgb_matrix_config.mode, rgb_matrix_config.enable);
  50. if (rgb_menu.selecting) {
  51. buffer[5 + rgb_menu.selection * 10] = '*';
  52. }
  53. else {
  54. buffer[5 + rgb_menu.selection * 10] = '>';
  55. }
  56. oled_write(buffer, false);
  57. }
  58. void rgb_menu_selection(void) {
  59. if (!is_keyboard_master()) return;
  60. rgb_menu.selecting = !rgb_menu.selecting;
  61. rgb_menu_changed = true;
  62. }
  63. void rgb_menu_action(bool clockwise) {
  64. if (!is_keyboard_master()) return;
  65. if (rgb_menu.selecting) {
  66. if (!clockwise) {
  67. rgb_menu.selection = (rgb_menu.selection - 1);
  68. if (rgb_menu.selection >= RGB_FUNCTION_COUNT)
  69. rgb_menu.selection = RGB_FUNCTION_COUNT - 1;
  70. }
  71. else {
  72. rgb_menu.selection = (rgb_menu.selection + 1) % RGB_FUNCTION_COUNT;
  73. }
  74. }
  75. else {
  76. (*rgb_matrix_functions[rgb_menu.selection][clockwise])();
  77. }
  78. rgb_menu_changed = true;
  79. }
  80. void rgb_menu_update(int8_t transaction_id) {
  81. if (!is_keyboard_master()) return;
  82. if (!rgb_menu_changed) return;
  83. rgb_menu_changed = false;
  84. transaction_rpc_send(transaction_id, sizeof(kb_menu_status_t), &rgb_menu);
  85. }
  86. void rgb_menu_slave_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
  87. memcpy(&rgb_menu, initiator2target_buffer, sizeof(kb_menu_status_t));
  88. }