lcd_keyframes.c 5.1 KB

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