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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_ind_P
  31. *
  32. * Print a string with an index substituted within it:
  33. *
  34. * $ displays the clipped C-string given by the inStr argument
  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_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const inStr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) {
  41. const uint8_t prop = USE_WIDE_GLYPH ? 2 : 1;
  42. uint8_t *p = (uint8_t*)pstr;
  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 == '$' && inStr) {
  70. n -= lcd_put_u8str_max_P(inStr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
  71. }
  72. else if (ch == '@') {
  73. lcd_put_wchar(AXIS_CHAR(ind));
  74. n--;
  75. }
  76. else {
  77. lcd_put_wchar(ch);
  78. n -= ch > 255 ? prop : 1;
  79. }
  80. }
  81. return n;
  82. }
  83. // Calculate UTF8 width with a simple check
  84. int calculateWidth(PGM_P const pstr) {
  85. if (!USE_WIDE_GLYPH) return utf8_strlen_P(pstr) * MENU_FONT_WIDTH;
  86. const uint8_t prop = 2;
  87. uint8_t *p = (uint8_t*)pstr;
  88. int n = 0;
  89. do {
  90. wchar_t ch;
  91. p = get_utf8_value_cb(p, read_byte_rom, &ch);
  92. if (!ch) break;
  93. n += (ch > 255) ? prop : 1;
  94. } while (1);
  95. return n * MENU_FONT_WIDTH;
  96. }
  97. #endif // HAS_LCDPRINT