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.

lcdprint.h 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length);
  110. /**
  111. * @brief Draw a UTF-8 string
  112. *
  113. * @param utf8_str : the UTF-8 string
  114. * @param max_length : the pixel length of the string allowed (or number of slots in HD44780)
  115. *
  116. * @return the pixel width
  117. *
  118. * Draw a UTF-8 string
  119. */
  120. int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length);
  121. /**
  122. * Set the print baseline position
  123. */
  124. void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row);
  125. /**
  126. * @brief Draw a ROM UTF-8 string
  127. *
  128. * @param utf8_pstr : the ROM UTF-8 string
  129. * @param max_length : the pixel length of the string allowed (or number of slots in HD44780)
  130. *
  131. * @return the pixel width
  132. *
  133. * Draw a ROM UTF-8 string
  134. */
  135. int lcd_put_u8str_max_P(PGM_P utf8_pstr, pixel_len_t max_length);
  136. inline int lcd_put_u8str_max_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P utf8_pstr, pixel_len_t max_length) {
  137. lcd_moveto(col, row);
  138. return lcd_put_u8str_max_P(utf8_pstr, max_length);
  139. }
  140. inline int lcd_put_u8str_max(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const utf8_fstr, pixel_len_t max_length) {
  141. return lcd_put_u8str_max_P(col, row, FTOP(utf8_fstr), max_length);
  142. }
  143. void lcd_put_int(const int i);
  144. inline void lcd_put_int(const lcd_uint_t col, const lcd_uint_t row, const int i) {
  145. lcd_moveto(col, row);
  146. lcd_put_int(i);
  147. }
  148. inline int lcd_put_u8str_P(PGM_P const pstr) { return lcd_put_u8str_max_P(pstr, PIXEL_LEN_NOLIMIT); }
  149. inline int lcd_put_u8str_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P const pstr) {
  150. lcd_moveto(col, row);
  151. return lcd_put_u8str_P(pstr);
  152. }
  153. inline int lcd_put_u8str(FSTR_P const fstr) { return lcd_put_u8str_P(FTOP(fstr)); }
  154. inline int lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const fstr) {
  155. return lcd_put_u8str_P(col, row, FTOP(fstr));
  156. }
  157. lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const inStr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH);
  158. inline lcd_uint_t lcd_put_u8str_ind_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P const pstr, const int8_t ind, PGM_P const inStr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
  159. lcd_moveto(col, row);
  160. return lcd_put_u8str_ind_P(pstr, ind, inStr, maxlen);
  161. }
  162. inline lcd_uint_t lcd_put_u8str_ind(FSTR_P const fstr, const int8_t ind, FSTR_P const inFstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
  163. return lcd_put_u8str_ind_P(FTOP(fstr), ind, FTOP(inFstr), maxlen);
  164. }
  165. inline lcd_uint_t lcd_put_u8str_ind(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const fstr, const int8_t ind, FSTR_P const inFstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
  166. return lcd_put_u8str_ind_P(col, row, FTOP(fstr), ind, FTOP(inFstr), maxlen);
  167. }
  168. inline int lcd_put_u8str(const char * const str) { return lcd_put_u8str_max(str, PIXEL_LEN_NOLIMIT); }
  169. inline int lcd_put_u8str(const lcd_uint_t col, const lcd_uint_t row, const char * const str) {
  170. lcd_moveto(col, row);
  171. return lcd_put_u8str(str);
  172. }
  173. inline int lcd_put_wchar(const wchar_t c) { return lcd_put_wchar_max(c, PIXEL_LEN_NOLIMIT); }
  174. inline int lcd_put_wchar(const lcd_uint_t col, const lcd_uint_t row, const wchar_t c) {
  175. lcd_moveto(col, row);
  176. return lcd_put_wchar(c);
  177. }
  178. int calculateWidth(PGM_P const pstr);