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.h 5.2KB

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