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 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #include <stdint.h>
  24. extern const uint8_t ISO10646_1_5x7[];
  25. extern const uint8_t font10x20[];
  26. extern const uint8_t Helvetica12Bold[];
  27. extern const uint8_t Helvetica14[], Helvetica14_symbols[];
  28. extern const uint8_t Helvetica18[], Helvetica18_symbols[];
  29. #define NO_GLYPH 0xFF
  30. typedef struct __attribute__((__packed__)) {
  31. uint8_t Format;
  32. uint8_t BBXWidth;
  33. uint8_t BBXHeight;
  34. int8_t BBXOffsetX;
  35. int8_t BBXOffsetY;
  36. uint8_t CapitalAHeight;
  37. uint16_t Encoding65Pos;
  38. uint16_t Encoding97Pos;
  39. uint8_t FontStartEncoding;
  40. uint8_t FontEndEncoding;
  41. int8_t LowerGDescent;
  42. int8_t FontAscent;
  43. int8_t FontDescent;
  44. int8_t FontXAscent;
  45. int8_t FontXDescent;
  46. } font_t;
  47. typedef struct __attribute__((__packed__)) {
  48. uint8_t BBXWidth;
  49. uint8_t BBXHeight;
  50. uint8_t DataSize;
  51. int8_t DWidth;
  52. int8_t BBXOffsetX;
  53. int8_t BBXOffsetY;
  54. } glyph_t;
  55. #define MAX_STRING_LENGTH 64
  56. class TFT_String {
  57. private:
  58. static glyph_t *glyphs[256];
  59. static font_t *font_header;
  60. static uint8_t data[MAX_STRING_LENGTH + 1];
  61. static uint16_t span; // in pixels
  62. static uint8_t length; // in characters
  63. static void add_character(uint8_t character);
  64. static void eol() { data[length] = 0x00; }
  65. public:
  66. static void set_font(const uint8_t *font);
  67. static void add_glyphs(const uint8_t *font);
  68. static font_t *font() { return font_header; };
  69. static uint16_t font_height() { return font_header->FontAscent - font_header->FontDescent; }
  70. static glyph_t *glyph(uint8_t character) { return glyphs[character] ?: glyphs[0x3F]; } /* Use '?' for unknown glyphs */
  71. static glyph_t *glyph(uint8_t *character) { return glyph(*character); }
  72. static void set();
  73. static void add(uint8_t character) { add_character(character); eol(); }
  74. static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH);
  75. static void add(uint8_t *string, int8_t index, uint8_t *itemString=nullptr);
  76. static void set(uint8_t *string) { set(); add(string); };
  77. static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); };
  78. static void set(const char *string) { set((uint8_t *)string); }
  79. static void set(const char *string, int8_t index, const char *itemString=nullptr) { set((uint8_t *)string, index, itemString); }
  80. static void add(const char *string) { add((uint8_t *)string); }
  81. static void trim(uint8_t character=0x20);
  82. static void rtrim(uint8_t character=0x20);
  83. static void ltrim(uint8_t character=0x20);
  84. static void truncate(uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } }
  85. static uint16_t width() { return span; }
  86. static uint8_t *string() { return data; }
  87. static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; }
  88. };
  89. extern TFT_String tft_string;