My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

utility.cpp 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "Marlin.h"
  23. #include "utility.h"
  24. #include "temperature.h"
  25. void safe_delay(millis_t ms) {
  26. while (ms > 50) {
  27. ms -= 50;
  28. delay(50);
  29. thermalManager.manage_heater();
  30. }
  31. delay(ms);
  32. }
  33. #if ENABLED(ULTRA_LCD)
  34. char conv[8] = { 0 };
  35. #define DIGIT(n) ('0' + (n))
  36. #define DIGIMOD(n, f) DIGIT((n)/(f) % 10)
  37. #define RJDIGIT(n, f) ((n) >= (f) ? DIGIMOD(n, f) : ' ')
  38. #define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
  39. // Convert unsigned int to string with 12 format
  40. char* itostr2(const uint8_t& xx) {
  41. conv[5] = DIGIMOD(xx, 10);
  42. conv[6] = DIGIMOD(xx, 1);
  43. return &conv[5];
  44. }
  45. // Convert signed int to rj string with 123 or -12 format
  46. char* itostr3(const int& x) {
  47. int xx = x;
  48. conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
  49. conv[5] = RJDIGIT(xx, 10);
  50. conv[6] = DIGIMOD(xx, 1);
  51. return &conv[4];
  52. }
  53. // Convert unsigned int to lj string with 123 format
  54. char* itostr3left(const int& xx) {
  55. char *str = &conv[6];
  56. *str = DIGIMOD(xx, 1);
  57. if (xx >= 10) {
  58. *(--str) = DIGIMOD(xx, 10);
  59. if (xx >= 100)
  60. *(--str) = DIGIMOD(xx, 100);
  61. }
  62. return str;
  63. }
  64. // Convert signed int to rj string with 1234, _123, -123, _-12, or __-1 format
  65. char *itostr4sign(const int& x) {
  66. const bool neg = x < 0;
  67. const int xx = neg ? -x : x;
  68. if (x >= 1000) {
  69. conv[3] = DIGIMOD(xx, 1000);
  70. conv[4] = DIGIMOD(xx, 100);
  71. conv[5] = DIGIMOD(xx, 10);
  72. }
  73. else {
  74. if (xx >= 100) {
  75. conv[3] = neg ? '-' : ' ';
  76. conv[4] = DIGIMOD(xx, 100);
  77. conv[5] = DIGIMOD(xx, 10);
  78. }
  79. else {
  80. conv[4] = ' ';
  81. if (xx >= 10) {
  82. conv[4] = neg ? '-' : ' ';
  83. conv[5] = DIGIMOD(xx, 10);
  84. }
  85. else {
  86. conv[4] = ' ';
  87. conv[5] = neg ? '-' : ' ';
  88. }
  89. }
  90. }
  91. conv[6] = DIGIMOD(xx, 1);
  92. return &conv[3];
  93. }
  94. // Convert unsigned float to string with 1.23 format
  95. char* ftostr12ns(const float& x) {
  96. const long xx = (x < 0 ? -x : x) * 100;
  97. conv[3] = DIGIMOD(xx, 100);
  98. conv[4] = '.';
  99. conv[5] = DIGIMOD(xx, 10);
  100. conv[6] = DIGIMOD(xx, 1);
  101. return &conv[3];
  102. }
  103. // Convert signed float to fixed-length string with 023.45 / -23.45 format
  104. char *ftostr32(const float& x) {
  105. long xx = x * 100;
  106. conv[1] = MINUSOR(xx, DIGIMOD(xx, 10000));
  107. conv[2] = DIGIMOD(xx, 1000);
  108. conv[3] = DIGIMOD(xx, 100);
  109. conv[4] = '.';
  110. conv[5] = DIGIMOD(xx, 10);
  111. conv[6] = DIGIMOD(xx, 1);
  112. return &conv[1];
  113. }
  114. #if ENABLED(LCD_DECIMAL_SMALL_XY)
  115. // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
  116. char *ftostr4sign(const float& fx) {
  117. const int x = fx * 10;
  118. if (!WITHIN(x, -99, 999)) return itostr4sign((int)fx);
  119. const bool neg = x < 0;
  120. const int xx = neg ? -x : x;
  121. conv[3] = neg ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' ');
  122. conv[4] = DIGIMOD(xx, 10);
  123. conv[5] = '.';
  124. conv[6] = DIGIMOD(xx, 1);
  125. return &conv[3];
  126. }
  127. #endif // LCD_DECIMAL_SMALL_XY
  128. // Convert float to fixed-length string with +123.4 / -123.4 format
  129. char* ftostr41sign(const float& x) {
  130. int xx = x * 10;
  131. conv[1] = MINUSOR(xx, '+');
  132. conv[2] = DIGIMOD(xx, 1000);
  133. conv[3] = DIGIMOD(xx, 100);
  134. conv[4] = DIGIMOD(xx, 10);
  135. conv[5] = '.';
  136. conv[6] = DIGIMOD(xx, 1);
  137. return &conv[1];
  138. }
  139. // Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
  140. char* ftostr43sign(const float& x, char plus/*=' '*/) {
  141. long xx = x * 1000;
  142. conv[1] = xx ? MINUSOR(xx, plus) : ' ';
  143. conv[2] = DIGIMOD(xx, 1000);
  144. conv[3] = '.';
  145. conv[4] = DIGIMOD(xx, 100);
  146. conv[5] = DIGIMOD(xx, 10);
  147. conv[6] = DIGIMOD(xx, 1);
  148. return &conv[1];
  149. }
  150. // Convert unsigned float to rj string with 12345 format
  151. char* ftostr5rj(const float& x) {
  152. const long xx = x < 0 ? -x : x;
  153. conv[2] = RJDIGIT(xx, 10000);
  154. conv[3] = RJDIGIT(xx, 1000);
  155. conv[4] = RJDIGIT(xx, 100);
  156. conv[5] = RJDIGIT(xx, 10);
  157. conv[6] = DIGIMOD(xx, 1);
  158. return &conv[2];
  159. }
  160. // Convert signed float to string with +1234.5 format
  161. char* ftostr51sign(const float& x) {
  162. long xx = x * 10;
  163. conv[0] = MINUSOR(xx, '+');
  164. conv[1] = DIGIMOD(xx, 10000);
  165. conv[2] = DIGIMOD(xx, 1000);
  166. conv[3] = DIGIMOD(xx, 100);
  167. conv[4] = DIGIMOD(xx, 10);
  168. conv[5] = '.';
  169. conv[6] = DIGIMOD(xx, 1);
  170. return conv;
  171. }
  172. // Convert signed float to string with +123.45 format
  173. char* ftostr52sign(const float& x) {
  174. long xx = x * 100;
  175. conv[0] = MINUSOR(xx, '+');
  176. conv[1] = DIGIMOD(xx, 10000);
  177. conv[2] = DIGIMOD(xx, 1000);
  178. conv[3] = DIGIMOD(xx, 100);
  179. conv[4] = '.';
  180. conv[5] = DIGIMOD(xx, 10);
  181. conv[6] = DIGIMOD(xx, 1);
  182. return conv;
  183. }
  184. // Convert unsigned float to string with 1234.56 format omitting trailing zeros
  185. char* ftostr62rj(const float& x) {
  186. const long xx = (x < 0 ? -x : x) * 100;
  187. conv[0] = RJDIGIT(xx, 100000);
  188. conv[1] = RJDIGIT(xx, 10000);
  189. conv[2] = RJDIGIT(xx, 1000);
  190. conv[3] = DIGIMOD(xx, 100);
  191. conv[4] = '.';
  192. conv[5] = DIGIMOD(xx, 10);
  193. conv[6] = DIGIMOD(xx, 1);
  194. return conv;
  195. }
  196. // Convert signed float to space-padded string with -_23.4_ format
  197. char* ftostr52sp(const float& x) {
  198. long xx = x * 100;
  199. uint8_t dig;
  200. conv[1] = MINUSOR(xx, RJDIGIT(xx, 10000));
  201. conv[2] = RJDIGIT(xx, 1000);
  202. conv[3] = DIGIMOD(xx, 100);
  203. if ((dig = xx % 10)) { // second digit after decimal point?
  204. conv[4] = '.';
  205. conv[5] = DIGIMOD(xx, 10);
  206. conv[6] = DIGIT(dig);
  207. }
  208. else {
  209. if ((dig = (xx / 10) % 10)) { // first digit after decimal point?
  210. conv[4] = '.';
  211. conv[5] = DIGIT(dig);
  212. }
  213. else // nothing after decimal point
  214. conv[4] = conv[5] = ' ';
  215. conv[6] = ' ';
  216. }
  217. return &conv[1];
  218. }
  219. #endif // ULTRA_LCD