My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

tft_string.cpp 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../inc/MarlinConfig.h"
  23. #if HAS_GRAPHICAL_TFT
  24. #include "tft_string.h"
  25. #include "../fontutils.h"
  26. //#define DEBUG_TFT_FONT
  27. #define DEBUG_OUT ENABLED(DEBUG_TFT_FONT)
  28. #include "../../core/debug_out.h"
  29. glyph_t *TFT_String::glyphs[256];
  30. font_t *TFT_String::font_header;
  31. uint8_t TFT_String::data[];
  32. uint16_t TFT_String::span;
  33. uint16_t TFT_String::length;
  34. void TFT_String::set_font(const uint8_t *font) {
  35. font_header = (font_t *)font;
  36. uint32_t glyph;
  37. for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = NULL;
  38. DEBUG_ECHOLNPAIR("Format: ", font_header->Format);
  39. DEBUG_ECHOLNPAIR("BBXWidth: ", font_header->BBXWidth);
  40. DEBUG_ECHOLNPAIR("BBXHeight: ", font_header->BBXHeight);
  41. DEBUG_ECHOLNPAIR("BBXOffsetX: ", font_header->BBXOffsetX);
  42. DEBUG_ECHOLNPAIR("BBXOffsetY: ", font_header->BBXOffsetY);
  43. DEBUG_ECHOLNPAIR("CapitalAHeight: ", font_header->CapitalAHeight);
  44. DEBUG_ECHOLNPAIR("Encoding65Pos: ", font_header->Encoding65Pos);
  45. DEBUG_ECHOLNPAIR("Encoding97Pos: ", font_header->Encoding97Pos);
  46. DEBUG_ECHOLNPAIR("FontStartEncoding: ", font_header->FontStartEncoding);
  47. DEBUG_ECHOLNPAIR("FontEndEncoding: ", font_header->FontEndEncoding);
  48. DEBUG_ECHOLNPAIR("LowerGDescent: ", font_header->LowerGDescent);
  49. DEBUG_ECHOLNPAIR("FontAscent: ", font_header->FontAscent);
  50. DEBUG_ECHOLNPAIR("FontDescent: ", font_header->FontDescent);
  51. DEBUG_ECHOLNPAIR("FontXAscent: ", font_header->FontXAscent);
  52. DEBUG_ECHOLNPAIR("FontXDescent: ", font_header->FontXDescent);
  53. add_glyphs(font);
  54. }
  55. void TFT_String::add_glyphs(const uint8_t *font) {
  56. uint32_t glyph;
  57. uint8_t *pointer = (uint8_t *)font + sizeof(font_t);
  58. for (glyph = ((font_t *)font)->FontStartEncoding; glyph <= ((font_t *)font)->FontEndEncoding; glyph++) {
  59. if (*pointer != NO_GLYPH) {
  60. glyphs[glyph] = (glyph_t *)pointer;
  61. pointer += sizeof(glyph_t) + ((glyph_t *)pointer)->DataSize;
  62. }
  63. else {
  64. pointer++;
  65. }
  66. }
  67. }
  68. void TFT_String::set() {
  69. *data = 0x00;
  70. span = 0;
  71. length = 0;
  72. }
  73. uint8_t read_byte(uint8_t *byte) { return *byte; }
  74. void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) {
  75. wchar_t wchar;
  76. while (*string) {
  77. string = get_utf8_value_cb(string, read_byte, &wchar);
  78. if (wchar > 255) wchar |= 0x0080;
  79. uint8_t ch = uint8_t(wchar & 0x00FF);
  80. if (ch == '=' || ch == '~' || ch == '*') {
  81. if (index >= 0) {
  82. int8_t inum = index + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
  83. if (ch == '*') add_character('E');
  84. if (inum >= 10) { add_character('0' + (inum / 10)); inum %= 10; }
  85. add_character('0' + inum);
  86. }
  87. else {
  88. add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED));
  89. }
  90. continue;
  91. }
  92. else if (ch == '$' && itemString) {
  93. add(itemString);
  94. continue;
  95. }
  96. add_character(ch);
  97. }
  98. eol();
  99. }
  100. void TFT_String::add(uint8_t *string) {
  101. wchar_t wchar;
  102. while (*string) {
  103. string = get_utf8_value_cb(string, read_byte, &wchar);
  104. if (wchar > 255) wchar |= 0x0080;
  105. uint8_t ch = uint8_t(wchar & 0x00FF);
  106. add_character(ch);
  107. }
  108. eol();
  109. }
  110. void TFT_String::add_character(uint8_t character) {
  111. if (length < MAX_STRING_LENGTH) {
  112. data[length] = character;
  113. length++;
  114. span += glyph(character)->DWidth;
  115. }
  116. }
  117. void TFT_String::rtrim(uint8_t character) {
  118. while (length) {
  119. if (data[length - 1] == 0x20 || data[length - 1] == character) {
  120. length--;
  121. span -= glyph(data[length])->DWidth;
  122. eol();
  123. }
  124. else {
  125. break;
  126. }
  127. }
  128. }
  129. void TFT_String::ltrim(uint8_t character) {
  130. uint16_t i, j;
  131. for (i = 0; (i < length) && (data[i] == 0x20 || data[i] == character); i++) {
  132. span -= glyph(data[i])->DWidth;
  133. }
  134. if (i == 0) return;
  135. for (j = 0; i < length; data[j++] = data[i++]);
  136. length = j;
  137. eol();
  138. }
  139. void TFT_String::trim(uint8_t character) {
  140. rtrim(character);
  141. ltrim(character);
  142. }
  143. TFT_String tft_string;
  144. #endif // HAS_GRAPHICAL_TFT