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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_WIRED_LCD && !HAS_GRAPHICAL_TFT
  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 '0'....'10' for indexes 0 - 10
  35. * ~ displays '1'....'11' for indexes 0 - 10
  36. * * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
  37. */
  38. 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*/) {
  39. const uint8_t prop = USE_WIDE_GLYPH ? 2 : 1;
  40. uint8_t *p = (uint8_t*)pstr;
  41. int8_t n = maxlen;
  42. while (n > 0) {
  43. wchar_t ch;
  44. p = get_utf8_value_cb(p, read_byte_rom, &ch);
  45. if (!ch) break;
  46. if (ch == '=' || ch == '~' || ch == '*') {
  47. if (ind >= 0) {
  48. if (ch == '*') { lcd_put_wchar('E'); n--; }
  49. if (n) {
  50. int8_t inum = ind + ((ch == '=') ? 0 : LCD_FIRST_TOOL);
  51. if (inum >= 10) {
  52. lcd_put_wchar('0' + (inum / 10)); n--;
  53. inum %= 10;
  54. }
  55. if (n) { lcd_put_wchar('0' + inum); n--; }
  56. }
  57. }
  58. else {
  59. PGM_P const b = ind == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED);
  60. n -= lcd_put_u8str_max_P(b, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
  61. }
  62. if (n) {
  63. n -= lcd_put_u8str_max_P((PGM_P)p, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
  64. break;
  65. }
  66. }
  67. else if (ch == '$' && inStr) {
  68. n -= lcd_put_u8str_max_P(inStr, n * (MENU_FONT_WIDTH)) / (MENU_FONT_WIDTH);
  69. }
  70. else {
  71. lcd_put_wchar(ch);
  72. n -= ch > 255 ? prop : 1;
  73. }
  74. }
  75. return n;
  76. }
  77. // Calculate UTF8 width with a simple check
  78. int calculateWidth(PGM_P const pstr) {
  79. if (!USE_WIDE_GLYPH) return utf8_strlen_P(pstr) * MENU_FONT_WIDTH;
  80. const uint8_t prop = 2;
  81. uint8_t *p = (uint8_t*)pstr;
  82. int n = 0;
  83. do {
  84. wchar_t ch;
  85. p = get_utf8_value_cb(p, read_byte_rom, &ch);
  86. if (!ch) break;
  87. n += (ch > 255) ? prop : 1;
  88. } while (1);
  89. return n * MENU_FONT_WIDTH;
  90. }
  91. #endif // HAS_WIRED_LCD