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.

string_format.cpp 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*********************
  2. * string_format.cpp *
  3. *********************/
  4. /****************************************************************************
  5. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  6. * *
  7. * This program is free software: you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU General Public License for more details. *
  16. * *
  17. * To view a copy of the GNU General Public License, go to the following *
  18. * location: <https://www.gnu.org/licenses/>. *
  19. ****************************************************************************/
  20. #include "../config.h"
  21. #if ENABLED(TOUCH_UI_FTDI_EVE)
  22. #include "../screens.h"
  23. #define ROUND(val) uint16_t((val)+0.5)
  24. #pragma GCC diagnostic push
  25. #if GCC_VERSION <= 50000
  26. #pragma GCC diagnostic ignored "-Wno-format"
  27. #endif
  28. /**
  29. * Formats a temperature string (e.g. "100°C")
  30. */
  31. void format_temp(char *str, const_celsius_float_t t1) {
  32. #ifdef TOUCH_UI_LCD_TEMP_PRECISION
  33. char num1[7];
  34. dtostrf(t1, 4 + TOUCH_UI_LCD_TEMP_PRECISION, TOUCH_UI_LCD_TEMP_PRECISION, num1);
  35. sprintf_P(str, PSTR("%s" S_FMT), num1, GET_TEXT(MSG_UNITS_C));
  36. #else
  37. sprintf_P(str, PSTR("%3d" S_FMT), ROUND(t1), GET_TEXT(MSG_UNITS_C));
  38. #endif
  39. }
  40. /**
  41. * Formats a temperature string for an idle heater (e.g. "100 °C / idle")
  42. */
  43. void format_temp_and_idle(char *str, const_celsius_float_t t1) {
  44. #ifdef TOUCH_UI_LCD_TEMP_PRECISION
  45. char num1[7];
  46. dtostrf(t1, 4 + TOUCH_UI_LCD_TEMP_PRECISION, TOUCH_UI_LCD_TEMP_PRECISION, num1);
  47. sprintf_P(str, PSTR("%s" S_FMT " / " S_FMT), num1, GET_TEXT(MSG_UNITS_C), GET_TEXT(MSG_IDLE));
  48. #else
  49. sprintf_P(str, PSTR("%3d" S_FMT " / " S_FMT), ROUND(t1), GET_TEXT(MSG_UNITS_C), GET_TEXT(MSG_IDLE));
  50. #endif
  51. }
  52. /**
  53. * Formats a temperature string for an active heater (e.g. "100 / 200°C")
  54. */
  55. void format_temp_and_temp(char *str, const_celsius_float_t t1, const_celsius_float_t t2) {
  56. #ifdef TOUCH_UI_LCD_TEMP_PRECISION
  57. char num1[7], num2[7];
  58. dtostrf(t1, 4 + TOUCH_UI_LCD_TEMP_PRECISION, TOUCH_UI_LCD_TEMP_PRECISION, num1);
  59. dtostrf(t2, 4 + TOUCH_UI_LCD_TEMP_PRECISION, TOUCH_UI_LCD_TEMP_PRECISION, num2);
  60. sprintf_P(str, PSTR("%s / %s" S_FMT), num1, num2, GET_TEXT(MSG_UNITS_C));
  61. #else
  62. sprintf_P(str, PSTR("%3d / %3d" S_FMT), ROUND(t1), ROUND(t2), GET_TEXT(MSG_UNITS_C));
  63. #endif
  64. }
  65. /**
  66. * Formats a temperature string for a material (e.g. "100°C (PLA)")
  67. */
  68. void format_temp_and_material(char *str, const_celsius_float_t t1, const char *material) {
  69. #ifdef TOUCH_UI_LCD_TEMP_PRECISION
  70. char num1[7];
  71. dtostrf(t1, 4 + TOUCH_UI_LCD_TEMP_PRECISION, TOUCH_UI_LCD_TEMP_PRECISION, num1);
  72. sprintf_P(str, PSTR("%s" S_FMT " (" S_FMT ")"), num1, GET_TEXT(MSG_UNITS_C), material);
  73. #else
  74. sprintf_P(str, PSTR("%3d" S_FMT " (" S_FMT ")"), ROUND(t1), GET_TEXT(MSG_UNITS_C), material);
  75. #endif
  76. }
  77. /**
  78. * Formats a position value (e.g. "10 mm")
  79. */
  80. void format_position(char *str, float p, uint8_t decimals) {
  81. dtostrf(p, 4 + decimals, decimals, str);
  82. strcat_P(str, PSTR(" "));
  83. strcat_P(str, GET_TEXT(MSG_UNITS_MM));
  84. }
  85. /**
  86. * Formats a position vector (e.g. "10; 20; 30 mm")
  87. */
  88. void format_position(char *str, float x, float y, float z) {
  89. char num1[7], num2[7], num3[7];
  90. dtostrf(x, 4, 2, num1);
  91. dtostrf(y, 4, 2, num2);
  92. dtostrf(z, 4, 2, num3);
  93. sprintf_P(str, PSTR("%s; %s; %s " S_FMT), num1, num2, num3, GET_TEXT(MSG_UNITS_MM));
  94. }
  95. #pragma GCC diagnostic pop
  96. #endif // TOUCH_UI_FTDI_EVE