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.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. * lcdprint.cpp
  24. */
  25. #include "../inc/MarlinConfigPre.h"
  26. #if HAS_LCDPRINT
  27. #include "marlinui.h"
  28. #include "lcdprint.h"
  29. /**
  30. * lcd_put_u8str_P
  31. *
  32. * Print a string with optional substitutions:
  33. *
  34. * $ displays the clipped string given by fstr or cstr
  35. * = displays '0'....'10' for indexes 0 - 10
  36. * ~ displays '1'....'11' for indexes 0 - 10
  37. * * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
  38. * @ displays an axis name such as XYZUVW, or E for an extruder
  39. */
  40. 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*/) {
  41. const uint8_t prop = USE_WIDE_GLYPH ? 2 : 1;
  42. const uint8_t *p = (uint8_t*)ptpl;
  43. int8_t n = maxlen;
  44. while (n > 0) {
  45. wchar_t ch;
  46. p = get_utf8_value_cb(p, read_byte_rom, &ch);
  47. if (!ch) break;
  48. if (ch == '=' || ch == '~' || ch == '*') {
  49. if (ind >= 0) {
  50. if (ch == '*') { lcd_put_wchar('E'); n--; }
  51. if (n) {
  52. int8_t inum = ind + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
  53. if (inum >= 10) {
  54. lcd_put_wchar('0' + (inum / 10)); n--;
  55. inum %= 10;
  56. }
  57. if (n) { lcd_put_wchar('0' + inum); n--; }
  58. }
  59. }
  60. else {
  61. PGM_P const b = ind == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED);
  62. n -= lcd_put_u8str_max_P(b, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
  63. }
  64. if (n) {
  65. n -= lcd_put_u8str_max_P((PGM_P)p, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
  66. break;
  67. }
  68. }
  69. else if (ch == '$' && fstr) {
  70. n -= lcd_put_u8str_max_P(FTOP(fstr), n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
  71. }
  72. else if (ch == '$' && cstr) {
  73. n -= lcd_put_u8str_max(cstr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
  74. }
  75. else if (ch == '@') {
  76. lcd_put_wchar(AXIS_CHAR(ind));
  77. n--;
  78. }
  79. else {
  80. lcd_put_wchar(ch);
  81. n -= ch > 255 ? prop : 1;
  82. }
  83. }
  84. return n;
  85. }
  86. // Calculate UTF8 width with a simple check
  87. int calculateWidth(PGM_P const pstr) {
  88. if (!USE_WIDE_GLYPH) return utf8_strlen_P(pstr) * MENU_FONT_WIDTH;
  89. const uint8_t prop = 2;
  90. const uint8_t *p = (uint8_t*)pstr;
  91. int n = 0;
  92. do {
  93. wchar_t ch;
  94. p = get_utf8_value_cb(p, read_byte_rom, &ch);
  95. if (!ch) break;
  96. n += (ch > 255) ? prop : 1;
  97. } while (1);
  98. return n * MENU_FONT_WIDTH;
  99. }
  100. #endif // HAS_LCDPRINT