My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

lcdprint.h 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. /**
  23. * @file lcdprint.h
  24. * @brief LCD print api
  25. * @author Yunhui Fu (yhfudev@gmail.com)
  26. * @version 1.0
  27. * @date 2016-08-19
  28. * @copyright GPL/BSD
  29. */
  30. #pragma once
  31. #include "fontutils.h"
  32. #include "../inc/MarlinConfig.h"
  33. #if IS_DWIN_MARLINUI
  34. #include "e3v2/marlinui/marlinui_dwin.h"
  35. #define LCD_PIXEL_WIDTH DWIN_WIDTH
  36. #define LCD_PIXEL_HEIGHT DWIN_HEIGHT
  37. #define LCD_WIDTH ((LCD_PIXEL_WIDTH) / (MENU_FONT_WIDTH))
  38. #define LCD_HEIGHT ((LCD_PIXEL_HEIGHT) / (MENU_LINE_HEIGHT))
  39. // The DWIN lcd_moveto function uses row / column, not pixels
  40. #define LCD_COL_X(col) (col)
  41. #define LCD_ROW_Y(row) (row)
  42. #define LCD_COL_X_RJ(len) (LCD_WIDTH - LCD_COL_X(len))
  43. #elif HAS_MARLINUI_U8GLIB
  44. #include "dogm/u8g_fontutf8.h"
  45. typedef u8g_uint_t lcd_uint_t;
  46. typedef u8g_int_t lcd_int_t;
  47. // Only Western languages support big / small fonts
  48. #if DISABLED(DISPLAY_CHARSET_ISO10646_1)
  49. #undef USE_BIG_EDIT_FONT
  50. #undef USE_SMALL_INFOFONT
  51. #endif
  52. #define MENU_FONT_NAME ISO10646_1_5x7
  53. #define MENU_FONT_WIDTH 6
  54. #define MENU_FONT_ASCENT 10
  55. #define MENU_FONT_DESCENT 2
  56. #define MENU_FONT_HEIGHT (MENU_FONT_ASCENT + MENU_FONT_DESCENT)
  57. #if ENABLED(USE_BIG_EDIT_FONT)
  58. #define EDIT_FONT_NAME u8g_font_9x18
  59. #define EDIT_FONT_WIDTH 9
  60. #define EDIT_FONT_ASCENT 10
  61. #define EDIT_FONT_DESCENT 3
  62. #else
  63. #define EDIT_FONT_NAME MENU_FONT_NAME
  64. #define EDIT_FONT_WIDTH MENU_FONT_WIDTH
  65. #define EDIT_FONT_ASCENT MENU_FONT_ASCENT
  66. #define EDIT_FONT_DESCENT MENU_FONT_DESCENT
  67. #endif
  68. #define EDIT_FONT_HEIGHT (EDIT_FONT_ASCENT + EDIT_FONT_DESCENT)
  69. // Get the Ascent, Descent, and total Height for the Info Screen font
  70. #if ENABLED(USE_SMALL_INFOFONT)
  71. extern const u8g_fntpgm_uint8_t u8g_font_6x9[];
  72. #define INFO_FONT_ASCENT 7
  73. #else
  74. #define INFO_FONT_ASCENT 8
  75. #endif
  76. #define INFO_FONT_DESCENT 2
  77. #define INFO_FONT_HEIGHT (INFO_FONT_ASCENT + INFO_FONT_DESCENT)
  78. #define INFO_FONT_WIDTH 6
  79. // Graphical LCD uses the menu font size for cursor positioning
  80. #define LCD_COL_X(col) (( (col)) * (MENU_FONT_WIDTH))
  81. #define LCD_ROW_Y(row) ((1 + (row)) * (MENU_LINE_HEIGHT))
  82. #else
  83. #define _UxGT(a) a
  84. typedef uint8_t lcd_uint_t;
  85. typedef int8_t lcd_int_t;
  86. #define MENU_FONT_WIDTH 1
  87. #define MENU_FONT_HEIGHT 1
  88. #define EDIT_FONT_WIDTH 1
  89. #define EDIT_FONT_HEIGHT 1
  90. #define INFO_FONT_WIDTH 1
  91. #define INFO_FONT_HEIGHT 1
  92. #define LCD_PIXEL_WIDTH LCD_WIDTH
  93. #define LCD_PIXEL_HEIGHT LCD_HEIGHT
  94. // Character LCD uses direct cursor positioning
  95. #define LCD_COL_X(col) (col)
  96. #define LCD_ROW_Y(row) (row)
  97. #endif
  98. #ifndef MENU_LINE_HEIGHT
  99. #define MENU_LINE_HEIGHT MENU_FONT_HEIGHT
  100. #endif
  101. #ifndef LCD_COL_X_RJ
  102. #define LCD_COL_X_RJ(len) (LCD_PIXEL_WIDTH - LCD_COL_X(len))
  103. #endif
  104. #define SETCURSOR(col, row) lcd_moveto(LCD_COL_X(col), LCD_ROW_Y(row))
  105. #define SETCURSOR_RJ(len, row) lcd_moveto(LCD_COL_X_RJ(len), LCD_ROW_Y(row))
  106. #define SETCURSOR_X(col) SETCURSOR(col, _lcdLineNr)
  107. #define SETCURSOR_X_RJ(len) SETCURSOR_RJ(len, _lcdLineNr)
  108. int lcd_glyph_height();
  109. /**
  110. * @brief Draw a UTF-8 character
  111. *
  112. * @param utf8_str : the UTF-8 character
  113. * @param max_length : the output width limit (in pixels on GLCD)
  114. *
  115. * @return the output width (in pixels on GLCD)
  116. */
  117. int lcd_put_wchar_max(const wchar_t c, const pixel_len_t max_length);
  118. /**
  119. * @brief Draw a SRAM UTF-8 string
  120. *
  121. * @param utf8_str : the UTF-8 string
  122. * @param max_length : the output width limit (in pixels on GLCD)
  123. *
  124. * @return the output width (in pixels on GLCD)
  125. */
  126. int lcd_put_u8str_max(const char *utf8_str, const pixel_len_t max_length);
  127. /**
  128. * Change the print cursor position
  129. */
  130. void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row);
  131. /**
  132. * @brief Draw a ROM UTF-8 string
  133. *
  134. * @param pstr : the ROM UTF-8 string
  135. * @param max_length : the output width limit (in pixels on GLCD)
  136. *
  137. * @return the output width (in pixels on GLCD)
  138. */
  139. int lcd_put_u8str_max_P(PGM_P pstr, const pixel_len_t max_length);
  140. inline int lcd_put_u8str_max_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P pstr, const pixel_len_t max_length) {
  141. lcd_moveto(col, row);
  142. return lcd_put_u8str_max_P(pstr, max_length);
  143. }
  144. inline int lcd_put_u8str_max(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const fstr, const pixel_len_t max_length) {
  145. return lcd_put_u8str_max_P(col, row, FTOP(fstr), max_length);
  146. }
  147. /**
  148. * @brief Draw an integer, left-justified
  149. *
  150. * @param i : the integer
  151. */
  152. void lcd_put_int(const int i);
  153. inline void lcd_put_int(const lcd_uint_t col, const lcd_uint_t row, const int i) {
  154. lcd_moveto(col, row);
  155. lcd_put_int(i);
  156. }
  157. /**
  158. * @brief Draw a ROM UTF-8 string
  159. *
  160. * @param i : the integer
  161. */
  162. inline int lcd_put_u8str_P(PGM_P const pstr) { return lcd_put_u8str_max_P(pstr, PIXEL_LEN_NOLIMIT); }
  163. inline int lcd_put_u8str_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P const pstr) {
  164. lcd_moveto(col, row);
  165. return lcd_put_u8str_P(pstr);
  166. }
  167. /**
  168. * @brief Draw a ROM UTF-8 F-string
  169. *
  170. * @param fstr The F-string pointer
  171. * @return the output width (in pixels on GLCD)
  172. */
  173. inline int lcd_put_u8str(FSTR_P const fstr) { return lcd_put_u8str_P(FTOP(fstr)); }
  174. inline int lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const fstr) {
  175. return lcd_put_u8str_P(col, row, FTOP(fstr));
  176. }
  177. /**
  178. * @brief Draw a string with optional substitution
  179. * @details Print a string with optional substitutions:
  180. * $ displays the clipped string given by fstr or cstr
  181. * = displays '0'....'10' for indexes 0 - 10
  182. * ~ displays '1'....'11' for indexes 0 - 10
  183. * * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
  184. * @ displays an axis name such as XYZUVW, or E for an extruder
  185. *
  186. * @param ptpl A ROM string (template)
  187. * @param ind An index value to use for = ~ * substitution
  188. * @param cstr An SRAM C-string to use for $ substitution
  189. * @param fstr A ROM F-string to use for $ substitution
  190. * @param maxlen The maximum size of the string (in pixels on GLCD)
  191. * @return the output width (in pixels on GLCD)
  192. */
  193. lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH);
  194. inline lcd_uint_t lcd_put_u8str_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P const ptpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
  195. lcd_moveto(col, row);
  196. return lcd_put_u8str_P(ptpl, ind, cstr, fstr, maxlen);
  197. }
  198. /**
  199. * @brief Draw a ROM UTF-8 F-string with optional substitution
  200. * @details (See above)
  201. *
  202. * @param ftpl A ROM F-string (template)
  203. * @param ind An index value to use for = ~ * substitution
  204. * @param cstr An SRAM C-string to use for $ substitution
  205. * @param fstr A ROM F-string to use for $ substitution
  206. * @param maxlen The maximum size of the string (in pixels on GLCD)
  207. * @return the output width (in pixels on GLCD)
  208. */
  209. inline lcd_uint_t lcd_put_u8str(FSTR_P const ftpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
  210. return lcd_put_u8str_P(FTOP(ftpl), ind, cstr, fstr, maxlen);
  211. }
  212. /**
  213. * @param col
  214. * @param row
  215. */
  216. inline lcd_uint_t lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const ftpl, const int8_t ind, const char *cstr=nullptr, FSTR_P const fstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
  217. return lcd_put_u8str_P(col, row, FTOP(ftpl), ind, cstr, fstr, maxlen);
  218. }
  219. /**
  220. * @brief Draw a SRAM string with no width limit
  221. *
  222. * @param str The UTF-8 string
  223. * @return the output width (in pixels on GLCD)
  224. */
  225. inline int lcd_put_u8str(const char * const str) { return lcd_put_u8str_max(str, PIXEL_LEN_NOLIMIT); }
  226. /**
  227. * @param col
  228. * @param row
  229. */
  230. inline int lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, const char * const str) {
  231. lcd_moveto(col, row);
  232. return lcd_put_u8str(str);
  233. }
  234. /**
  235. * @brief Draw a UTF-8 character with no width limit
  236. *
  237. * @param c The wchar to draw
  238. * @return the output width (in pixels on GLCD)
  239. */
  240. inline int lcd_put_wchar(const wchar_t c) { return lcd_put_wchar_max(c, PIXEL_LEN_NOLIMIT); }
  241. /**
  242. * @param col
  243. * @param row
  244. */
  245. inline int lcd_put_wchar(const lcd_uint_t col, const lcd_uint_t row, const wchar_t c) {
  246. lcd_moveto(col, row);
  247. return lcd_put_wchar(c);
  248. }
  249. /**
  250. * @brief Calculate the width of a ROM UTF-8 string (in pixels on GLCD)
  251. *
  252. * @param pstr The ROM-based UTF-8 string
  253. * @return the string width (in pixels on GLCD)
  254. */
  255. int calculateWidth(PGM_P const pstr);
  256. /**
  257. * @brief Calculate the width of a ROM UTF-8 string (in pixels on GLCD)
  258. *
  259. * @param pstr The ROM-based UTF-8 string
  260. * @return the string width (in pixels on GLCD)
  261. */
  262. inline int calculateWidth(FSTR_P const fstr) { return calculateWidth(FTOP(fstr)); }