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.

184 lines
5.9 KiB

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