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

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