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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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];
  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 _123, -123, _-12, or __-1 format
  69. char *itostr4sign(const int& x) {
  70. int xx = abs(x), sign = 0;
  71. if (xx >= 100) {
  72. conv[1] = DIGIMOD(xx, 100);
  73. conv[2] = DIGIMOD(xx, 10);
  74. }
  75. else {
  76. conv[0] = ' ';
  77. if (xx >= 10) {
  78. sign = 1;
  79. conv[2] = DIGIMOD(xx, 10);
  80. }
  81. else {
  82. conv[1] = ' ';
  83. sign = 2;
  84. }
  85. }
  86. conv[sign] = x < 0 ? '-' : ' ';
  87. conv[3] = DIGIMOD(xx, 1);
  88. conv[4] = '\0';
  89. return conv;
  90. }
  91. // Convert unsigned float to string with 1.23 format
  92. char* ftostr12ns(const float& x) {
  93. long xx = abs(x * 100);
  94. conv[0] = DIGIMOD(xx, 100);
  95. conv[1] = '.';
  96. conv[2] = DIGIMOD(xx, 10);
  97. conv[3] = DIGIMOD(xx, 1);
  98. conv[4] = '\0';
  99. return conv;
  100. }
  101. // Convert signed float to fixed-length string with 023.45 / -23.45 format
  102. char *ftostr32(const float& x) {
  103. long xx = x * 100;
  104. conv[0] = MINUSOR(xx, DIGIMOD(xx, 10000));
  105. conv[1] = DIGIMOD(xx, 1000);
  106. conv[2] = DIGIMOD(xx, 100);
  107. conv[3] = '.';
  108. conv[4] = DIGIMOD(xx, 10);
  109. conv[5] = DIGIMOD(xx, 1);
  110. conv[6] = '\0';
  111. return conv;
  112. }
  113. // Convert float to fixed-length string with +123.4 / -123.4 format
  114. char* ftostr41sign(const float& x) {
  115. int xx = x * 10;
  116. conv[0] = MINUSOR(xx, '+');
  117. conv[1] = DIGIMOD(xx, 1000);
  118. conv[2] = DIGIMOD(xx, 100);
  119. conv[3] = DIGIMOD(xx, 10);
  120. conv[4] = '.';
  121. conv[5] = DIGIMOD(xx, 1);
  122. conv[6] = '\0';
  123. return conv;
  124. }
  125. // Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
  126. char* ftostr43sign(const float& x, char plus/*=' '*/) {
  127. long xx = x * 1000;
  128. conv[0] = xx ? MINUSOR(xx, plus) : ' ';
  129. conv[1] = DIGIMOD(xx, 1000);
  130. conv[2] = '.';
  131. conv[3] = DIGIMOD(xx, 100);
  132. conv[4] = DIGIMOD(xx, 10);
  133. conv[5] = DIGIMOD(xx, 1);
  134. conv[6] = '\0';
  135. return conv;
  136. }
  137. // Convert unsigned float to rj string with 12345 format
  138. char* ftostr5rj(const float& x) {
  139. long xx = abs(x);
  140. conv[0] = RJDIGIT(xx, 10000);
  141. conv[1] = RJDIGIT(xx, 1000);
  142. conv[2] = RJDIGIT(xx, 100);
  143. conv[3] = RJDIGIT(xx, 10);
  144. conv[4] = DIGIMOD(xx, 1);
  145. conv[5] = '\0';
  146. return conv;
  147. }
  148. // Convert signed float to string with +1234.5 format
  149. char* ftostr51sign(const float& x) {
  150. long xx = x * 10;
  151. conv[0] = MINUSOR(xx, '+');
  152. conv[1] = DIGIMOD(xx, 10000);
  153. conv[2] = DIGIMOD(xx, 1000);
  154. conv[3] = DIGIMOD(xx, 100);
  155. conv[4] = DIGIMOD(xx, 10);
  156. conv[5] = '.';
  157. conv[6] = DIGIMOD(xx, 1);
  158. conv[7] = '\0';
  159. return conv;
  160. }
  161. // Convert signed float to string with +123.45 format
  162. char* ftostr52sign(const float& x) {
  163. long xx = x * 100;
  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] = '.';
  169. conv[5] = DIGIMOD(xx, 10);
  170. conv[6] = DIGIMOD(xx, 1);
  171. conv[7] = '\0';
  172. return conv;
  173. }
  174. // Convert signed float to space-padded string with -_23.4_ format
  175. char* ftostr52sp(const float& x) {
  176. long xx = x * 100;
  177. uint8_t dig;
  178. conv[0] = MINUSOR(xx, RJDIGIT(xx, 10000));
  179. conv[1] = RJDIGIT(xx, 1000);
  180. conv[2] = DIGIMOD(xx, 100);
  181. if ((dig = xx % 10)) { // second digit after decimal point?
  182. conv[3] = '.';
  183. conv[4] = DIGIMOD(xx, 10);
  184. conv[5] = DIGIT(dig);
  185. }
  186. else {
  187. if ((dig = (xx / 10) % 10)) { // first digit after decimal point?
  188. conv[3] = '.';
  189. conv[4] = DIGIT(dig);
  190. }
  191. else // nothing after decimal point
  192. conv[3] = conv[4] = ' ';
  193. conv[5] = ' ';
  194. }
  195. conv[6] = '\0';
  196. return conv;
  197. }
  198. #endif // ULTRA_LCD