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.

utility.cpp 6.3KB

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