My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

tft_string.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #include "../marlinui.h"
  27. //#define DEBUG_TFT_FONT
  28. #define DEBUG_OUT ENABLED(DEBUG_TFT_FONT)
  29. #include "../../core/debug_out.h"
  30. glyph_t *TFT_String::glyphs[256];
  31. font_t *TFT_String::font_header;
  32. uint8_t TFT_String::data[];
  33. uint16_t TFT_String::span;
  34. uint8_t TFT_String::length;
  35. void TFT_String::set_font(const uint8_t *font) {
  36. font_header = (font_t *)font;
  37. uint32_t glyph;
  38. for (glyph = 0; glyph < 256; glyph++) glyphs[glyph] = nullptr;
  39. DEBUG_ECHOLNPGM("Format: ", font_header->Format);
  40. DEBUG_ECHOLNPGM("BBXWidth: ", font_header->BBXWidth);
  41. DEBUG_ECHOLNPGM("BBXHeight: ", font_header->BBXHeight);
  42. DEBUG_ECHOLNPGM("BBXOffsetX: ", font_header->BBXOffsetX);
  43. DEBUG_ECHOLNPGM("BBXOffsetY: ", font_header->BBXOffsetY);
  44. DEBUG_ECHOLNPGM("CapitalAHeight: ", font_header->CapitalAHeight);
  45. DEBUG_ECHOLNPGM("Encoding65Pos: ", font_header->Encoding65Pos);
  46. DEBUG_ECHOLNPGM("Encoding97Pos: ", font_header->Encoding97Pos);
  47. DEBUG_ECHOLNPGM("FontStartEncoding: ", font_header->FontStartEncoding);
  48. DEBUG_ECHOLNPGM("FontEndEncoding: ", font_header->FontEndEncoding);
  49. DEBUG_ECHOLNPGM("LowerGDescent: ", font_header->LowerGDescent);
  50. DEBUG_ECHOLNPGM("FontAscent: ", font_header->FontAscent);
  51. DEBUG_ECHOLNPGM("FontDescent: ", font_header->FontDescent);
  52. DEBUG_ECHOLNPGM("FontXAscent: ", font_header->FontXAscent);
  53. DEBUG_ECHOLNPGM("FontXDescent: ", font_header->FontXDescent);
  54. add_glyphs(font);
  55. }
  56. void TFT_String::add_glyphs(const uint8_t *font) {
  57. uint32_t glyph;
  58. uint8_t *pointer = (uint8_t *)font + sizeof(font_t);
  59. for (glyph = ((font_t *)font)->FontStartEncoding; glyph <= ((font_t *)font)->FontEndEncoding; glyph++) {
  60. if (*pointer != NO_GLYPH) {
  61. glyphs[glyph] = (glyph_t *)pointer;
  62. pointer += sizeof(glyph_t) + ((glyph_t *)pointer)->DataSize;
  63. }
  64. else
  65. pointer++;
  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. /**
  75. * Add a string, applying substitutions for the following characters:
  76. *
  77. * $ displays an inserted C-string given by the itemString parameter
  78. * = displays '0'....'10' for indexes 0 - 10
  79. * ~ displays '1'....'11' for indexes 0 - 10
  80. * * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
  81. * @ displays an axis name such as XYZUVW, or E for an extruder
  82. */
  83. void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString/*=nullptr*/) {
  84. wchar_t wchar;
  85. while (*string) {
  86. string = get_utf8_value_cb(string, read_byte, &wchar);
  87. if (wchar > 255) wchar |= 0x0080;
  88. uint8_t ch = uint8_t(wchar & 0x00FF);
  89. if (ch == '=' || ch == '~' || ch == '*') {
  90. if (index >= 0) {
  91. int8_t inum = index + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
  92. if (ch == '*') add_character('E');
  93. if (inum >= 10) { add_character('0' + (inum / 10)); inum %= 10; }
  94. add_character('0' + inum);
  95. }
  96. else
  97. add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED));
  98. }
  99. else if (ch == '$' && itemString)
  100. add(itemString);
  101. else if (ch == '@')
  102. add_character(AXIS_CHAR(index));
  103. else
  104. add_character(ch);
  105. }
  106. eol();
  107. }
  108. void TFT_String::add(uint8_t *string, uint8_t max_len) {
  109. wchar_t wchar;
  110. while (*string && max_len) {
  111. string = get_utf8_value_cb(string, read_byte, &wchar);
  112. if (wchar > 255) wchar |= 0x0080;
  113. uint8_t ch = uint8_t(wchar & 0x00FF);
  114. add_character(ch);
  115. max_len--;
  116. }
  117. eol();
  118. }
  119. void TFT_String::add_character(uint8_t character) {
  120. if (length < MAX_STRING_LENGTH) {
  121. data[length] = character;
  122. length++;
  123. span += glyph(character)->DWidth;
  124. }
  125. }
  126. void TFT_String::rtrim(uint8_t character) {
  127. while (length) {
  128. if (data[length - 1] == 0x20 || data[length - 1] == character) {
  129. length--;
  130. span -= glyph(data[length])->DWidth;
  131. eol();
  132. }
  133. else
  134. break;
  135. }
  136. }
  137. void TFT_String::ltrim(uint8_t character) {
  138. uint16_t i, j;
  139. for (i = 0; (i < length) && (data[i] == 0x20 || data[i] == character); i++) {
  140. span -= glyph(data[i])->DWidth;
  141. }
  142. if (i == 0) return;
  143. for (j = 0; i < length; data[j++] = data[i++]);
  144. length = j;
  145. eol();
  146. }
  147. void TFT_String::trim(uint8_t character) {
  148. rtrim(character);
  149. ltrim(character);
  150. }
  151. TFT_String tft_string;
  152. #endif // HAS_GRAPHICAL_TFT