lcd_keyframes.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #include "resources/resources.h"
  21. bool lcd_keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state) {
  22. (void)animation;
  23. gdispClear(White);
  24. gdispDrawString(0, 10, state->layer_text, state->font_dejavusansbold12, Black);
  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. return false;
  61. }
  62. static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
  63. *buffer = ' ';
  64. ++buffer;
  65. for (int i = 0; i<8; i++)
  66. {
  67. uint32_t mask = (1u << i);
  68. if (mods & mask) {
  69. *buffer = '1';
  70. } else {
  71. *buffer = '0';
  72. }
  73. ++buffer;
  74. if (i==3) {
  75. *buffer = ' ';
  76. ++buffer;
  77. }
  78. }
  79. *buffer = 0;
  80. }
  81. bool lcd_keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
  82. (void)animation;
  83. const char* title = "Modifier states";
  84. const char* mods_header = " CSAG CSAG ";
  85. char status_buffer[12];
  86. gdispClear(White);
  87. gdispDrawString(0, 0, title, state->font_fixed5x8, Black);
  88. gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black);
  89. format_mods_bitmap_string(state->status.mods, status_buffer);
  90. gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black);
  91. return false;
  92. }
  93. #define LED_STATE_STRING_SIZE sizeof("NUM CAPS SCRL COMP KANA")
  94. static void get_led_state_string(char* output, visualizer_state_t* state) {
  95. uint8_t pos = 0;
  96. if (state->status.leds & (1u << USB_LED_NUM_LOCK)) {
  97. memcpy(output + pos, "NUM ", 4);
  98. pos += 4;
  99. }
  100. if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) {
  101. memcpy(output + pos, "CAPS ", 5);
  102. pos += 5;
  103. }
  104. if (state->status.leds & (1u << USB_LED_SCROLL_LOCK)) {
  105. memcpy(output + pos, "SCRL ", 5);
  106. pos += 5;
  107. }
  108. if (state->status.leds & (1u << USB_LED_COMPOSE)) {
  109. memcpy(output + pos, "COMP ", 5);
  110. pos += 5;
  111. }
  112. if (state->status.leds & (1u << USB_LED_KANA)) {
  113. memcpy(output + pos, "KANA", 4);
  114. pos += 4;
  115. }
  116. output[pos] = 0;
  117. }
  118. bool lcd_keyframe_display_led_states(keyframe_animation_t* animation, visualizer_state_t* state)
  119. {
  120. (void)animation;
  121. char output[LED_STATE_STRING_SIZE];
  122. get_led_state_string(output, state);
  123. gdispClear(White);
  124. gdispDrawString(0, 10, output, state->font_dejavusansbold12, Black);
  125. return false;
  126. }
  127. bool lcd_keyframe_display_layer_and_led_states(keyframe_animation_t* animation, visualizer_state_t* state) {
  128. (void)animation;
  129. gdispClear(White);
  130. uint8_t y = 10;
  131. if (state->status.leds) {
  132. char output[LED_STATE_STRING_SIZE];
  133. get_led_state_string(output, state);
  134. gdispDrawString(0, 1, output, state->font_dejavusansbold12, Black);
  135. y = 17;
  136. }
  137. gdispDrawString(0, y, state->layer_text, state->font_dejavusansbold12, Black);
  138. return false;
  139. }
  140. bool lcd_keyframe_draw_logo(keyframe_animation_t* animation, visualizer_state_t* state) {
  141. (void)state;
  142. (void)animation;
  143. // Read the uGFX documentation for information how to use the displays
  144. // http://wiki.ugfx.org/index.php/Main_Page
  145. gdispClear(White);
  146. // You can use static variables for things that can't be found in the animation
  147. // or state structs, here we use the image
  148. //gdispGBlitArea is a tricky function to use since it supports blitting part of the image
  149. // if you have full screen image, then just use LCD_WIDTH and LCD_HEIGHT for both source and target dimensions
  150. gdispGBlitArea(GDISP, 0, 0, LCD_WIDTH, LCD_HEIGHT, 0, 0, LCD_WIDTH, (pixel_t*)resource_lcd_logo);
  151. return false;
  152. }
  153. bool lcd_keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
  154. (void)animation;
  155. (void)state;
  156. gdispSetPowerMode(powerOff);
  157. return false;
  158. }
  159. bool lcd_keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
  160. (void)animation;
  161. (void)state;
  162. gdispSetPowerMode(powerOn);
  163. return false;
  164. }