logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

common_oled.c (3684B)


  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 & snprintf
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <transactions.h>
  16. typedef struct {
  17. bool selecting;
  18. uint8_t selection;
  19. } kb_menu_status_t;
  20. static kb_menu_status_t rgb_menu = { false, 4 };
  21. static bool rgb_menu_changed = false;
  22. void render_logo(void) {
  23. static const char PROGMEM font_logo[] = {
  24. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  25. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  26. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  27. oled_write_P(font_logo, false);
  28. }
  29. void render_icon(void) {
  30. static const char PROGMEM font_icon[] = {
  31. 0x9b,0x9c,0x9d,0x9e,0x9f,
  32. 0xbb,0xbc,0xbd,0xbe,0xbf,
  33. 0xdb,0xdc,0xdd,0xde,0xdf,0
  34. };
  35. oled_write_P(font_icon, false);
  36. }
  37. #define RGB_FUNCTION_COUNT 6
  38. typedef void (*rgb_matrix_f)(void);
  39. const rgb_matrix_f rgb_matrix_functions[RGB_FUNCTION_COUNT][2] = {
  40. { rgb_matrix_increase_hue, rgb_matrix_decrease_hue },
  41. { rgb_matrix_increase_sat, rgb_matrix_decrease_sat },
  42. { rgb_matrix_increase_val, rgb_matrix_decrease_val },
  43. { rgb_matrix_increase_speed, rgb_matrix_decrease_speed },
  44. { rgb_matrix_step, rgb_matrix_step_reverse },
  45. { rgb_matrix_toggle, rgb_matrix_toggle }
  46. };
  47. void render_rgb_menu(void) {
  48. static char buffer[63] = {0};
  49. snprintf(buffer, sizeof(buffer), "Hue %3dSatrn %3dValue %3dSpeed %3dMode %3dEnbld %3d",
  50. 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);
  51. if (rgb_menu.selecting) {
  52. buffer[5 + rgb_menu.selection * 10] = '*';
  53. }
  54. else {
  55. buffer[5 + rgb_menu.selection * 10] = '>';
  56. }
  57. oled_write(buffer, false);
  58. }
  59. void rgb_menu_selection(void) {
  60. if (!is_keyboard_master()) return;
  61. rgb_menu.selecting = !rgb_menu.selecting;
  62. rgb_menu_changed = true;
  63. }
  64. void rgb_menu_action(bool clockwise) {
  65. if (!is_keyboard_master()) return;
  66. if (rgb_menu.selecting) {
  67. if (!clockwise) {
  68. rgb_menu.selection = (rgb_menu.selection - 1);
  69. if (rgb_menu.selection >= RGB_FUNCTION_COUNT)
  70. rgb_menu.selection = RGB_FUNCTION_COUNT - 1;
  71. }
  72. else {
  73. rgb_menu.selection = (rgb_menu.selection + 1) % RGB_FUNCTION_COUNT;
  74. }
  75. }
  76. else {
  77. (*rgb_matrix_functions[rgb_menu.selection][clockwise])();
  78. }
  79. rgb_menu_changed = true;
  80. }
  81. void rgb_menu_update(int8_t transaction_id) {
  82. if (!is_keyboard_master()) return;
  83. if (!rgb_menu_changed) return;
  84. rgb_menu_changed = false;
  85. transaction_rpc_send(transaction_id, sizeof(kb_menu_status_t), &rgb_menu);
  86. }
  87. void rgb_menu_slave_sync(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
  88. memcpy(&rgb_menu, initiator2target_buffer, sizeof(kb_menu_status_t));
  89. }