My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

utility.cpp 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #if ENABLED(LCD_DECIMAL_SMALL_XY)
  121. // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
  122. char *ftostr4sign(const float& fx) {
  123. int x = fx * 10;
  124. if (x <= -100 || x >= 1000) return itostr4sign((int)fx);
  125. int xx = abs(x);
  126. conv[0] = x < 0 ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' ');
  127. conv[1] = DIGIMOD(xx, 10);
  128. conv[2] = '.';
  129. conv[3] = DIGIMOD(xx, 1);
  130. conv[4] = '\0';
  131. return conv;
  132. }
  133. #endif // LCD_DECIMAL_SMALL_XY
  134. // Convert float to fixed-length string with +123.4 / -123.4 format
  135. char* ftostr41sign(const float& x) {
  136. int xx = x * 10;
  137. conv[0] = MINUSOR(xx, '+');
  138. conv[1] = DIGIMOD(xx, 1000);
  139. conv[2] = DIGIMOD(xx, 100);
  140. conv[3] = DIGIMOD(xx, 10);
  141. conv[4] = '.';
  142. conv[5] = DIGIMOD(xx, 1);
  143. conv[6] = '\0';
  144. return conv;
  145. }
  146. // Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
  147. char* ftostr43sign(const float& x, char plus/*=' '*/) {
  148. long xx = x * 1000;
  149. conv[0] = xx ? MINUSOR(xx, plus) : ' ';
  150. conv[1] = DIGIMOD(xx, 1000);
  151. conv[2] = '.';
  152. conv[3] = DIGIMOD(xx, 100);
  153. conv[4] = DIGIMOD(xx, 10);
  154. conv[5] = DIGIMOD(xx, 1);
  155. conv[6] = '\0';
  156. return conv;
  157. }
  158. // Convert unsigned float to rj string with 12345 format
  159. char* ftostr5rj(const float& x) {
  160. long xx = abs(x);
  161. conv[0] = RJDIGIT(xx, 10000);
  162. conv[1] = RJDIGIT(xx, 1000);
  163. conv[2] = RJDIGIT(xx, 100);
  164. conv[3] = RJDIGIT(xx, 10);
  165. conv[4] = DIGIMOD(xx, 1);
  166. conv[5] = '\0';
  167. return conv;
  168. }
  169. // Convert signed float to string with +1234.5 format
  170. char* ftostr51sign(const float& x) {
  171. long xx = x * 10;
  172. conv[0] = MINUSOR(xx, '+');
  173. conv[1] = DIGIMOD(xx, 10000);
  174. conv[2] = DIGIMOD(xx, 1000);
  175. conv[3] = DIGIMOD(xx, 100);
  176. conv[4] = DIGIMOD(xx, 10);
  177. conv[5] = '.';
  178. conv[6] = DIGIMOD(xx, 1);
  179. conv[7] = '\0';
  180. return conv;
  181. }
  182. // Convert signed float to string with +123.45 format
  183. char* ftostr52sign(const float& x) {
  184. long xx = x * 100;
  185. conv[0] = MINUSOR(xx, '+');
  186. conv[1] = DIGIMOD(xx, 10000);
  187. conv[2] = DIGIMOD(xx, 1000);
  188. conv[3] = DIGIMOD(xx, 100);
  189. conv[4] = '.';
  190. conv[5] = DIGIMOD(xx, 10);
  191. conv[6] = DIGIMOD(xx, 1);
  192. conv[7] = '\0';
  193. return conv;
  194. }
  195. // Convert unsigned float to string with 1234.56 format omitting trailing zeros
  196. char* ftostr62rj(const float& x) {
  197. long xx = abs(x * 100);
  198. conv[0] = RJDIGIT(xx, 100000);
  199. conv[1] = RJDIGIT(xx, 10000);
  200. conv[2] = RJDIGIT(xx, 1000);
  201. conv[3] = DIGIMOD(xx, 100);
  202. conv[4] = '.';
  203. conv[5] = DIGIMOD(xx, 10);
  204. conv[6] = DIGIMOD(xx, 1);
  205. conv[7] = '\0';
  206. return conv;
  207. }
  208. // Convert signed float to space-padded string with -_23.4_ format
  209. char* ftostr52sp(const float& x) {
  210. long xx = x * 100;
  211. uint8_t dig;
  212. conv[0] = MINUSOR(xx, RJDIGIT(xx, 10000));
  213. conv[1] = RJDIGIT(xx, 1000);
  214. conv[2] = DIGIMOD(xx, 100);
  215. if ((dig = xx % 10)) { // second digit after decimal point?
  216. conv[3] = '.';
  217. conv[4] = DIGIMOD(xx, 10);
  218. conv[5] = DIGIT(dig);
  219. }
  220. else {
  221. if ((dig = (xx / 10) % 10)) { // first digit after decimal point?
  222. conv[3] = '.';
  223. conv[4] = DIGIT(dig);
  224. }
  225. else // nothing after decimal point
  226. conv[3] = conv[4] = ' ';
  227. conv[5] = ' ';
  228. }
  229. conv[6] = '\0';
  230. return conv;
  231. }
  232. #endif // ULTRA_LCD