lcd_keyframes.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Copyright 2017 Fred Sundvik
  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 "lcd_keyframes.h"
  17. #include <string.h>
  18. #include "action_util.h"
  19. #include "led.h"
  20. bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) {
  21. (void)animation;
  22. gdispClear(White);
  23. gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black);
  24. gdispFlush();
  25. return false;
  26. }
  27. static void format_layer_bitmap_string(uint16_t default_layer, uint16_t layer, char* buffer) {
  28. for (int i=0; i<16;i++)
  29. {
  30. uint32_t mask = (1u << i);
  31. if (default_layer & mask) {
  32. if (layer & mask) {
  33. *buffer = 'B';
  34. } else {
  35. *buffer = 'D';
  36. }
  37. } else if (layer & mask) {
  38. *buffer = '1';
  39. } else {
  40. *buffer = '0';
  41. }
  42. ++buffer;
  43. if (i==3 || i==7 || i==11) {
  44. *buffer = ' ';
  45. ++buffer;
  46. }
  47. }
  48. *buffer = 0;
  49. }
  50. bool lcd_keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
  51. (void)animation;
  52. const char* layer_help = "1=On D=Default B=Both";
  53. char layer_buffer[16 + 4]; // 3 spaces and one null terminator
  54. gdispClear(White);
  55. gdispDrawString(0, 0, layer_help, state->font_fixed5x8, Black);
  56. format_layer_bitmap_string(state->status.default_layer, state->status.layer, layer_buffer);
  57. gdispDrawString(0, 10, layer_buffer, state->font_fixed5x8, Black);
  58. format_layer_bitmap_string(state->status.default_layer >> 16, state->status.layer >> 16, layer_buffer);
  59. gdispDrawString(0, 20, layer_buffer, state->font_fixed5x8, Black);
  60. gdispFlush();
  61. return false;
  62. }
  63. static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
  64. *buffer = ' ';
  65. ++buffer;
  66. for (int i = 0; i<8; i++)
  67. {
  68. uint32_t mask = (1u << i);
  69. if (mods & mask) {
  70. *buffer = '1';
  71. } else {
  72. *buffer = '0';
  73. }
  74. ++buffer;
  75. if (i==3) {
  76. *buffer = ' ';
  77. ++buffer;
  78. }
  79. }
  80. *buffer = 0;
  81. }
  82. bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
  83. (void)animation;
  84. const char* title = "Modifier states";
  85. const char* mods_header = " CSAG CSAG ";
  86. char status_buffer[12];
  87. gdispClear(White);
  88. gdispDrawString(0, 0, title, state->font_fixed5x8, Black);
  89. gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black);
  90. format_mods_bitmap_string(state->status.mods, status_buffer);
  91. gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black);
  92. gdispFlush();
  93. return false;
  94. }
  95. #define LED_STATE_STRING_SIZE sizeof("NUM CAPS SCRL COMP KANA")
  96. static void get_led_state_string(char* output, visualizer_state_t* state) {
  97. uint8_t pos = 0;
  98. if (state->status.leds & (1u << USB_LED_NUM_LOCK)) {
  99. memcpy(output + pos, "NUM ", 4);
  100. pos += 4;
  101. }
  102. if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) {
  103. memcpy(output + pos, "CAPS ", 5);
  104. pos += 5;
  105. }
  106. if (state->status.leds & (1u << USB_LED_SCROLL_LOCK)) {
  107. memcpy(output + pos, "SCRL ", 5);
  108. pos += 5;
  109. }
  110. if (state->status.leds & (1u << USB_LED_COMPOSE)) {
  111. memcpy(output + pos, "COMP ", 5);
  112. pos += 5;
  113. }
  114. if (state->status.leds & (1u << USB_LED_KANA)) {
  115. memcpy(output + pos, "KANA ", 5);
  116. pos += 5;
  117. }
  118. output[pos] = 0;
  119. }
  120. bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state)
  121. {
  122. (void)animation;
  123. char output[LED_STATE_STRING_SIZE];
  124. get_led_state_string(output, state);
  125. gdispClear(White);
  126. gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black);
  127. gdispFlush();
  128. return false;
  129. }
  130. bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state) {
  131. (void)animation;
  132. gdispClear(White);
  133. uint8_t y = 10;
  134. if (state->status.leds) {
  135. char output[LED_STATE_STRING_SIZE];
  136. get_led_state_string(output, state);
  137. gdispDrawString(0, 1, output, state->font_dejavusansbold12, Black);
  138. y = 17;
  139. }
  140. gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black);
  141. gdispFlush();
  142. return false;
  143. }