My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

tft_string.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #pragma once
  23. // TODO: Make AVR-compatible with separate ROM / RAM string methods
  24. #include <stdint.h>
  25. extern const uint8_t ISO10646_1_5x7[];
  26. extern const uint8_t font10x20[];
  27. extern const uint8_t Helvetica12Bold[];
  28. extern const uint8_t Helvetica14[], Helvetica14_symbols[];
  29. extern const uint8_t Helvetica18[], Helvetica18_symbols[];
  30. #define NO_GLYPH 0xFF
  31. typedef struct __attribute__((__packed__)) {
  32. uint8_t Format;
  33. uint8_t BBXWidth;
  34. uint8_t BBXHeight;
  35. int8_t BBXOffsetX;
  36. int8_t BBXOffsetY;
  37. uint8_t CapitalAHeight;
  38. uint16_t Encoding65Pos;
  39. uint16_t Encoding97Pos;
  40. uint8_t FontStartEncoding;
  41. uint8_t FontEndEncoding;
  42. int8_t LowerGDescent;
  43. int8_t FontAscent;
  44. int8_t FontDescent;
  45. int8_t FontXAscent;
  46. int8_t FontXDescent;
  47. } font_t;
  48. typedef struct __attribute__((__packed__)) {
  49. uint8_t BBXWidth;
  50. uint8_t BBXHeight;
  51. uint8_t DataSize;
  52. int8_t DWidth;
  53. int8_t BBXOffsetX;
  54. int8_t BBXOffsetY;
  55. } glyph_t;
  56. #define MAX_STRING_LENGTH 64
  57. class TFT_String {
  58. private:
  59. static glyph_t *glyphs[256];
  60. static font_t *font_header;
  61. static char data[MAX_STRING_LENGTH + 1];
  62. static uint16_t span; // in pixels
  63. static void add_character(const char character);
  64. static void eol() { data[length] = '\0'; }
  65. public:
  66. static uint8_t length; // in characters
  67. static void set_font(const uint8_t *font);
  68. static void add_glyphs(const uint8_t *font);
  69. static font_t *font() { return font_header; };
  70. static uint16_t font_height() { return font_header->FontAscent - font_header->FontDescent; }
  71. static glyph_t *glyph(uint8_t character) { return glyphs[character] ?: glyphs[0x3F]; } /* Use '?' for unknown glyphs */
  72. static glyph_t *glyph(uint8_t *character) { return glyph(*character); }
  73. /**
  74. * @brief Set the string empty
  75. */
  76. static void set();
  77. /**
  78. * @brief Append an ASCII character and EOL
  79. *
  80. * @param character The ASCII character
  81. */
  82. static void add(const char character) { add_character(character); eol(); }
  83. static void set(wchar_t character) { set(); add(character); }
  84. /**
  85. * @brief Append / Set C-string
  86. *
  87. * @param cstr The string
  88. * @param max_len Character limit
  89. */
  90. static void add(const char *cstr, uint8_t max_len=MAX_STRING_LENGTH);
  91. static void set(const char *cstr, uint8_t max_len=MAX_STRING_LENGTH) { set(); add(cstr, max_len); }
  92. /**
  93. * @brief Append / Set F-string
  94. *
  95. * @param fstr The string
  96. * @param max_len Character limit
  97. */
  98. static void add(FSTR_P const fstr, uint8_t max_len=MAX_STRING_LENGTH) { add(FTOP(fstr), max_len); }
  99. static void set(FSTR_P const fstr, uint8_t max_len=MAX_STRING_LENGTH) { set(FTOP(fstr), max_len); }
  100. /**
  101. * @brief Append / Set C-string with optional substitution
  102. *
  103. * @param tpl A string with optional substitution
  104. * @param index An index
  105. * @param cstr An SRAM C-string to use for $ substitution
  106. * @param fstr A ROM F-string to use for $ substitution
  107. */
  108. static void add(const char *tpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr);
  109. static void set(const char *tpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { set(); add(tpl, index, cstr, fstr); }
  110. /**
  111. * @brief Append / Set F-string with optional substitution
  112. *
  113. * @param ftpl A ROM F-string with optional substitution
  114. * @param index An index
  115. * @param cstr An SRAM C-string to use for $ substitution
  116. * @param fstr A ROM F-string to use for $ substitution
  117. */
  118. static void add(FSTR_P const ftpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { add(FTOP(ftpl), index, cstr, fstr); }
  119. static void set(FSTR_P const ftpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { set(); add(ftpl, index, cstr, fstr); }
  120. // Common string ops
  121. static void trim(const char character=' ');
  122. static void rtrim(const char character=' ');
  123. static void ltrim(const char character=' ');
  124. static void truncate(const uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } }
  125. // Accessors
  126. static char *string() { return data; }
  127. static uint16_t width() { return span; }
  128. static uint16_t center(const uint16_t width) { return span > width ? 0 : (width - span) / 2; }
  129. };
  130. extern TFT_String tft_string;